jsantell / dancer.js

high-level audio API, designed to make sweet visualizations
jsantell.github.com/dancer.js
MIT License
2.11k stars 211 forks source link

Beat Detection #15

Open circlegarage opened 11 years ago

circlegarage commented 11 years ago

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.

jsantell commented 11 years ago

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).

circlegarage commented 11 years ago

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 notifications@github.com 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.

cesutherland commented 11 years ago

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.

circlegarage commented 11 years ago

mmhhh another question:

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

Yahav commented 11 years ago

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.

jsantell commented 11 years ago

@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.