BASS.NET API for the Un4seen BASS Audio Library

BassFxBASS_FX_BPM_DecodeGet Method

BASS.NET API for the Un4seen BASS Audio Library
Get the original BPM of a decoding channel.

Namespace:  Un4seen.Bass.AddOn.Fx
Assembly:  Bass.Net (in Bass.Net.dll) Version: 2.4.17.5
Syntax

[DllImportAttribute("bass_fx")]
public static float BASS_FX_BPM_DecodeGet(
	int channel,
	double startSec,
	double endSec,
	int minMaxBPM,
	BASSFXBpm flags,
	BPMPROGRESSPROC proc,
	IntPtr user
)

Parameters

channel
Type: SystemInt32
Stream/music/wma/cd/any other supported add-on format using a decoding channel.
startSec
Type: SystemDouble
Start detecting position in seconds (if <0 it uses the current position).
endSec
Type: SystemDouble
End detecting position in seconds (> 0).
minMaxBPM
Type: SystemInt32
Set min & max bpm, e.g: MakeLong(Int16, Int16)(LowWord, HighWord), LowWord=Min, HighWord=Max. 0 = defaults to 45/230.
flags
Type: Un4seen.Bass.AddOn.FxBASSFXBpm
Use one of the following (see BASSFXBpm):
BASS_FX_BPM_BKGRNDIf in use, then you can do other stuff while detection's in process.
BASS_FX_BPM_MULT2If in use, then the detected BPM will be automatically multiplied by 2 if (BPM < minBPM*2) - recommended setting.
BASS_FX_FREESOURCEFree the source handle as well?
proc
Type: Un4seen.Bass.AddOn.FxBPMPROGRESSPROC
User defined function to receive the process in percents (see BPMPROGRESSPROC), use if not in use.
user
Type: SystemIntPtr
User instance data to pass to the callback function.

Return Value

Type: Single
If successful, the original BPM value is returned, else -1 is returned. Use BASS_ErrorGetCode to get the error code.
Remarks

The BPM detection algorithm works by detecting repeating low-frequency (<250Hz) sound patterns and thus works mostly with most rock/pop music with bass or drum beat. The BPM detection doesn't work on pieces such as classical music without distinct, repeating bass frequency patterns. Also pieces with varying tempo, varying bass patterns or very complex bass patterns (jazz, hiphop) may produce odd BPM readings.

In cases when the bass pattern drifts a bit around a nominal beat rate (e.g. drummer is again drunken ;-), the BPM algorithm may report incorrect harmonic one-halft to one-thirdth of the correct BPM value. In such case the system could for example report BPM value of 50 or 100 instead of correct BPM value of 150.

ERROR CODEDescription
BASS_ERROR_HANDLEchannel is not valid.
BASS_ERROR_DECODEThe channel is not a decoding channel. Make sure the channel was created using the BASS_STREAM_DECODE or BASS_MUSIC_DECODE flag.
BASS_ERROR_FORMATThe channel's format is not supported. Make sure the channel is either Stereo or Mono.
BASS_ERROR_ILLPARAMAn illegal parameter was specified.
BASS_ERROR_ALREADYBPM detection, for this channel is already in use.

Examples

Get the BPM value for the first 120 seconds of a track:
private BPMPROGRESSPROC _bpmProc;
...
int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE);
_bpmProc = new BPMPROGRESSPROC(MyBPMProc);
float bpm = BassFx.BASS_FX_BPM_DecodeGet(stream, 0.0, 120.0, 0, BASSFXBpm.BASS_FX_BPM_BKGRND | 
                                                                BASSFXBpm.BASS_FX_FREESOURCE | 
                                                                BASSFXBpm.BASS_FX_BPM_MULT2, _bpmProc);
BassFx.BASS_FX_BPM_Free(stream);
...
private void MyBPMProc(int channel, float percent)
{
  Console.Write("{0}%\r", percent);
}
See Also

Reference