Using AVFoundation / CoreMedia / Other Frameworks to Detect Beats / Onsets
Asked Answered
N

1

12

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

Ng answered 20/2, 2012 at 2:34 Comment(2)
Well, you need to have access to the pure pcm data. Choose whatever audio lib offers that and apply existing algortihms to the dataMccormick
Seen this question? It seems to have links to some pretty good solutions. #657573Putative
S
4

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:

https://adamhess.github.io/Onset_Detection_Nov302011.pdf

or for hardcore treatment of it:

https://scholar.google.com/citations?view_op=view_citation&hl=en&user=PMHXcoAAAAAJ&citation_for_view=PMHXcoAAAAAJ:uJ-U7cs_P_0C

Syndic answered 3/4, 2012 at 14:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.