Audio Analysis and BPM Calculation in a Spreadsheet

Last week I showed the beginnings of my audio analysis program. This week it’s time to talk about the goals. My final goal is to do BPM calculation on various music sources. It should be fairly fast, but there’s no need for a realtime readout. I did some Google-ing, but couldn’t find any freely available Java implementation. So I ended up reinventing the wheel.

I did however look for a little help. Yov408’s explanation on GameDev is an exceptionally well tutorial and introduction into beat detection. If you read the article, you’ll notice that the first thing you need is the energy of the music file. So I added an energy calculating filter to my architecture.

Post Office

Creative Commons License photo credit: wenzday01

See the Google Docs spreadsheet with a visual representation.

Afterward, I wanted to get some insight into the algorithm, so I took some random samples and put them in a spreadsheet. My test song is one with a very very clear beat, so if my beat detection algorithm works on anything, this will be it.

I did have to expand the algorithm a little, to calculate the actual BPM. The document only describes beat detection, but once you got that far, BPM calculation is fairly trivial (just count the beats and divide by the time).

If you open the spreadsheet, you’ll notice that I got lucky with my first sample. Immediately I calculated a pretty good BPM of the song (it is about 128 BPM), however, when I tried another sample of the same song, the result was completely wrong. But you might notice that if I did not use the adaptive algorithm to calculate the threshold value C.

See the Google Docs spreadsheet with a visual representation.

I tried to implement that, and although the theory sounds good, the results were even worse. I’m pretty sure I need to go over it one more time to figure out the best values for the constants (I have a different input range then the article). But it’s a start.

Next week, I’ll try to tune that adaptive algorithm and hopefully publish my code. If you have some experience in BPM calculation, I’d love to hear what algorithm you used. Because there are as many theories out there as there are people calculating BPM counts.

Image credit