使用 AVFoundation / CoreMedia / 其他框架来检测节拍/起始
(前言:这是我在 Stack Overflow 上遇到的第一个与音频相关的问题,所以我会尽力用最好的措辞来表达。欢迎编辑。)
我正在创建一个应用程序,它将允许用户循环播放音乐。目前,我们的原型允许这些“循环标记”(实现为 UISliders)每秒捕捉一次,指定循环的开始和结束。显然,当循环音乐时,秒是处理这个问题的一种非常粗暴的方式,所以我想使用节拍来代替。
除了标记 UISlider 捕捉到的节拍之外,我不想做任何其他事情:
- 向我们的
loadMusic
方法提供一个音频文件。 - 通过库运行它来检测节拍或它们之间的间隔(也许)。
- 将该值输入到滑块的
setNumberOfTickMarks:
方法中。 - 利润!
不幸的是,我通过 Google 和 SO 得到的大多数结果都产生了更先进的节拍检测库,例如混音器将使用的库。对我来说太过分了。
这是 CoreMedia、AVFoundation 或 AudioToolbox 可以处理的吗?如果没有,是否有其他库可以处理这个问题?我对 Apple 文档的研究仅产生了 MIDI 文件的相关结果。但苹果自己的软件也有这样的功能,例如iMovie 的 snap-to-beats 功能。
此时任何指南、代码或摘要都会非常有帮助。
编辑:经过更多的挖掘后,我正在寻找的正确术语似乎是发作检测。
(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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
起始点检测算法有多种形式,从查看原始音乐信号到使用频域技术。
如果您想要一种快速简单的方法来确定节拍位置:
将音乐信号切成小段(
20-50ms
块)计算信号的平方和平均值:
Sum(Xn ^2) / N
(其中N
是每20-50ms
的样本数)如果您想要更复杂的技术,请查看:
https://adamhess.github.io/Onset_Detection_Nov302011.pdf
或对其进行硬核处理:
https://scholar.google.com/itations?view_op=view_itation&hl=en&user=PMHXcoAAAAAJ&itation_for_view=PMHXcoAAAAAJ:uJ-U7cs_P_0C
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:
Chop up the music signal into small segments (
20-50ms
chunks)Compute the squared sum average of the signal:
Sum(Xn ^2) / N
(whereN
is the number of sample per20-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