Reading audio with Extended Audio File Services (ExtAudioFileRead)

Posted by Paperflyer on Stack Overflow See other posts from Stack Overflow or by Paperflyer
Published on 2010-03-15T20:29:10Z Indexed on 2010/03/15 20:29 UTC
Read the original article Hit count: 635

Filed under:
|
|

I am working on understanding Core Audio, or rather: Extended Audio File Services

Here, I want to use ExtAudioFileRead() to read some audio data from a file.
This works fine as long as I use one single huge buffer to store my audio data (that is, one AudioBuffer). As soon as I use more than one AudioBuffer, ExtAudioFileRead() returns the error code -50 ("error in parameter list"). As far as I can figure out, this means that one of the arguments of ExtAudioFileRead() is wrong. Probably the audioBufferList.

I can not use one huge buffer because then, dataByteSize would overflow its UInt32-integer range with huge files.

Here is the code to create the 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);
}

UInt32 numFrames = fileLengthInFrames;
error = ExtAudioFileRead(extAudioFileRef,
                         &numFrames,
                         audioBufferList);

Do you know what I am doing wrong here?

© Stack Overflow or respective owner

Related posts about coreaudio

Related posts about objective-c