在我的代码中,我设置了一个包含两个音频单元的音频处理图:一个 I/O 单元和一个多通道混音器单元。首先是 I/O 单元:
bool RtApiIos::setupAU(void *handle, AURenderCallbackStruct inRenderProc, AudioStreamBasicDescription &outFormat)
{
AudioUnitHandle *auHandle = (AudioUnitHandle *)handle;
AudioComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_RemoteIO;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
AudioComponent comp = AudioComponentFindNext( NULL, &desc );
if (AudioComponentInstanceNew(comp, &auHandle->audioUnit))
return false;
if (AudioUnitSetProperty(auHandle->audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inRenderProc, sizeof(inRenderProc)))
return false;
然后是多通道混音器单元:
AudioComponentDescription mixerDesc;
mixerDesc.componentType = kAudioUnitType_Mixer;
mixerDesc.componentSubType = kAudioUnitSubType_MultiChannelMixer;
mixerDesc.componentManufacturer = kAudioUnitManufacturer_Apple;
mixerDesc.componentFlags = 0;
mixerDesc.componentFlagsMask = 0;
comp = AudioComponentFindNext( NULL, &mixerDesc );
if (AudioComponentInstanceNew(comp, &auHandle->mixerUnit))
return false;
UInt32 busCount = 1;
if( AudioUnitSetProperty(auHandle->mixerUnit, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &busCount, sizeof(busCount)) )
return false;
if (AudioUnitSetProperty(auHandle->mixerUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inRenderProc, sizeof(inRenderProc)))
return false;
size = sizeof(localFormat);
if (AudioUnitGetProperty(auHandle->mixerUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &localFormat, &size ))
return false;
if( AudioUnitSetProperty(auHandle->mixerUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Output, 0, &localFormat.mSampleRate, sizeof(localFormat.mSampleRate)))
return false;
我启动了处理图,然后我们就出发了。音频播放正常,但例程的最后一次调用对平移没有声音影响(并且“err”== 0)。
// Declare and instantiate an audio processing graph
NewAUGraph(&auHandle->processingGraph);
AUNode mixerNode;
AUGraphAddNode(auHandle->processingGraph, &mixerDesc, &mixerNode);
AUNode ioNode;
AUGraphAddNode(auHandle->processingGraph, &desc, &ioNode);
// Indirectly performs audio unit instantiation
if (AUGraphOpen(auHandle->processingGraph))
return false;
if( AUGraphConnectNodeInput(auHandle->processingGraph, mixerNode, 0, ioNode, 0) )
return false;
if (AUGraphInitialize(auHandle->processingGraph))
return false;
AudioUnitParameterValue panValue = 0.9; // panned almost dead-right. possible values are between -1 and 1
OSStatus err = AudioUnitSetParameter(auHandle->mixerUnit, kMultiChannelMixerParam_Pan, kAudioUnitScope_Output, 0, panValue, 0);
if (err != noErr) {
//error setting pan
}
}
我究竟做错了什么?谢谢!!