Saving AudioBuffer Lists from ExtAudioFile API for Later Use

Using Xcode / Cocoa and the ExtAudioFile API, I am trying to save AudioBufferList * objects for later use, but I'm having trouble re-accessing data. These objects come from repeating calls to ExtAudioFileRead.

I understand that I cannot just put these AudioBufferList * objects in an NSArray, but I got the impression that NSPointerArray would work for this purpose. However, when you try to access the audioBufferList-> mBuffers [0] .mData files after storing the sound buffer lists in NSPointerArray, they simply return to zero.

I have been memcpying audioBufferLists for new audioBufferList objects since I am reusing the same sound buffer list for every call to ExtAudioFileRead. I'm not sure if this is enough, and memcpying objects void * audioBufferList-> mBuffers [0] .mData doesn't help either.

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

+4
source share
1 answer

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

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 a Float32 typedef)

If you choose a different format, the array may contain SInt16 values ​​or something else.
Therefore, you should know your type of output when you want to copy the contents of mData.
If you know the format, you can just create a c-array

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

and memcpy audioBufferList.mBuffers [i] .mData into this.
If you want to use cocoa NSMutableArray, you will have to wrap the floats in an NSNumber object.

+5
source

All Articles