Question

(Preface: This is my first audio-related question on Stack Overflow, so I'll try to word this as best as I possibly can. Edits welcome.)

I'm creating an application that'll allow users to loop music. At the moment our prototypes allow these "loop markers" (implemented as UISliders) to snap at every second, specifying the beginning and end of a loop. Obviously, when looping music, seconds are a very crude manner to handle this, so I would like to use beats instead.

I don't want to do anything other than mark beats for the UISliders to snap to:

  • Feed our loadMusic method an audio file.
  • Run it through a library to detect beats or the intervals between them (maybe).
  • Feed that value into the slider's setNumberOfTickMarks: method.
  • Profit!

Unfortunately, most of the results I've run into via Google and SO have yielded much more advanced beat detection libraries like those that remixers would use. Overkill in my case.

Is this something that CoreMedia, AVFoundation or AudioToolbox can handle? If not, are there other libraries that can handle this? My research into Apple's documentation has only yielded relevant results... for MIDI files. But Apple's own software have features like this, such as iMovie's snap-to-beats functionality.

Any guidance, code or abstracts would be immensely helpful at this point.

EDIT: After doing a bit more digging around, it seems the correct terminology for what I'm looking for is onset detection.

Was it helpful?

Solution

Onset Detection algorithms come in many flavors from looking at the raw music signal to using frequency domain techniques.

if you want a quick and easy way to determin where beats are:

  1. Chop up the music signal into small segments (20-50ms chunks)

  2. Compute the squared sum average of the signal: Sum(Xn ^2) / N (where N is the number of sample per 20-50ms)

If you want more sophisticated techniques look into:

http://bingweb.binghamton.edu/~ahess2/Onset_Detection_Nov302011.pdf

or for hardcore treatment of it:

http://www.elec.qmul.ac.uk/people/juan/Documents/Bello-TSAP-2005.pdf

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top