cjcliffe / beatdetektor

BeatDetektor BPM detection / visualization library
http://www.beatdetektor.com
325 stars 54 forks source link

Hello, #3

Open cunqueiromarco opened 8 years ago

cunqueiromarco commented 8 years ago

Hello, I did a FFT of an audio file's raw data and I now have a 1024-length Float32Array. I want to use the beat detector to determine the BPM of the audio file. I'm having difficulty figuring out how to use the BeatDetektor functions and wanted to know if you could help. Thanks.

cjcliffe commented 8 years ago

@dominiroc11 just need to pass the un-altered FFT (it should look symmetrical) to beatdetektor with a timestamp -- bd.process(timestamp, fft_data);

After each update it will set bd.win_bpm_int and bd.win_bmp_int_lo if detection was reasonable. win_bpm_int is BPM accurate to 1 decimal place (but you have to divide by 10) and will take longer to detect and is usually inaccurate unless win_bmp_int_lo (which is just integer BPM) is also set.

If you're just processing a WAV file just tally all the win_bmp_int_lo values and pick the one that appears most. Once you find that you can compare to the win_bmp_int tally and find the best match that's < 1.0 away from the win_bmp_int_lo pick.

Also bd.beat_counter, bd.half_counter and bd.quater_counter will contain the current 1, 1/2 and 1/4 beat counts (which you can use as a counter to sync something to for real-time visuals) but won't necessarily contain the actual beat count from a track.