dancer.js icon indicating copy to clipboard operation
dancer.js copied to clipboard

Beat Detection

Open circlegarage opened this issue 13 years ago • 6 comments

Hi there!

I'm trying to use dancer.js as a beat detector to count the amount of BPM of a song.

Using the single_song_demo example, i'm incrementing a variable on 'onbeat' event. At 60 seconds I log the variable, but the result is not aligned with results given by BPM detection software.

What can I modify/tune? What am I doing wrong?

Thanks in advance.

circlegarage avatar Aug 07 '12 14:08 circlegarage

Dancer's beat detection is moderately simple -- it looks for a peak that meets the requirements of the beat object (correct frequency, amplitude greater than threshold, amplitude greater than the decaying previous beat). Essentially a beat can be thought of as a bass drum kick. If there's a lot of double bass going on, you'll have more than one "beat detected" than per music-theory-beat.

Perhaps the current beat functionality should be turned into a "kick" feature, with beat detection focusing on triggering once per "beat" (4 times a measure in a 4/4 song).

jsantell avatar Aug 07 '12 17:08 jsantell

Thanks for ur reply!

Have you got some ideas? Code in particular to implement?

Sorry to ask for this, but i'm quite ignorant about sound management. I'vr seen there is a library called beatdetektor.js, can be useful to implent it in dancer.js? but i don't know how to use it :).

Then...how can i connect dancer to soundmanager?

Thanks,

Marco

Il giorno 07/ago/2012, alle ore 19:01, Jordan Santell [email protected] ha scritto:

Dancer's beat detection is moderately simple -- it looks for a peak that meets the requirements of the beat object (correct frequency, amplitude greater than threshold, amplitude greater than the decaying previous beat). Essentially a beat can be thought of as a bass drum kick. If there's a lot of double bass going on, you'll have more than one "beat detected" than per music-theory-beat.

Perhaps the current beat functionality should be turned into a "kick" feature, with beat detection focusing on triggering once per "beat" (4 times a measure in a 4/4 song).

— Reply to this email directly or view it on GitHub.

circlegarage avatar Aug 07 '12 20:08 circlegarage

Maybe it does make sense to change beat to kick.

I think beat detection (as in BPM) could get very sophisticated, but this would be neat to implement. Here's one starting place: http://stackoverflow.com/questions/657073/how-to-detect-bpm-of-the-song-by-programming but I think academic sources would be better.

It should be trivial to implement a metronome-type event for when the time signature and tempo of a song are known.

The complication with either is managing the event loop... if someone is doing something even a little complex on each 'beat' the events would pile up, but maybe that's up to the user to sort out.

cesutherland avatar Aug 09 '12 11:08 cesutherland

mmhhh another question:

  • which is the uom of the frequency parameter? by default 0-10 what does it mean?

I'm now experimenting with a sort of filter checking time when a beat occours...

circlegarage avatar Aug 09 '12 17:08 circlegarage

yeah i would like to know as well what are frequency and threshold? i think i need to better understand those in order to know which values will do best.

Yahav avatar Aug 10 '12 07:08 Yahav

@circlegarage The frequency array is an ordered list of frequencies -- each element represents i_40hz to i_40+40hz (roughly, I have to look up again what the range of each slice is), with the normalized value of that element being that frequency's amplitude. The frequency param in beat is what frequency range to focus in for the detection, usually something low.

Currently, it uses SM2 to fallback on if HTML5 audio APIs are not supported. Plans in the future to be able to pass in an SM2 object so it can be tied into another SM2 player already on the site.

@Yahav Threshold is a minimum normalized amplitude a frequency must reach in order to be considered a 'beat'. Once a beat is detected, the amplitude of the previously detected beat must be overcome by the amplitude of the next beat, and the previously detected beat's amplitude decays at the decay rate set.

@cesutherland Agreed, "beat" should be renamed to "kick" -- beat detection (as in firing a callback four times every measure in a 4/4 song), can be implemented otherwise, but this feature is more of detecting a kick drum.

jsantell avatar Aug 10 '12 14:08 jsantell