Hiya 😀!
We have a SpriteKit app where we play multiple audio files at the same time (max. 5 separate samples started at the same time), as a sort of music sampler. Since switching to AVAudioEngine and optimizing the engine, real-time play is quite smooth, but not yet perfect. Lags may be coming from other things than sample playback, but I would like to make sure that our audio format is the best it can be for real-time play.
What is the best audio format for real-time playback?
We are currently testing a bunch of formats with CAF with the source being high-quality AIF, including aac, aacl, BEI16, ima4 and LEI16. I've heard from other places that LEI16 should be the best, but we still do get some lagging and the diskspace required is quite high at more than 50mb. I'm also assuming compression formats such as ima4 are not the best because they need to be uncompressed on runtime. For converting we are using afconvert, so a typical line for us would be afconvert -f caff -d LEI16 -c 1 source.aif.
Our playback system is based on AVAudioEngine with AVAudioPlayerNode's playing preloaded AVAudioPCMBuffers. Another thing I'm curious about is whether we could use compressed audio to save diskspace and uncompress the samples to buffers during preload with AVAudioCompressedBuffers. I remember seeing a WWDC talk about this, but I'm not sure exactly how it works. I guess you load a compressed file into the AVAudioCompressedBuffer and it automatically uncompresses it and readies it for playback...? Or do I have to use AVAudioConverter? If anyone has any experience with this, we would soooooo appreciate any input!
Thanks!