views:

138

answers:

1

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.

A: 

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.

warrenm
I should comment that your "outBytes" is not genuinely an out parameter - it's an io parameter, meaning that you need to set it in advance to the capacity of your buffer. If the data to be read exceeds the size of your buffer, fewer packets will be read, and the other out params will reflect this.
warrenm