xcode - AUiPodEQ AUGraph

时间:2015-05-13 14:52:02

标签: xcode avfoundation core-audio equalizer

我正在使用AVAudioplayer为iOS开发音乐应用程序,我希望在其中实现均衡器。 我在互联网上搜索了一个很好的解决方案,最终得到了像这样的AUGraph配置:

// multichannel mixer unit
AudioComponentDescription mixer_desc;
mixer_desc.componentType = kAudioUnitType_Mixer;
mixer_desc.componentSubType = kAudioUnitSubType_MultiChannelMixer;
mixer_desc.componentManufacturer = kAudioUnitManufacturer_Apple;
mixer_desc.componentFlags = 0;
mixer_desc.componentFlagsMask = 0;
// iPodEQ unit
AudioComponentDescription eq_desc;
eq_desc.componentType = kAudioUnitType_Effect;
eq_desc.componentSubType = kAudioUnitSubType_AUiPodEQ;
eq_desc.componentManufacturer =  kAudioUnitManufacturer_Apple;
eq_desc.componentFlags = 0;
eq_desc.componentFlagsMask = 0;
// output unit
AudioComponentDescription output_desc;
output_desc.componentType = kAudioUnitType_Output;
output_desc.componentSubType = kAudioUnitSubType_GenericOutput;
output_desc.componentManufacturer =  kAudioUnitManufacturer_Apple;
output_desc.componentFlags = 0;
output_desc.componentFlagsMask =  0;

// create a new AUGraph
OSStatus result = NewAUGraph(&mGraph);
// Add Audio Nodes to graph
AUNode outputNode;
AUNode eqNode;
AUNode mixerNode;
AUGraphAddNode(mGraph, &mixer_desc, &mixerNode);
AUGraphAddNode(mGraph, &eq_desc, &eqNode);

AUGraphAddNode(mGraph, &output_desc, &outputNode);

// open the graph AudioUnits (but not initialized)
result = AUGraphOpen(mGraph);
// grab the audio unit instances from the nodes
AudioUnit mEQ;
AudioUnit mMixer;
result = AUGraphNodeInfo(mGraph, mixerNode, NULL, &mMixer);
result = AUGraphNodeInfo(mGraph, eqNode, NULL, &mEQ);

// set number of input buses for the mixer Audio Unit
UInt32 numbuses = 0;
AudioUnitSetProperty ( mMixer, kAudioUnitProperty_ElementCount,
                      kAudioUnitScope_Input, 0, &numbuses, sizeof(numbuses));

// get the equalizer factory presets list
CFArrayRef mEQPresetsArray;
UInt32 sizeof1 = sizeof(mEQPresetsArray);
AudioUnitGetProperty(mEQ, kAudioUnitProperty_FactoryPresets,
                     kAudioUnitScope_Global, 0, &mEQPresetsArray, &sizeof1);


result = AUGraphConnectNodeInput(mGraph, mixerNode, 0, eqNode, 0);
result = AUGraphConnectNodeInput(mGraph, eqNode, 0, outputNode, 0);

AudioUnitSetParameter(mMixer, kMultiChannelMixerParam_Enable, kAudioUnitScope_Input, 0, 1, 0);

AUPreset *aPreset = (AUPreset*)CFArrayGetValueAtIndex(mEQPresetsArray, 7);
AudioUnitSetProperty (mEQ, kAudioUnitProperty_PresentPreset,
                      kAudioUnitScope_Global, 0, aPreset, sizeof(AUPreset));

AUGraphInitialize(mGraph);
AUGraphStart(mGraph);

AUGraph正在运行,但EQ并未应用。论证' 7' in AUPreset *aPreset = (AUPreset*)CFArrayGetValueAtIndex(mEQPresetsArray, 7);是应该应用的均衡器的索引。 (电子) 我通过记录mEQPresetsArray - Array:

的值来获取该索引
for (int i = 0; i < CFArrayGetCount(mEQPresetsArray); i++) {
    AUPreset *aPreset = (AUPreset*)CFArrayGetValueAtIndex(mEQPresetsArray, i);
    NSLog(@"%d: %@", (int)aPreset->presetNumber, aPreset->presetName);
}

如何解决我的问题?我已经尝试过NVDSP了,但它似乎也没有起作用。我没有在互联网上找到任何其他解决方案。

先谢谢Fabian。

2 个答案:

答案 0 :(得分:0)

如果这适用于iOS,则需要使用kAudioUnitSubType_RemoteIO而不是kAudioUnitSubType_GenericOutput。

答案 1 :(得分:0)

你不能使用AVAudioPlayer来做你的EQ,你需要AVPlayer。

请点击此处查看使用音频水龙头的示例项目:

https://developer.apple.com/library/ios/samplecode/AudioTapProcessor/Introduction/Intro.html