BPM Detection OCX
    Documentation

Usage

Once you have downloaded the ocx, you can put it in your windows\system directory or in the same directory as your project's executable file.
You can now add the control to your project.

In Visual Basic 5 and 6 you can add the control to your project by using the Project->Components menu.

Functions

Init (Optional ByVal nrOfChannels As Long = 5, Optional ByVal HistoryLength As Long = 40, Optional ByVal MinBPM As Long = 80, Optional ByVal MaxBPM As Long = 180, Optional ByVal Sensitivity As Single = 0.9, Optional ByVal DynamicSensitivity As Boolean = True)

Before using the ocx, you can initialize it. If you do not initialize it, it will be automatically initialized with the default settings when you start using it.
You can also use this function to clear the data, this can be done when a new song is loaded/played because the bpm of the previous song and the new song will probably not be the same.

nrOfChannels : This is how much of the spectrum data should be used. 5 means the 5 lowest frequency bands will be used for beat detection.
HistoryLength : This is the size of the beat memory. By default 40 beats are stored. Increasing this number will improve the accuracy, but will make it slower to adapt to a new bpm when the song has a variable bpm rate.
MinBPM : The minimum allowed bpm to detect.
MaxBPM : The maximum allowed bpm to detect.
Sensitivity : At which level a beat is detected.
DynamicSensitivity : The sensitivity value can change dynamically depending on the music. It is strongly recommended to turn this on. If it is turned on, it doesn't matter what sensitivity is set to.

Process (ByRef Spectrum() As Single)

This function does the actual work, just pass the current spectrum information.
You should try to call this function at least 50 times per second, and 100-200 times is preferred for accurate results.

Register (ByVal EMail As String, ByVal Code As String)

When you have received a code you can register the control so it stops randomly complaining.

 

Events

beatExpected ( )

This event will be called every time a beat can occur based on the current found bpm.
It is not necessary that an actual beat occurs for this event to be triggered.
If you want to know if a beat has actually occured, you can use this event in combination with the BeatLoudness property.

 

Variables

BPM

This is the value you were probably looking for. The Beats Per Minute value will give you the predicted BPM over the last beats (depending on the HistoryLength value)

nrOfBeats

This value will tell you how many beats in a row have been found to calculate the bpm value from.
A higher value means the predicted bpm is more likely to be correct.
When it's higher than 20 you can be pretty sure about the value, when it's lower than 5 you should interpret the value more as a guess.

beatLoudness

This will return a value between 0 and 1 that tells you the loudness of the last beat. For most songs this will be around 1 when a beat is going on and <0.5 on the parts with no beat.

 

Example Code

This code is an example when using the control in combination with the FMod sound engine in Visual Basic.
You are free to contribute examples in other languages/other sound engines.

'... initialize sound engine, open, play music

'Somewhere declare a variable to store the spectrum data
Dim Spectrum(300) As Single

'Somewhere activate the Spectrum DSP
FSOUND_DSP_SetActive FSOUND_DSP_GetFFTUnit, 1

'Now call the process code in a loop
Do Until ExitApp
    'Get Spectrum data and process it
    GetSpectrum Spectrum
    BPMControl1.Process Spectrum

    'You can use the calculated data here
    Label1 = BPMControl1.BPM

    'Make sure you give windows some time to update stuff
    DoEvents
Loop