Thursday, April 14, 2011

How to detect BPM of the song by programming

In my application, i have to detect all the songs and BPM of those songs. Detect the songs are finished now I have to detect BPM of songs.

Does anyone tell me that how can I detect BPM of each song by programming in Cocoa.

Thanks, Haresh.

From stackoverflow
  • Perform a Fourier transform, and find peaks in the power spectrum. You're looking for peaks below the 20 Hz cutoff for human hearing. I'd guess typically in the 0.1-5ish Hz range to be generous.

    SO question that might help: http://stackoverflow.com/questions/477944/bpm-audio-detection-library

    Also, here is one of several "peak finding" questions on SO: http://stackoverflow.com/questions/3260/peak-detection-of-measured-signal/


    Edit: Not that I do audio processing. It's just a guess based on the fact that you're looking for a frequency domain property of the file...


    another edit: It is worth noting that lossy compression formats like mp3, store Fourier domain data rather than time domain data in the first place. With a little cleverness, you can save yourself some heavy computation...but see the thoughtful comment by cobbal.

    cobbal : however, mp3 achieves it's compression by chopping off the frequencies outside of human hearing. Fourier may not be the right tool here.
    dmckee : AH. Good point, that.
    TrayMan : MP3 doesn't 'chop off' frequencies outside of human hearing and it performs cosine transformations (related to Fourier's) individually to enveloped windows about 1 ms wide each. I'd try dmckee's first suggestion on 10 s long windows and see what comes out.
  • This is challenging to explain in a single StackOverflow post. In general, the simplest beat-detection algorithms work by locating peaks in sound energy, which is easy to detect. More sophisticated methods use comb filters and other statistical/waveform methods. For a detailed explication including code samples, check this GameDev article out.

  • Here's a free program will analyze and write BPM to ID3V2 tag. No idea how good

  • If you can manage to use PyObjC to interface with python code in your project, Echo Nest Remix is a pretty slick API for python:

    http://code.google.com/p/echo-nest-remix/

    There's a method analysis.tempo which will give you the BPM. It can do a whole lot more than simple BPM, as you can see from the API docs or this tutorial:

    http://lindsay.at/work/remix/overview.html

  • I'd imagine this will be easiest in 4-4 dance music, as there should be a single low frequency thud about twice a second.

  • Beat extraction involves the identification of cognitive metric structures in music. Very often these do not correspond to physical sound energy - for example, in most music there is a level of syncopation, which means that the "foot-tapping" beat that we perceive does not correspond to the presence of a physical sound. This means that this is a quite different field to onset detection, which is the detection of the physical sounds, and is performed in a different way.

    You could try the Aubio library, which is a plain C library offering both onset and beat extraction tools.

    There is also the online Echonest API, although this involves uploading an MP3 to a website and retrieving XML, so might not be so suitable..

    EDIT: I came across this last night - a very promising looking C/C++ library, although I haven't used it myself. Vamp Plugins

  • Accurate BPM detection is very difficult. See this stackoverflow question, and my reply to it.

  • To repost my answer: The easy way to do it is to have the user tap a button in rhythm with the beat, and count the number of taps divided by the time.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.