Inter App Audio technology : make effect node and instrument node independent

453 views Asked by At

I am writing an HOST application that uses Core Audio's new iOS 7 Inter App Audio technology. I have managed to get the instruments apps and effects app with the help of Inter-App Audio Examples .

The issue is that the effect node is dependent upon the instrument node. I want to make effect node and instrument node independent.

Here i my Try.

if (desc.componentType == kAudioUnitType_RemoteEffect) {
//            if ([self isRemoteInstrumentConnected]) {
                if (!_engineStarted)                                    // Check if session is active
                    [self checkStartOrStopEngine];
                
                if ([self isGraphStarted])                              // Check if graph is running and or is created, if so, stop it
                    [self checkStartStopGraph];
                
                if ([self checkGraphInitialized ])                      // Check if graph has been inititialized if so, uninitialize it.
                    Check(AUGraphUninitialize(hostGraph));
                
                Check (AUGraphAddNode (hostGraph, &desc, &effectNode)); // Add remote instrument

                //Disconnect previous chain
               // Check(AUGraphDisconnectNodeInput(hostGraph, mixerNode, remoteBus));
                
                //Connect the effect node to the mixer on the remoteBus
                Check(AUGraphConnectNodeInput (hostGraph, effectNode, 0, mixerNode, remoteBus));
                
                //Connect the remote instrument node to the effect node on bus 0
                Check(AUGraphConnectNodeInput (hostGraph, instrumentNode, 0, effectNode, 0));
                
                //Grab audio units from the graph
                Check(AUGraphNodeInfo(hostGraph, effectNode, 0, &effect));
                currentUnit = &effect;
            }

if (currentUnit) {
            Check (AudioUnitSetProperty (*currentUnit,                  // Set stereo format
                                         kAudioUnitProperty_StreamFormat,
                                         kAudioUnitScope_Output,
                                         playerBus,
                                         &stereoStreamFormat,
                                         sizeof (stereoStreamFormat)));
            UInt32 maxFrames = 4096;
            Check(AudioUnitSetProperty(*currentUnit,
                                       kAudioUnitProperty_MaximumFramesPerSlice,
                                       kAudioUnitScope_Global, playerBus,
                                       &maxFrames,
                                       sizeof(maxFrames)));
            
            [self addAudioUnitPropertyListeners:*currentUnit];          // Add property listeners to audio unit
            Check(AUGraphInitialize (hostGraph));                       // Initialize the graph

            [self checkStartStopGraph];                                 //Start the graph
        }
        
        [_connectedNodes addObject:rau];

but my Application Crashes on this Line --

Check(AUGraphInitialize (hostGraph));

And the Error i got ,

ConnectAudioUnit failed with error

-10860 Initialize failed with error

-10860 error -10860 from AUGraphInitialize (hostGraph)


Note :- I have also Attached screenshot of code portion for better understand.

enter image description here

Edit 1 :-

- (void)createGraph {
    // 1
    NewAUGraph(&hostGraph);

    // 2
    AudioComponentDescription iOUnitDescription;
    iOUnitDescription.componentType =
    kAudioUnitType_Output;
    iOUnitDescription.componentSubType =
    kAudioUnitSubType_RemoteIO;
    iOUnitDescription.componentManufacturer =
    kAudioUnitManufacturer_Apple;
    iOUnitDescription.componentFlags = 0;
    iOUnitDescription.componentFlagsMask = 0;
    AUGraphAddNode(hostGraph, &iOUnitDescription, &outNode);

    // 3
    AUGraphOpen(hostGraph);

    // 4
    Check(AUGraphNodeInfo(hostGraph, outNode, 0, &outputUnit));
    // 5
    AudioStreamBasicDescription format;
    format.mChannelsPerFrame = 2;
    format.mSampleRate =
    [[AVAudioSession sharedInstance] sampleRate];
    format.mFormatID = kAudioFormatLinearPCM;
    format.mFormatFlags =
    kAudioFormatFlagsNativeFloatPacked |
    kAudioFormatFlagIsNonInterleaved;
    format.mBytesPerFrame = sizeof(Float32);
    format.mBytesPerPacket = sizeof(Float32);
    format.mBitsPerChannel = 32;
    format.mFramesPerPacket = 1;

    AudioUnitSetProperty(mixerUnit,
                         kAudioUnitProperty_StreamFormat,
                         kAudioUnitScope_Output,
                         1,
                         &format,
                         sizeof(format));

    AudioUnitSetProperty(mixerUnit,
                         kAudioUnitProperty_StreamFormat,
                         kAudioUnitScope_Input,
                         0,
                         &format,
                         sizeof(format));
    CAShow(hostGraph);
}
1

There are 1 answers

2
BHendricks On

So the error you're seeing, as per apple docs, is due to The specified node cannot be found.

It looks like you've taken the Apple example app you linked and just deleted a bit to attempt to remove 1 node, but I don't believe its that simple. The documentation of the example clearly states the two nodes are dependent. Just changing the addition of remotes method is not going to be enough, because the host still is attempting to create both, as shown by the error you're seeing.

From this file in the example project, you are only showing the changes you made to addRemoteAU but you need to be making changes to createGraph as well, since that is where the hostGraph is initialized with its nodes. If you initialize the graph with only 1 node, then in addRemoteAU you should stop seeing an error due to a node not being found, since the graph at that point won't expect two nodes (which it does now from it's creation).