views:

182

answers:

1

Using Xcode/Cocoa and the ExtAudioFile API, I'm trying to store away AudioBufferList* objects away for later use, but I'm running into trouble with re-accessing the data. These objects are coming from repeated ExtAudioFileRead calls.

I realize that I can't just stuff these AudioBufferList* objects into an NSArray, but I was under the impression that an NSPointerArray would work for this purpose. However, when trying to access audioBufferList->mBuffers[0].mData after storing the audio buffer lists in the NSPointerArray, they just come back zeroed out.

I was memcpying the audioBufferLists to new audioBufferList objects since I'm reusing the same audio buffer list for each ExtAudioFileRead call. I'm not sure if that's sufficient, though, and memcpying the void* audioBufferList->mBuffers[0].mData objects isn't helping either.

What's the easiest way to store these AudioBufferList* objects? Am I on the right track?

+1  A: 

AudioBufferLists hold their data in audioBufferList.mBuffers[i].mData.
mData is void* and the actual type of the values is determined by the output format you specified.

Example:
If you defined
kAudioFormatFlagsCanonical,
kAudioFormatLinearPCM,
mBitsPerChannel = 32 and
mFramesPerPacket = 1
as your output format, the mData-array contains values of type AudioSampleType (which is Float32 a typedef)

If you have chosen another format the array might contain SInt16 values or something else.
So you must be aware of your output type when you want to copy the contents of mData around.
If you know the format you could simply create a c-array

dataCopy = calloc(dataSize, sizeof(Float32));

and memcpy audioBufferList.mBuffers[i].mData into that.
If you want to use a cocoa NSMutableArray, you would have to wrap the floats into a NSNumber object.

weichsel
Or you could create an NSMutableData holding `dataSize` bytes and `memcpy` the `mData` into the data's `mutableBytes`.
Peter Hosey