我正在尝试编写一个添加音效的 iOS 应用程序。我正在尝试在 auconverter 和 remoteIO 之间放置一个效果音频单元(例如,失真和混响)。设置好所说的AU后,没有声音。
NewAUGraph(&mAuGraph);
AUGraphOpen(mAuGraph);
AUNode remoteOutputNode, converterNode, effectNode;
AudioUnit remoteIOAudioUnit, converterUnit, effectUnit;
AudioComponentDescription cd;
cd.componentManufacturer = kAudioUnitManufacturer_Apple;
cd.componentFlags = cd.componentFlagsMask = 0;
// remote io
cd.componentType = kAudioUnitType_Output;
cd.componentSubType = kAudioUnitSubType_RemoteIO;
AUGraphAddNode(mAuGraph, &cd, &remoteOutputNode);
// converter
cd.componentType = kAudioUnitType_FormatConverter;
cd.componentSubType = kAudioUnitSubType_AUConverter;
AUGraphAddNode(mAuGraph, &cd, &converterNode);
// ipodeq
cd.componentType = kAudioUnitType_Effect;
cd.componentSubType = kAudioUnitSubType_Distortion;
AUGraphAddNode(mAuGraph, &cd, &effectNode);
//callback
AURenderCallbackStruct callbackStruct;
callbackStruct.inputProc = renderCallback;
callbackStruct.inputProcRefCon = &audioDataInfo;
AUGraphSetNodeInputCallback(mAuGraph, converterNode, 0, &callbackStruct);
// set audio unit asbd
AudioStreamBasicDescription audioFormat = AUCanonicalASBD(44100.0, audioDataInfo.inputFormat.mChannelsPerFrame);
AUGraphNodeInfo(mAuGraph, converterNode, NULL, &converterUnit);
AudioUnitSetProperty(converterUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &audioDataInfo.inputFormat, sizeof(AudioStreamBasicDescription));
AudioUnitSetProperty(converterUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &audioFormat, sizeof(AudioStreamBasicDescription));
// get effect unit
AUGraphNodeInfo(mAuGraph, effectNode, NULL, &effectUnit);
// set effect unit asbd
AudioUnitSetProperty(effectUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &audioFormat, sizeof(AudioStreamBasicDescription));
AudioUnitSetProperty(effectUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &audioFormat, sizeof(audioFormat));
// set remoteio unit asbd
AUGraphNodeInfo(mAuGraph, remoteOutputNode, 0, &remoteIOAudioUnit);
AudioUnitSetProperty(remoteIOAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &audioFormat, sizeof(AudioStreamBasicDescription));
AUGraphConnectNodeInput(mAuGraph, converterNode, 0, effectNode, 0);
AUGraphConnectNodeInput(mAuGraph, effectNode, 0, remoteOutputNode, 0);
AUGraphInitialize(mAuGraph);
在AUGraphConnectNodeInput
部分,如果没有
AUGraphConnectNodeInput(mAuGraph, converterNode, 0, effectNode, 0);
AUGraphConnectNodeInput(mAuGraph, effectNode, 0, remoteOutputNode, 0);
但
AUGraphConnectNodeInput(mAuGraph, converterNode, 0, remoteOutputNode, 0);
它产生没有效果的声音。