iPhone 实时音频循环切换
我正在尝试找到播放无缝音频循环的最佳方法,用户可以在尽可能短的时间内切换到另一个音频,并提供相当数量(30-150)的非常短的循环。 OpenAL 足以满足此要求吗?还是我需要深入研究音频单元?苹果文档称,对于像乐器这样的实时反馈,音频单元是正确的选择。
我只是想获得社区对此的意见,任何链接和示例项目将不胜感激。
I'm trying to find the best way to play a seamless loop of audio, that the user can switch out for another at the shortest possible notice, with a decent number (30-150) of very short loops being available. Will OpenAL be sufficient for this, or do I need to delve into Audio Units? The Apple Documentation says that for real-time feedback like an instrument, Audio Units is the right choice.
I just want to get the community's opinion on this, and any links and sample projects would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 AVAudioPlayer 无缝循环压缩音频文件(numberOfLoops = -1)。我建议使用 IMA4 编码的 CAF 文件,因为据传这些文件可以受益于硬件解压缩(为其他事情节省 CPU 周期)。
要减小文件大小,您可以降低比特率(尝试 96 kbps)和/或使用单声道。
请注意,AVAudioPlayer 不允许您更改播放的速度或频率。
You can use AVAudioPlayer to seamlessly loop a compressed audio file (numberOfLoops = -1). I suggest using IMA4-encoded CAF files, as these are rumored to benefit from hardware decompression (saving CPU cycles for other things).
To keep file size down, you can lower the bit rate (try 96 kbps) and/or use mono.
Note that AVAudioPlayer does not allow you to change the tempo or frequency of playback.
这可能并不能真正回答你的问题,但是你看过Finch吗?
仅查看源代码可能会提供一些指导。
this probably doesn't really answer your question, but have you ever looked at Finch?
Just looking at the source might provide some pointers.
如果您需要能够切换到另一个音频样本而没有播放延迟,则需要使用 OpenAL。 AVAudioPlayer 在开始播放之前有一个延迟。
您可以通过调用prepareToPlay来最小化延迟,但它并不总是完全消除延迟。同样,如果用户选择播放 30 到 150 个样本,您将无法事先知道哪些样本需要预加载。
以下是 OpenAL 和 AVAudioPlayer 之间的优缺点的概述:http: //kstenerud.github.com/ObjectAL-for-iPhone/documentation/index.html#choosing_sec
If you need to be able to switch to another audio sample with no playback delay, you'll need to use OpenAL. AVAudioPlayer has a delay before it starts playing.
You can minimize that delay by calling prepareToPlay, but it won't always eliminate the delay completely. As well, if you have 30 to 150 samples that the user selects for playback, you won't know beforehand which samples need to be preloaded.
Here's a rundown of the pros and cons between OpenAL and AVAudioPlayer: http://kstenerud.github.com/ObjectAL-for-iPhone/documentation/index.html#choosing_sec
我最终使用了 Cocos2D 的音频库,它的性能比我预期的要好得多。 AVAudioPlayer 最终的级别比我需要的要低一些。
I ended up using Cocos2D's audio library for this, and it was far more performant than I'd expected. AVAudioPlayer ended up being a good bit lower-level than I'd needed.