I'm trying to do some audio processing with the new AVAudioUnits / AVAudioNodes. As the AVAudioUnits expose their underlying (classic CA) AudioUnit, I assumed I could simply attach a render callback as always, but the callback never gets called.
Here’s the code I’m talking about:
AVAudioUnitReverb *reverbUnit = [[AVAudioUnitReverb alloc] init];
AURenderCallbackStruct renderCallbackStruct;
renderCallbackStruct.inputProc = &myRenderCallback;
renderCallbackStruct.inputProcRefCon = myAudioStruct;
AudioUnitSetProperty(reverbUnit.audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Global, 0, &renderCallbackStruct, sizeof(renderCallbackStruct));
And the render callback looks basically like the following:
OSStatus myRenderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData) {
printf("callback!");
return noErr;
}
The reverbUnit is of course attached to the engine (PlayerNode -> Reverb -> MainMixer
) and I can hear the audio from the player (reverberated) as expected.
Note: When I set the callback via
AudioUnitAddRenderNotify(reverbUnit, &myRenderCallback, myAudioStruct)
it gets called, but then the ioData->mBuffers[0].mData
is nil (which is correct AFAIK), so this is not an alternative.