10段均衡器可配置如下
转换器节点-> eqNode-> 转换器节点-> ioNode。
请参考下面的示例代码。在这里,我使用了 iPodEQ 单元。用 10 段均衡器替换 iPodEQunit 格式规范。
AUNode outputNode;
AUNode iPodTimeNode;
AUNode converterNode;
AUNode converterNode2;
AudioUnit converterAU;
AudioUnit converterAU2;
printf("create client format ASBD\n");
// client format audio going into the converter
mClientFormat.SetCanonical(1, false);
mClientFormat.mSampleRate = kGraphSampleRate;
mClientFormat.Print();
printf("create output format ASBD\n");
CAStreamBasicDescription localOutput;
localOutput.SetAUCanonical(2, false);
localOutput.mSampleRate = kGraphSampleRate;
// output format
mOutputFormat.SetCanonical(1, false);
mOutputFormat.mSampleRate = kGraphSampleRate;
mOutputFormat.Print();
OSStatus result = noErr;
printf("-----------\n");
printf("new AUGraph\n");
// create a new AUGraph
result = NewAUGraph(&mGraph);
if (result) { printf("NewAUGraph result %ld %08X %4.4s\n", result,
(unsigned int)result, (char*)&result); return; }
// create three CAComponentDescription for the AUs we want in the graph
// output unit
CAComponentDescription output_desc(kAudioUnitType_Output,
kAudioUnitSubType_GenericOutput,
kAudioUnitManufacturer_Apple);
// iPodTime unit
CAComponentDescription iPodTime_desc(kAudioUnitType_FormatConverter,
kAudioUnitSubType_AUiPodTimeOther,
kAudioUnitManufacturer_Apple);
// AU Converter
CAComponentDescription converter_desc(kAudioUnitType_FormatConverter,
kAudioUnitSubType_AUConverter,
kAudioUnitManufacturer_Apple);
printf("add nodes\n");
// create a node in the graph that is an AudioUnit, using the supplied
// AudioComponentDescription to find and open that unit
result = AUGraphAddNode(mGraph, &output_desc, &outputNode);
result = AUGraphAddNode(mGraph, &iPodTime_desc, &iPodTimeNode);
result = AUGraphAddNode(mGraph, &converter_desc, &converterNode);
result = AUGraphAddNode(mGraph, &converter_desc, &converterNode2);
// connect a node's output to a node's input
// converter -> iPodTime ->converter-> output
result = AUGraphConnectNodeInput(mGraph, converterNode2, 0, iPodTimeNode, 0);
result = AUGraphConnectNodeInput(mGraph, iPodTimeNode, 0, converterNode, 0);
result = AUGraphConnectNodeInput(mGraph, converterNode, 0, outputNode, 0);
// open the graph -- AudioUnits are open but not initialized
// (no resource allocation occurs here)
result = AUGraphOpen(mGraph);
// grab audio unit instances from the nodes
result = AUGraphNodeInfo(mGraph, converterNode, NULL, &converterAU);
result = AUGraphNodeInfo(mGraph, converterNode2, NULL, &converterAU2);
result = AUGraphNodeInfo(mGraph, iPodTimeNode, NULL, &mIPodTime);
result = AUGraphNodeInfo(mGraph, outputNode, NULL, &mOutputUnit);
//Get EQ unit format
UInt32 size ;
CAStreamBasicDescription eqDesc;
AudioUnitGetProperty(mIPodTime, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &eqDesc, &size);
eqDesc.Print();
// setup render callback struct
AURenderCallbackStruct rcbs;
rcbs.inputProc = &renderInput;
rcbs.inputProcRefCon = &mUserData;
printf("set AUGraphSetNodeInputCallback\n");
// set a callback for the specified node's specified input bus (bus 1)
result = AUGraphSetNodeInputCallback(mGraph, converterNode2, 0, &rcbs);
//SetFormat
result = AudioUnitSetProperty(converterAU2, kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input, 0, &mClientFormat, sizeof(mClientFormat));
result = AudioUnitSetProperty(converterAU2, kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output, 0, &eqDesc, sizeof(eqDesc));
printf("set converter input bus %d client kAudioUnitProperty_StreamFormat\n", 0);
// set the input stream format, this is the format of the audio
// for the converter input bus (bus 1)
result = AudioUnitSetProperty(converterAU, kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input, 0, &localOutput, sizeof(localOutput));
// in an au graph, each nodes output stream format (including sample rate)
// needs to be set explicitly this stream format is propagated to its
// destination's input stream format
printf("set converter output kAudioUnitProperty_StreamFormat\n");
// set the output stream format of the converter
result = AudioUnitSetProperty(converterAU, kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output, 0, &mOutputFormat, sizeof(mOutputFormat));
result = AudioUnitSetProperty(mOutputUnit, kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output, 0, &mOutputFormat, sizeof(mOutputFormat));
// set the output stream format of the iPodTime unit
result = AudioUnitSetProperty(mIPodTime, kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output, 0, &localOutput, sizeof(localOutput));
printf("AUGraphInitialize\n");
// add a render notification, this is a callback that the graph will call every time the graph renders
// the callback will be called once before the graph’s render operation, and once after the render operation is complete