Search code examples
iphoneobjective-ccore-audioaudioqueueservices

AudioFileReadPackets to an array?


I'd like to read packets from an audio file, but I don't want to send them to a playback buffer. I just want to get an array of the packets, ideally as floats. I've prepped the audio and then want to call:

OSStatus err = AudioFileReadPackets (audioFileID,FALSE,outBytes,NULL,0,numPackets,whatGoesHere?);

But what goes in that last argument?

Thanks.


Solution

  • If you were using Audio Queue Services, that's where you'd put the mAudioData pointer of an AudioQueueBuffer. But since you just want the bits, you can pass a pointer to a preallocated buffer (static or dynamic) of your choosing. You can infer an upper bound on the necessary size of the buffer by using portions of the dataFormat from your file.

    An example of this computation is provided in the Audio Queue Services Programming Guide; grep for DeriveBufferSize.