AUGraphAddNode -10862

我想实现一个audio单元模式,I / O Pass 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); 这条线坠毁了,为什么? 如何将传入的audio直接发送到输出硬件没有渲染调用function?

我知道-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);