1

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.

max
  • 1,509
  • 1
  • 19
  • 24

1 Answers1

3

The render callback gets over-ridden by the connecting the input node of the reverb unit in the AUGraph. You can only have one input to a reverb node, either an input node or a render callback.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153