xcode - AUiPodEQ AUGraph
xcode - AUiPodEQ AUGraph
我正在使用 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。 AUPreset *aPreset = (AUPreset*)CFArrayGetValueAtIndex(mEQPresetsArray, 7);
中的参数 '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。
如果这是 iOS,那么您需要使用 kAudioUnitSubType_RemoteIO 而不是 kAudioUnitSubType_GenericOutput。
您不能使用 AVAudioPlayer 来做 EQ,您需要 AVPlayer。
请在此处查看使用音频分路器的示例项目:
https://developer.apple.com/library/ios/samplecode/AudioTapProcessor/Introduction/Intro.html
我正在使用 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。 AUPreset *aPreset = (AUPreset*)CFArrayGetValueAtIndex(mEQPresetsArray, 7);
中的参数 '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。
如果这是 iOS,那么您需要使用 kAudioUnitSubType_RemoteIO 而不是 kAudioUnitSubType_GenericOutput。
您不能使用 AVAudioPlayer 来做 EQ,您需要 AVPlayer。
请在此处查看使用音频分路器的示例项目:
https://developer.apple.com/library/ios/samplecode/AudioTapProcessor/Introduction/Intro.html