Author Topic: BPM  (Read 5989 times)

0 Members and 1 Guest are viewing this topic.

Offline ricardo

  • Posts: 2
    • View Profile
BPM
« on: May 27, 2008, 04:21:42 PM »
Hello

Im using BASS_FX for a while (i was using 2.3.x versions) and now im changing to new version.

Im trying the BPM wich i never used before.

In my tests, getting the BEAT callback to work its okay.

My problem is with the BPM part.

per example, when i try to get the BPM the function never returns back.

Let me show my PureBasic code:

Code: [Select]
  BASS_StreamFree(Handle1)
  Handle1=BASS_StreamCreateFile(0, @filename, 0, 0, 0)
  Debug BASS_ErrorGetCode()
  uEndPos = BASS_ChannelGetLength(Handle1,#BASS_POS_BYTE)
  Debug BASS_ErrorGetCode()
  hVolume.f = 1
  BASS_ChannelSetAttribute(Handle1,#BASS_ATTRIB_VOL,hVolume)
  Debug BASS_ErrorGetCode()
  BASS_ChannelPlay(Handle1,0)
  Debug BASS_ErrorGetCode()
  Debug BASS_FX_BPM_DecodeGet(Handle1,10,14,0,#BASS_FX_BPM_BKGRND|#BASS_FX_FREESOURCE,@ObtieneBPMCallBack())
  Debug BASS_ErrorGetCode()

The mp3 start playing and everything goes fine. I receive just error codes = 0
But when calling BASS_FX_BPM_DecodeGet i dont receive nothing, not error not nothing, just stay there and never return back.

Im doing something wrong?

Thanks in advance!

Note:

I tried too using the BASS_STREAM_DECODE flag when creating the Stream, with same results.
« Last Edit: May 27, 2008, 04:28:26 PM by ricardo »

Offline (: JOBnik! :)

  • Administrator
  • *****
  • Posts: 44
  • Gender: Male
    • View Profile
    • (: JOBnik! :)
Re: BPM
« Reply #1 on: May 28, 2008, 11:16:21 AM »
Hi ;D

1st of all, BASS_FX_BPM_DecodeGet, needs a handle using BASS_STREAM_DECODE flag.

DWORD handle = BASS_StreamCreateFile(...,BASS_STREAM_DECODE);

But you really don't want to have 1 handle for playing and decoding bpm, as it will change positions and you won't hear the song as you want.

I suggest you to have 1 handle for playing song and 2nd for bpm, but I guess it's better to have a function that gets the decode BPM:

Code: [Select]
DWORD hBPM;

float getDecodeBPM(const char *fp, double startSec, double endSec)
{
    // free previous hBPM (will free the decode stream as well, because of using BASS_FX_FREESOURCE flag)
    BASS_FX_BPM_Free(hBPM);

    // create decode stream
    hBPM = BASS_StreamCreateFile(FALSE, fp, 0, 0, BASS_STREAM_DECODE);

    // get BPM
    return BASS_FX_BPM_DecodeGet(hBPM, startSec, endSec, 0, BASS_FX_BPM_BKGRND | BASS_FX_BPM_MULT2 | BASS_FX_FREESOURCE, (BPMPROCESSPROC*)bpmProcessProc);
}

Your code will look like that:
Code: [Select]
  BASS_StreamFree(Handle1)
  Handle1=BASS_StreamCreateFile(0, @filename, 0, 0, 0)
  Debug BASS_ErrorGetCode()

  uEndPos = BASS_ChannelGetLength(Handle1,#BASS_POS_BYTE)
  Debug BASS_ErrorGetCode()
  hVolume.f = 1
  BASS_ChannelSetAttribute(Handle1,#BASS_ATTRIB_VOL,hVolume)
  Debug BASS_ErrorGetCode()

  BASS_ChannelPlay(Handle1,0)
  Debug BASS_ErrorGetCode()

  Debug getDecodeBPM(10, 14)
  Debug BASS_ErrorGetCode()

Also it's much better and safer to have a dedicated thread for this instead of using BASS_FX_BPM_BKGRND flag :)
Have fun!
8) JOBnik! 8)

Offline ricardo

  • Posts: 2
    • View Profile
Re: BPM
« Reply #2 on: June 02, 2008, 09:21:27 PM »
Hi

Okay, its working now :)

One question about Beat call bakc:

Im receiving it, if i interpreted right is miliseconds value, right?

Okay, but i think i notice that sometimes the "beat" is in fact a syncope (i hope its right in english the word) and not the "strong" tempo.
I mean in a 4x4 times song, i dont receive allways the 4 strong "black" notes, but maybe some are syncopes (an accent in a soft tempo).

What can i expect to receive from this beat callback? Always the 4 black notes? (talking about 4x4 as example) or the "peaks"?
Some explanation of what is supposued to receive are welcome.

Thanks in advance :)

Offline (: JOBnik! :)

  • Administrator
  • *****
  • Posts: 44
  • Gender: Male
    • View Profile
    • (: JOBnik! :)
Re: BPM
« Reply #3 on: June 03, 2008, 10:45:43 PM »
Hi ;D

The beat detection algorithm is checking for peaks.
If you need to optimize the detection, then please take a look at BASS_FX_BPM_BeatSet/GetParameters :)
Have fun!
8) JOBnik! 8)