Last active
May 4, 2019 12:24
-
-
Save standinga/0ed908ed78a811c8febce0469655adef to your computer and use it in GitHub Desktop.
Buffer.hpp struct Buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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