I've written my own audio library. (Silly, I know but I enjoy it.) Right now, I'm using it to play stereo files from the iPod library on iOS. It works well except that sometimes the call to ExtAudioFileRead() takes longer than 23ms. Since my AudioUnits output setup is playing audio at 44.1KHz, and it's asking for 1024 frames per callback. My code + ExtAudioFileRead() must take no longer than 23ms to respond.
I'm quite surprised that ExtAudioFileRead() is so slow. What I'm doing seems quite the normal thing to do. I'm thinking there must be some undocumented configuration magic that I'm not doing. Here is my relevant configuration code:
ExtAudioFileRef _extAudioFileRef;
OSStatus result;
result = ::ExtAudioFileOpenURL((__bridge CFURLRef)_url, &_extAudioFileRef);
AudioStreamBasicDescription format;
format.mBitsPerChannel = 8 * sizeof(float);
format.mBytesPerFrame = sizeof(float);
format.mBytesPerPacket = sizeof(float);
format.mChannelsPerFrame = channelCount;
format.mFormatFlags = kAudioFormatFlagIsFloat|kAudioFormatFlagIsNonInterleaved;
format.mFormatID = kAudioFormatLinearPCM;
format.mFramesPerPacket = 1;
format.mSampleRate = framesPerSecond;
result = ::ExtAudioFileSetProperty(_extAudioFileRef,
kExtAudioFileProperty_ClientDataFormat,
sizeof(format),
&format);
I'm not setting any other properties of _extAudioFileRef.
I've traced the heck out of this. I've put time measurement around just my call to ExtAudioFileRead() so I know it's not my code slowing this process down. It's got to be a configuration issue, right?
Thanks so much for any help or even guesses!
Cheers, Christopher
You shouldn't be reading from the audio file in your audio callback - you should be buffering in another thread and passing the samples across.
You're breaking cardinal audio rule #4: