开发者

Real-Time Audio Loop Switching for iPhone

开发者 https://www.devze.com 2023-02-10 11:50 出处:网络
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 shorte开发者_C百科st possible notice, with a decent number (30-150) of very short loo

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 shorte开发者_C百科st 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.


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.


this probably doesn't really answer your question, but have you ever looked at Finch? Just looking at the source might provide some pointers.

  • Johannes


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号