问题
I want to implement a Audio Unit pattern,I/O Pass Through.My code below
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); this line crashed.Why? How to sends incoming audio directly to the output hardware without render call function ?
回答1:
I know -10862 mean is that input_desc
and out_desc
are all kAudioUnit_Output
, AUGraph can have only one output node. And the correct code below here.
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);
来源:https://stackoverflow.com/questions/36325291/augraphaddnode-10862