2

I am in the practice of Audio Unit API.

I've added the kAudioUnitType_Effect to a sound buffer offline and play the sound with reverb sucessfully , as demo in the official demo code: "AVCaptureToAudioUnit" The AUGraph is AUconverter->AUeffect->RIO output.

But when I try to add the effect to play realtime input sound with the AUGraph: RIO input->AUeffect->RIO output. It makes no sound at all. Is there any mistakes I made?

Best

Vincent

// 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");

0 Answers0