AUGraphAddNode -10862

AUGraphAddNode -10862

我想实现音频单元模式,I/O通过下面的Through.My代码

    OSStatus result = noErr;
    result = NewAUGraph(&audioGraph);
    if (noErr != result) {[self printErrorMessage: @"NewAUGraph" withStatus: result]; return;}

    // 2.add AUNode
    AUNode inputNode;
    AUNode outputNode;

    // client format audio goes into the mixer
    clientFromat.SetCanonical(1, true);
    clientFromat.mSampleRate = kGraphSampleRate;
    clientFromat.Print();

    CAComponentDescription input_desc(kAudioUnitType_Output,kAudioUnitSubType_RemoteIO,kAudioUnitManufacturer_Apple);
    CAComponentDescription output_desc(kAudioUnitType_Output,kAudioUnitSubType_RemoteIO,kAudioUnitManufacturer_Apple);

    result = AUGraphAddNode(audioGraph, &input_desc, &inputNode);
    if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for Mixer unit" withStatus: result]; return;}

    result = AUGraphAddNode(audioGraph, &output_desc, &outputNode); // this line crash
    if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for Mixer unit" withStatus: result]; return;}

result = AUGraphAddNode(audioGraph, &output_desc, &outputNode);这行 crashed.Why?如何在没有渲染调用功能的情况下将输入音频直接发送到输出硬件?

我知道-10862的意思是input_descout_desc都是kAudioUnit_Output,AUGraph只能有一个输出节点。下面是正确的代码。

  OSStatus result = noErr;
    result = NewAUGraph(&audioGraph);
    if (noErr != result) {[self printErrorMessage: @"NewAUGraph" withStatus: result]; return;}

    // 2.add AUNode
    AUNode ioNode;

    // client format audio goes into the mixer
    clientFromat.SetCanonical(1, true);
    clientFromat.mSampleRate = kGraphSampleRate;
    clientFromat.Print();

    CAComponentDescription io_desc(kAudioUnitType_Output,kAudioUnitSubType_RemoteIO,kAudioUnitManufacturer_Apple);

    result = AUGraphAddNode(audioGraph, &io_desc, &ioNode);
    if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for Mixer unit" withStatus: result]; return;}

    // 3.open augraphic
    result = AUGraphOpen(audioGraph);
    if (noErr != result) {[self printErrorMessage: @"AUGraphOpen" withStatus: result]; return;}

    // 4.get audio unit instance from nodes
    result = AUGraphNodeInfo(audioGraph, ioNode, NULL, &ioUnit);
    if (result) { printf("AUGraphNodeInfo result %ld %08X %4.4s\n", result, (unsigned int)result, (char*)&result); return; }

    // 5. set audio unit property
    CAStreamBasicDescription outputFormat;
    // output format
    outputFormat.SetAUCanonical(1, false);
    outputFormat.mSampleRate = kGraphSampleRate;
    outputFormat.Print();

    AudioUnitElement inputBus = 1;
    UInt32 enableInput = 1;
    result = AudioUnitSetProperty(ioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, inputBus, &enableInput, sizeof(enableInput));

    // 6.connect input->eq->output node        
    result = AUGraphConnectNodeInput(audioGraph, ioNode, 1,ioNode, 0);
    if (result) { printf("AUGraphConnectNodeInput result %lu %4.4s\n", result, (char*)&result); return; }


    // 7. initialize graphic
    result = AUGraphInitialize(audioGraph);
    if (result) { printf("AUGraphInitialize result %ld %08X %4.4s\n", result, (unsigned int)result, (char*)&result); return; }
    CAShow(audioGraph);