Author Topic: BASS_FX_BPM_DecodeGet  (Read 292 times)

Ed1966

  • Posts: 218
BASS_FX_BPM_DecodeGet
« on: 26 Aug '22 - 10:16 »
Hello friends,

I use BASS_FX_BPM_DecodeGet and after some searching I come to the following.
Works very nice, must say.

Code: [Select]
procedure TBassMixerAudio18.CalculateBPMValue;
var
  SongMiddle,
  SongStart: Double;
  SongEnd: Double;
begin
  FBPMValue := 0;
  SongStart := (GetPlayingTime / 3);
  SongMiddle := (GetPlayingTime / 2);
  SongEnd := (GetPlayingTime - SongStart);

  // http://www.un4seen.com/forum/?topic=13290.msg92939;topicseen#msg92939
  // Limits set to 29 and 230 bpm which is the default value of soundtouch
  // The detection of BPM starts at the middle of song and not for the whole song.
  FBPMValue := BASS_FX_BPM_DecodeGet(GetStream, SongMiddle, SongEnd, MakeLong(29, 230), BASS_FX_BPM_MULT2, nil, nil);
  // BASS_FX_BPM_MULT2: if ( BPM * 2 < max ) BPM = BPM * 2;

  if (BASS_ErrorGetCode = 0) and (FBPMValue <> -1) then
  begin
    if (FBPMValue >= 180) then
      FBPMValue := (FBPMValue / 2);

  end;
end;

Have read a lot whether this is correct and still see a lot of differences? Is there a way to make it super or is it what it is?
I can think this is it.

Maybe some pointers for improvements?

Regards,
Eduard.

Ed1966

  • Posts: 218
Re: BASS_FX_BPM_DecodeGet
« Reply #1 on: 14 Sep '22 - 10:41 »
I Think i got it. :-)
Question:

Is it possible to calculate or detect de KEY in a song. Like C, A, Am etc.
Or is this future option? Or how can i do this myself?

Regards,
Eduard.


« Last Edit: 14 Sep '22 - 10:57 by Ed1966 »

Ian @ un4seen

  • Administrator
  • Posts: 24726
Re: BASS_FX_BPM_DecodeGet
« Reply #2 on: 15 Sep '22 - 16:22 »
Unfortunately, BASS doesn't include that option. It isn't something that I've looked into, so I'm unable to offer suggestions, but I would imagine there are libraries available for it, eg. you could get the sample data from BASS (BASS_ChannelGetData) and pass it to another library to analyse.

Ed1966

  • Posts: 218
Re: BASS_FX_BPM_DecodeGet
« Reply #3 on: 15 Sep '22 - 17:31 »
Thanks for the information. I'll keep looking.

Ed1966

  • Posts: 218
Re: BASS_FX_BPM_DecodeGet
« Reply #4 on: 16 Sep '22 - 12:11 »
If I use BASS_ChannelGetData with FFT table how can i extract for example 260 hz (Think KEY C)
Have you got little example or missing i point.
Here thinking to increase 260 hz in table and so on. But 260, let's say 250-270 increase de C array.
To detect overal the KEY. highest is de KEY at the end of the song?
I use Delphi but C++ is fine. Thank you.
Regards,
Eduard.

Ian @ un4seen

  • Administrator
  • Posts: 24726
Re: BASS_FX_BPM_DecodeGet
« Reply #5 on: 16 Sep '22 - 17:11 »
You can translate a frequency to the nearest FFT bin like this:

Code: [Select]
int bin = (float)frequency * fftsize / samplerate + 0.5;

But I'm not sure simply finding the loudest frequency will necessarily give you the key of a song. If it isn't something that you're familiar with, perhaps it would be best to look around for a ready-made library that you can use for detecting the key, before trying to implement it yourself if you don't find anything?

jpf

  • Posts: 149
Re: BASS_FX_BPM_DecodeGet
« Reply #6 on: 17 Sep '22 - 06:16 »
@ Ed1966:
As Ian said, you'd better use an existing library, or at least take other's research on the subject as a starting point. These are just a few of them (you can find more using Google search):

https://github.com/evanpurkhiser/keyfinder-cli
https://github.com/jackmcarthur/musical-key-finder
https://github.com/mixxxdj/libkeyfinder
https://github.com/napulen/justkeydding
https://github.com/apmcleod/key-detect
https://github.com/angelfaraldo/edmkey
https://github.com/tfriedel/trackanalyzer

I didn't test any of these myself.

Ed1966

  • Posts: 218
Re: BASS_FX_BPM_DecodeGet
« Reply #7 on: 20 Sep '22 - 05:15 »
It has become clearer.

I'll look into it but I think it's getting too complicated for me.  ;D

Thanks for thinking along.

Regards,
Eduard.

Ed1966

  • Posts: 218
Re: BASS_FX_BPM_DecodeGet
« Reply #8 on: 20 Sep '22 - 11:10 »
I was thinking this link.

https://www.ibrahimshaath.co.uk/keyfinder/

Complete C++ and I am Delphi so i must re-learn, install C++ or stop immediately.
Maybe there comes a time, but not right now.

Thank you  :)