8

我正在尝试制作一个 10 波段均衡器,kAudioUnitSubType_NBandEQ音频单元似乎是可行的方法,但 Apple 的文档并未涵盖如何设置/配置它。

我已经连接了节点,但是当我尝试将 EQNode 与 iONode(输出)连接时出错:https ://gist.github.com/2295463

如何将效果转换为有效的 10 段均衡器?

更新: 使用Novocaine的有效 DSP 配方也是一种解决方案,任何想法!那些 DSP 公式相当复杂。

更新 2 :我更喜欢使用Novocaine 的有效 DSP 公式,因为它比编程音频节点更干净/更小。

更新 3: “Multitype EQ 单元(子类型 kAudioUnitSubType_NBandEQ)提供了一个均衡器,可以配置为“Mutitype EQ Unit Filter Types”(第 68 页)中描述的任何一种类型。” 来源: http: //developer.apple.com/library/ios/DOCUMENTATION/AudioUnit/Reference/AudioUnit_Framework/AudioUnit_Framework.pdf 但仍然没有例子。

重要更新 (17/05):我建议大家使用我在 github 上发布的 DSP 类:https ://github.com/bartolsthoorn/NVDSP它可能会为您节省很多工作。它将使开发 n 波段均衡器或任何类型的音频滤波器变得轻而易举。

4

2 回答 2

3

我是 Novocaine 的创造者,我用它使用 vDSP 制作了一个 200 多个频段的 EQ。

我正在考虑切换到 NBandEQ 音频单元,但我有一个使用 vDSP_deq22 的工作解决方案。

vDSP_deq22 使用二阶 IIR 滤波器一次过滤一个样本数据。您可以在 musicdsp.org 上找到二阶巴特沃斯系数,或者更一般地通过 Google 搜索。如果您可以访问副本,Matlab 也会为您计算它们。我使用了musicdsp.org。您将创建 10 个 vDSP_deq22 滤波器,通过每个滤波器运行您的音频,将该频段乘以指定的增益,然后将滤波器组中所有滤波器的输出相加到您的输出音频中。

于 2012-04-19T21:07:13.667 回答
2

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
于 2012-04-11T06:10:23.617 回答