Search code examples
iphonecore-audioopenalaudiounit

Real-Time Audio Loop Switching for iPhone


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.


Solution

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