In my code, I set up an audio processing graph with two audio units: an I/O unit, and a multichannel mixer unit. First the I/O unit:
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;
Then the multichannel mixer unit:
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;
I start up the processing graph, and off we go. The audio plays OK, but the last call of the routine has no audible effect on the pan (and "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
}
}
What am I doing wrong? Thanks!!