Clearing an AudioBufferList

The following code once gave me a headache bug:

    // Clear the output buffer
    for ( int i=0; i<bufferList->mNumberBuffers; i++ ) {
        memset(bufferList->mBuffers[i].mData, 0, bufferList->mBuffers[i].mDataByteSize);

Some apple audio units will change the mDataByteSize field after processing (and according to documentation may even supply an entirely new bufferList). Under some circumstances the above may therefore not yield the expected result.

I ended up writing a AudioBufferList_ClearFrames routine (which calls vDSP_vclr) and set the mDataByteSize field accordingly

    Following call is important: 
    it sets frameCount frames to 0.0, and sets mDataByteSize accordingly
    Some AudioUnits may adjust the AudioBuffer info, particularly the 
    mDataByteSize field, which obviously doesn't go well with global 
    bufferList pointers.
void AudioBufferList_ClearFrames(AudioBufferList *bufferList, UInt32 frameCount);


  • Yep, same here. I haven't seen the actual buffer pointer change (except it gives you a new buffer if mData is NULL), but have seen the mDataByteSize been changed by AUs. Clearing N frames is the right thing instead, also I set the mDatabyteSize to correct value for my global/shared buffers for each render cycle.

  • Fair enough - changed.

Sign In or Register to comment.