I'm working on understanding Core Audio, more specifically: Advanced Audio File Services
Here I want to use ExtAudioFileRead() to read some audio data from a file.
This works great while I use one huge buffer to store my audio data (i.e. one AudioBuffer ). As soon as I use more than one AudioBuffer , ExtAudioFileRead() returns an error code of -50 ("error in parameter list"). As far as I can tell, this means that one of the ExtAudioFileRead() arguments is incorrect. Probably audioBufferList .
I cannot use one huge buffer, because then dataByteSize would fill its UInt32 integer range with huge files.
Here is the code to create an audioBufferList :
AudioBufferList *audioBufferList; audioBufferList = malloc(sizeof(AudioBufferList) + (numBuffers-1)*sizeof(AudioBuffer)); audioBufferList->mNumberBuffers = numBuffers; for (int bufferIdx = 0; bufferIdx<numBuffers; bufferIdx++ ) { audioBufferList->mBuffers[bufferIdx].mNumberChannels = numChannels; audioBufferList->mBuffers[bufferIdx].mDataByteSize = dataByteSize; audioBufferList->mBuffers[bufferIdx].mData = malloc(dataByteSize); }
And here is a working but overflowing code:
UInt32 dataByteSize = fileLengthInFrames * bytesPerFrame;
And finally, calling ExtAudioFileRead() (should work with both versions):
UInt32 numFrames = fileLengthInFrames; error = ExtAudioFileRead(extAudioFileRef, &numFrames, audioBufferList);
Do you know what I'm doing wrong here?
source share