Skip to content

Instantly share code, notes, and snippets.

@standinga
Last active May 4, 2019 12:24
Show Gist options
  • Save standinga/0ed908ed78a811c8febce0469655adef to your computer and use it in GitHub Desktop.
Save standinga/0ed908ed78a811c8febce0469655adef to your computer and use it in GitHub Desktop.
Buffer.hpp struct Buffer
#import <AVFoundation/AVFoundation.h>
struct Buffer {
AVAudioPCMBuffer *pcmBuffer = nullptr;
AudioBufferList* mutableAudioBufferList = nullptr;
AudioBufferList const* originalAudioBufferList = nullptr;
AUAudioFrameCount maxFrames = 0;
float volume = 1.0;
/*
prepareInputBufferList populates the mutableAudioBufferList with the data
pointers from the originalAudioBufferList.
The upstream audio unit may overwrite these with its own pointers, so each
render cycle this function needs to be called to reset them.
*/
void prepareInputBufferList() {
UInt32 byteSize = maxFrames * sizeof(float);
mutableAudioBufferList->mNumberBuffers = originalAudioBufferList->mNumberBuffers;
for (UInt32 i = 0; i < originalAudioBufferList->mNumberBuffers; ++i) {
mutableAudioBufferList->mBuffers[i].mNumberChannels = originalAudioBufferList->mBuffers[i].mNumberChannels;
mutableAudioBufferList->mBuffers[i].mData = originalAudioBufferList->mBuffers[i].mData;
mutableAudioBufferList->mBuffers[i].mDataByteSize = byteSize;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment