While working on a rhythm music game, I noticed that AVAudioPlayer has a latency between the reported .currentTime and the actual location within an audio file, that varies according to the file format.
For instance, playing an .m4a file will produce lower latency than playing an .aac file (ADTS AAC).
That's somewhat understandable and I came to accept this already (as the latency was a constant according to file type).
What I don't understand, is why these different latencies might also happen for 2 kinds of .m4a files, those converted from an original AIFF file, and those first converted to ADTS AAC and then converted to .m4a
In other words:
If I run:
afconvert -f m4af -d aac my_aif_file.aif
I get a file playing in lower latency than a file that was created like this:
afconvert -f adts -d aac my_aif_file.aif
afconvert -f m4af -d aac my_aif_file.aac
Any explanation/solution to understand these different outcomes will be appreciated.
Found the issue - it's the conversion itself.
When converting to adts aac the converted audio has a prefix of about 40ms of silence... Weird...