I tried it. Doesn't make any difference.
What happens is that I hear the initial 1.5 seconds of audio (from the initial callback to prime the buffers for playback), then silence. The program doesn't crash but I have a IKImageView that gets garbled. Don't know if it has anything to do with it...
I have put the code in a class, which I initialize and send -start to in my AppDelegate's -applicationDidFinishLaunching:
static void MyAQOutputCallback(void *inUserData,
AudioQueueRef inAQ,
AudioQueueBufferRef inCompleteAQBuffer)
{
MyPlayer *aqp = (MyPlayer*)inUserData;
if (aqp->isDone) return;
UInt32 numBytes;
UInt32 nPackets = aqp->numPacketsToRead;
CheckError(
AudioFileReadPackets(aqp->playbackFile,
false,
&numBytes,
aqp->packetDescs,
aqp->packetPosition,
&nPackets,
inCompleteAQBuffer->mAudioData),
"AudioFileReadPackets failed");
if (nPackets > 0)
{
inCompleteAQBuffer->mAudioDataByteSize = numBytes;
AudioQueueEnqueueBuffer(inAQ,
inCompleteAQBuffer,
(aqp->packetDescs ? nPackets : 0),
aqp->packetDescs);
aqp->packetPosition += nPackets;
}
else
{
CheckError(AudioQueueStop(inAQ, false), "AudioQueueStop failed");
aqp->isDone = true;
AudioQueueDispose(inAQ, TRUE);
}
}