AVAudioPlayer Seamless looping of AAC files

In the WWDC 2011 session 404 video we're told that AVAudioPlayer should be able to dynamically ignore the priming and remainder frames in AAC audio, which should enable seamless looping of compressed files, but I can't get this to work in practice.

I can verify in both Logic Pro and WaveLab that the wav versions of my files loop perfectly, but in our app (iOS) they have a clear gap at the loop point.

Our encoded files are m4a 448 kbps, 48k AAC files. I've tried exports from WaveLab and afconvert, but both fail to provide seamless looping. For afconvert I used the arguments from the WWDC video: -f "m4af" -d "aac".

Any advice? We really need to use compressed files to keep app size down, but we absolutely need them to loop seamlessly (they're ambient background soundscapes).

Replies

Just to add an update to this: I was able to improve the "seam" in my seamless loop by manually setting the loop start to the priming frame count from afinfo, and the loop end to priming + valid.

However, I'm now wondering whether a truly seamless loop is actually possible with compressed audio. Since the signal at any given point is always an approximation when encoded, the audio on both sides of a "cut" in the original wav must also be an approximation, meaning that the two sides won't necessarily be as "similar" as in the original. That seems reasonable to me, but is it correct?

I'm talking about a "seamless" loop of an ambient soundscape recording, btw, so there's no actual silence (i.e., it's not a drum loop or anything like that).