Beat Detection in Processing

So I’m currently working on creating some music/sound responsive visuals in processing.  Using this programming environment and it’s associated libraries, it’s possible to get FFT ( Fast Fourier Transform ) data live as sound is playing through the computer.  So it’s quite simple to make objects react to the force or volume of sound, but to get actual *beat* detection is slightly harder ( as essentially, that’s what this will be used for in the end ).

I did some research, and found a variety of possible implementations.  Most of the people who have attempted such a program have started by splitting the FFT data up into “zones”.  Then looking at the average data in each of these zones.  I whipped up a quick prototype over the last two days.

 screen-01451.jpg

So let me quickly explain what’s going on here.  On the far left, you’ve got two red bars, these red bars indicate the overal average volume, then the rest of the vertical lines make up the results from the spectrum analysis, which I’ve then split up into 7 “zones” ( green, blue, green, blue etc ). On each of these zones, I get the “average” of the values ( the white line ), and then I also have a “beat” line ( red ).  The beat line falls at a steady rate, but if it hits the white line, a “beat” in that zone is detected.  Basically, if the sound crosses a certain threshold.  The white circle in the centre is displayed if 5 or more zones detect a beat.

It’s a little rough at the moment, and I need to do some fine tuning ( and replace that butt ugly circle with something prettier with a fade-out on it ( attack, and delay ) ).  But I’ve uploaded the windows .exe version for people to play with, the browser based java version wont work.  The program takes whatever is set to play through your recording device.  ( microphone etc ).  I have my computer set up so that the waveout, or “what u hear” is set to the default device on my microphone output.  That way I can press play on my mp3 player, and voila, data!

Beat Detect v3 – Made with Processing ( .zip,  425kb )

Advertisements

About aA

I'm a 28 year old Designer from Brisbane, Australia. I've got a keen interest in Motion Graphics, Illustration, and Game Design. View all posts by aA

5 responses to “Beat Detection in Processing

  • ao

    I was looking to mess around with beat detection myself and was wondering how to split the data up into ‘zones’ I was hoping your zip file had source that would demonstrate this, but it didn’t and I couldn’t even run the windows export since I use linux

    • aA

      Hey, sorry for not providing the source code – I forgot this was even here to be honest, most of the code and examples from this project are at another blog :

      http://www.tenfiftyfour.com/aAVis/

      The post you’re probably after is this one :

      “Audio Analysis and Beat Detection version 2”
      http://www.tenfiftyfour.com/aAVis/?p=12

      Though I don’t believe there’s any source code there either.

      Essentially it’s a manual split. I decide the number of ‘zones’ I want to have. Then I split the entire stream, from left to right, into these zones.

      The zones increase in size as they move along.

      It’s been a while since I wrote this, and the source code is all at home.

      I also wrote this for my final ‘reflection’ :

      “The Fourier Transform produces a Spectrum – it saves the magnitude of each frequency. All of this information is saved within an array, divided up into 512 Bins ( 512 is the number I chose ).

      This data can then be intepreted in any way I see fit. In order to do Beat Detection, there is some more computation involved : The FFT stream must be divided into X segments ( I chose 6 ). The sizes get larger the further right you move into the stream ( ie, Bass to Treble ). For each of these “zones” I then calculated the average value, and a “threshold value” based on the average. If the average value moves higher than the threshold, then that constitutes a “dramatic” increase in that zone, and (quite possibly) a beat.

      There are obvious flaws in this solution, however it was the best option I could find for *live* beat detecting”

      ( more here – http://www.tenfiftyfour.com/aAVis/reflection/productionp2.html )

      I hope that helps. If not , let me know and I’ll get a hold of the sourcecode for you.

      – A.

    • aA

      I was actually in the middle of adding ‘tapping’ to set the beat in a newer version – Possibly a more accurate ( though less dynamic ) way to track beat detection ?

  • wonko

    this is really cool and has huge potential in live performaces for visualisations. It is interesting that most music can be thought of mathematically and that that living mathematics begars analysis to discover it’s underlying structure. It will be very interesting to see this progress. I wonder if there is merit in honing in particular frequencies, searching for the “doof” amongst the myriad of other waveforms here.

  • Afro88

    That’s pretty cool Anth, does a pretty good job with most tracks :)

    What could also make things easier for it is letting it know the tempo range the music is in, like 125 – 135bpm. Then you sort of know that roughly every 1.8 seconds there should be 4 beats. And don’t deny the overall volume change as an indicator – look at a few tracks in Audacity or something, and you can very easily tell where the beat is by the volume spikes. I guess you could start with the volume spikes, then compare to the zone data (ie, does this spike have more in 3 bottom zones than the top 2?). It really could go on and on couldn’t it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: