2

我正在练习 Audio Unit API。

我已将 kAudioUnitType_Effect 添加到离线声音缓冲区并成功播放带有混响的声音,如官方演示代码中的演示:“AVCaptureToAudioUnit” AUGraph 是 AUconverter->AUeffect->RIO 输出。

但是当我尝试添加效果以使用 AUGraph 播放实时输入声音时:RIO 输入->AUeffect->RIO 输出。它根本没有声音。我犯了什么错误吗?

最好的

文森特

// describe unit   AudioComponent
AudioComponentDescription audioCompDesc;
audioCompDesc.componentType = kAudioUnitType_Output;
audioCompDesc.componentSubType = kAudioUnitSubType_RemoteIO;
audioCompDesc.componentManufacturer = kAudioUnitManufacturer_Apple;
audioCompDesc.componentFlags = 0;
audioCompDesc.componentFlagsMask = 0;

// get rio unit from audio component manager
AudioComponent rioComponent = AudioComponentFindNext(NULL, &audioCompDesc);
//create Instance
CheckError(AudioComponentInstanceNew(rioComponent, &_effectState.rioUnit),
           "Couldn't get RIO unit instance");


// describe unit   AudioComponent
AudioComponentDescription audioCompDesc2;
audioCompDesc2.componentType = kAudioUnitType_FormatConverter;
audioCompDesc2.componentSubType = kAudioUnitSubType_AUConverter;
audioCompDesc2.componentManufacturer = kAudioUnitManufacturer_Apple;
audioCompDesc2.componentFlags = 0;
audioCompDesc2.componentFlagsMask = 0;

// get rio unit from audio component manager
AudioComponent converterComponent = AudioComponentFindNext(NULL, &audioCompDesc2);
//create Instance
CheckError(AudioComponentInstanceNew(converterComponent, &_effectState.converterUnit),
           "Couldn't get RIO unit instance");

// describe unit   AudioComponent
AudioComponentDescription audioCompDesc3;
audioCompDesc3.componentType = kAudioUnitType_Effect;
audioCompDesc3.componentSubType = kAudioUnitSubType_Reverb2;
audioCompDesc3.componentManufacturer = kAudioUnitManufacturer_Apple;
audioCompDesc3.componentFlags = 0;
audioCompDesc3.componentFlagsMask = 0;


// get rio unit from audio component manager
AudioComponent reverbComponent = AudioComponentFindNext(NULL, &audioCompDesc3);
//create Instance
CheckError(AudioComponentInstanceNew(reverbComponent, &_effectState.reverbUnit),
           "Couldn't get RIO unit instance");

AudioUnitElement ioUnitInputElement  = 1;
AudioUnitElement converterUnitOutputBus = 0;
AudioUnitElement reverbUnitOutputBus = 0;
AudioUnitElement ioUnitOutputElement = 0;

AudioUnitConnection ioUnitOutToIoconverterUnitIn;
ioUnitOutToIoconverterUnitIn.sourceAudioUnit    = _effectState.rioUnit;
ioUnitOutToIoconverterUnitIn.sourceOutputNumber = ioUnitInputElement;
ioUnitOutToIoconverterUnitIn.destInputNumber    = converterUnitOutputBus;

AudioUnitSetProperty (
                      _effectState.converterUnit,                     // connection destination
                      kAudioUnitProperty_MakeConnection,  // property key
                      kAudioUnitScope_Input,              // destination scope
                      converterUnitOutputBus,                // destination element
                      &ioUnitOutToIoconverterUnitIn,                // connection definition
                      sizeof (ioUnitOutToIoconverterUnitIn)
                      );


AudioUnitConnection converterOutToreverbIn;
converterOutToreverbIn.sourceAudioUnit    = _effectState.converterUnit;
converterOutToreverbIn.sourceOutputNumber = converterUnitOutputBus;
converterOutToreverbIn.destInputNumber    = reverbUnitOutputBus;

AudioUnitSetProperty (
                      _effectState.reverbUnit,                     // connection destination
                      kAudioUnitProperty_MakeConnection,  // property key
                      kAudioUnitScope_Input,              // destination scope
                      reverbUnitOutputBus,                // destination element
                      &converterOutToreverbIn,                // connection definition
                      sizeof (converterOutToreverbIn)
                      );




// AudioUnitElement reverbUnitOutputBus  = 0;
 //AudioUnitElement ioUnitOutputElement = 0;

 AudioUnitConnection reverbOutToIoUnitIn;
 reverbOutToIoUnitIn.sourceAudioUnit    = _effectState.reverbUnit;
 reverbOutToIoUnitIn.sourceOutputNumber = reverbUnitOutputBus;
 reverbOutToIoUnitIn.destInputNumber    = ioUnitOutputElement;

 AudioUnitSetProperty (
 _effectState.rioUnit,                     // connection destination
 kAudioUnitProperty_MakeConnection,  // property key
 kAudioUnitScope_Input,              // destination scope
 ioUnitOutputElement,                // destination element
 &reverbOutToIoUnitIn,                // connection definition
 sizeof (reverbOutToIoUnitIn)
                       );

CheckError(AudioUnitInitialize(_effectState.rioUnit),"Couldn't initialize RIO unit");

CheckError(AudioUnitInitialize(_effectState.converterUnit),"Couldn't initialize RIO unit");

CheckError(AudioUnitInitialize(_effectState.reverbUnit),"Couldn't initialize RIO unit");

CheckError (AudioOutputUnitStart (_effectState.rioUnit),"Couldn't start RIO unit");
4

0 回答 0