iljawascoding
iljawascoding

Reputation: 1110

Add Node with custom render proc the AUGraph

Anybody knows the magic recipe to add a node with a custom render function in between existing filter nodes to an AUGraph on macOS. No matter if I use AUGraphSetNodeInputCallback or AudioUnitSetProperty to set my custom render callback, my render callback is not being called. Are kAudioUnitType_Effect and kAudioUnitSubType_AUFilter the correct params for setting up such a node?

OSStatus AudioEngineGraph::BuildCustomGraphNode (AudioEngineGraphInput& inInput, AUGraph inGraph, std::shared_ptr<AudioEngineGraphNode> inNode) {
    AudioComponentDescription outputcd = {0};
    OSStatus                  err;

    outputcd.componentType = kAudioUnitType_Effect;
    outputcd.componentSubType = kAudioUnitSubType_AUFilter;
    outputcd.componentManufacturer = kAudioUnitManufacturer_Apple;

    err = AUGraphAddNode(inGraph, &outputcd, &(inNode->mNode));
    checkErrAndReturn("AUGraphAddNode", err);
    err = AUGraphNodeInfo(inGraph, (inNode->mNode), NULL, &(inNode->mUnit));
    checkErrAndReturn("AUGraphNodeInfo", err);
}

// connect all the nodes in my graph, then set the render callback


    AURenderCallbackStruct callbackStruct;

    callbackStruct.inputProc = myRenderProc;
    callbackStruct.inputProcRefCon = &inInput;
    
    //checkErr(AudioUnitSetProperty(inNode->mUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &callbackStruct, sizeof(callbackStruct)));

    checkErr (AUGraphSetNodeInputCallback(inGraph, inNode->mNode, 0, &callbackStruct));

Upvotes: 1

Views: 30

Answers (1)

iljawascoding
iljawascoding

Reputation: 1110

You need to build your own Swift/Objective-C subclass of AUAudioUnit that includes your custom filter code. Once you have registered that with CoreAudio, you can create a node in your AudioGraph using your custom unit. Why can't things be easy? Found that source code helpful (but a little buggy): https://github.com/GeorgeMcMullen/AudioUnitV3Example/blob/0ab6f2feb953d37e4e7b2359627b97858b317bc8/Filter/Shared/FilterDemo.mm

Upvotes: 1

Related Questions