Skip to content

Instantly share code, notes, and snippets.

@standinga
Last active September 26, 2019 01:29
Show Gist options
  • Save standinga/5181ae41b714bc3e5790c8016c2c305f to your computer and use it in GitHub Desktop.
Save standinga/5181ae41b714bc3e5790c8016c2c305f to your computer and use it in GitHub Desktop.
updated internalRenderBlock
- (AUInternalRenderBlock)internalRenderBlock {
// Capture in locals to avoid ObjC member lookups. If "self" is captured in render, we're doing it wrong. See sample code.
__block Buffer* buffer = &_buffer;
return ^AUAudioUnitStatus(AudioUnitRenderActionFlags *actionFlags, const AudioTimeStamp *timestamp, AVAudioFrameCount frameCount, NSInteger outputBusNumber, AudioBufferList *outputData, const AURenderEvent *realtimeEventListHead, AURenderPullInputBlock pullInputBlock) {
// Do event handling and signal processing here.
AudioUnitRenderActionFlags pullFlags = 0;
buffer->prepareInputBufferList();
AUAudioUnitStatus err = pullInputBlock(&pullFlags, timestamp, frameCount, 0, buffer->mutableAudioBufferList);
if (err != 0) {
NSLog(@"borama VolumePluginAudioUnit AudioUnitRenderActionFlags");
return err;
}
AudioBufferList *inAudioBufferList = buffer->mutableAudioBufferList;
AudioBufferList *outAudioBufferList = outputData;
// If passed null output buffer pointers, process in-place in the input buffer.
if (outAudioBufferList->mBuffers[0].mData == nullptr) {
for (UInt32 i = 0; i < outAudioBufferList->mNumberBuffers; ++i) {
outAudioBufferList->mBuffers[i].mData = inAudioBufferList->mBuffers[i].mData;
}
}
UInt32 samplesCount = inAudioBufferList->mBuffers[0].mDataByteSize / sizeof(float);
for (int j = 0; j < inAudioBufferList->mNumberBuffers; j++) {
float* input = (float*)inAudioBufferList->mBuffers[j].mData;
float* output = (float*)outAudioBufferList->mBuffers[j].mData;
// the might be more than one channel (stereo)
for (int i = 0; i < samplesCount; i++) {
output[i] = buffer->volume * input[i];
}
}
return noErr;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment