yeah this stuff is a bit tricky to set up. this is how im setting up
an 8 channel mixer
-(void)intialiseAudio{
// Initialize and configure the audio session, and add an
interuption listener
AudioSessionInitialize(NULL, NULL, rioInterruptionListener, self);
NSLog(@"Audio Init");
//set the audio category
UInt32 audioCategory = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
sizeof(audioCategory), &audioCategory);
UInt32 getAudioCategory = sizeof(audioCategory);
AudioSessionGetProperty(kAudioSessionProperty_AudioCategory,
&getAudioCategory, &getAudioCategory);
if(getAudioCategory == kAudioSessionCategory_AmbientSound){
NSLog(@"kAudioSessionCategory_AmbientSound");
}
else{
NSLog(@"Could not get kAudioSessionCategory_AmbientSound");
}
//add a property listener
AudioSessionAddPropertyListener
(kAudioSessionProperty_AudioRouteChange, propListener, self);
Float32 preferredBufferSize = .00125;
AudioSessionSetProperty
(kAudioSessionProperty_PreferredHardwareIOBufferDuration,
sizeof(preferredBufferSize), &preferredBufferSize);
//set the audio session active
AudioSessionSetActive(YES);
AudioComponentDescription mixerDescription, outputDescription;
//the AUNodes
AUNode mixerNode;
AUNode outputNode;
//the graph
AUGraph graph;
OSErr err = noErr;
err = NewAUGraph(&graph);
NSAssert(err == noErr, @"Error creating graph.");
mixerDescription.componentFlags = 0;
mixerDescription.componentFlagsMask = 0;
mixerDescription.componentType = kAudioUnitType_Mixer;
mixerDescription.componentSubType =
kAudioUnitSubType_MultiChannelMixer;
mixerDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
err = AUGraphAddNode(graph, &mixerDescription, &mixerNode);
NSAssert(err == noErr, @"Error creating mixer node.");
outputDescription.componentFlags = 0;
outputDescription.componentFlagsMask = 0;
outputDescription.componentType = kAudioUnitType_Output;
outputDescription.componentSubType = kAudioUnitSubType_RemoteIO;
outputDescription.componentManufacturer =
kAudioUnitManufacturer_Apple;
err = AUGraphAddNode(graph, &outputDescription, &outputNode);
NSAssert(err == noErr, @"Error creating output node.");
err = AUGraphOpen(graph);
NSAssert(err == noErr, @"Error opening graph.");
//get the 2 audio units
AURenderCallbackStruct callback;
callback.inputProc = TestCallback;
callback.inputProcRefCon = self;
//mixer channel 0
err = AUGraphSetNodeInputCallback(graph, mixerNode, 0, &callback);
NSAssert(err == noErr, @"Error setting render callback.");
//mixer channel 1
err = AUGraphSetNodeInputCallback(graph, mixerNode, 1, &callback);
NSAssert(err == noErr, @"Error setting render callback.");
//mixer channel 2
err = AUGraphSetNodeInputCallback(graph, mixerNode, 2, &callback);
NSAssert(err == noErr, @"Error setting render callback.");
//mixer channel 3
err = AUGraphSetNodeInputCallback(graph, mixerNode, 3, &callback);
NSAssert(err == noErr, @"Error setting render callback.");
//mixer channel 4
err = AUGraphSetNodeInputCallback(graph, mixerNode, 4, &callback);
NSAssert(err == noErr, @"Error setting render callback.");
//mixer channel 5
err = AUGraphSetNodeInputCallback(graph, mixerNode, 5, &callback);
NSAssert(err == noErr, @"Error setting render callback.");
//mixer channel 6
err = AUGraphSetNodeInputCallback(graph, mixerNode, 6, &callback);
NSAssert(err == noErr, @"Error setting render callback.");
//mixer channel 7
err = AUGraphSetNodeInputCallback(graph, mixerNode, 7, &callback);
NSAssert(err == noErr, @"Error setting render callback.");
//and finally the mixer to the output node
err = AUGraphConnectNodeInput(graph, mixerNode, 0, outputNode, 0);
NSAssert(err == noErr, @"Error connecting mixer to output.");
//get the 2 audio units
err = AUGraphNodeInfo(graph, outputNode, &outputDescription, &output);
err = AUGraphNodeInfo(graph, mixerNode, &mixerDescription, &mixer);
// Describe format
audioFormat.mSampleRate = 44100.00;
audioFormat.mFormatID = kAudioFormatLinearPCM;
audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger |
kAudioFormatFlagIsPacked;
audioFormat.mFramesPerPacket = 1;
audioFormat.mChannelsPerFrame = 2;
audioFormat.mBitsPerChannel = 16;
audioFormat.mBytesPerPacket = 4;
audioFormat.mBytesPerFrame = 4;
//Apply format
err = AudioUnitSetProperty(mixer,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0,
&audioFormat,
sizeof(audioFormat));
err = AudioUnitSetProperty(mixer,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
1,
&audioFormat,
sizeof(audioFormat));
err = AudioUnitSetProperty(mixer,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
2,
&audioFormat,
sizeof(audioFormat));
err = AudioUnitSetProperty(mixer,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
3,
&audioFormat,
sizeof(audioFormat));
err = AudioUnitSetProperty(mixer,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
4,
&audioFormat,
sizeof(audioFormat));
err = AudioUnitSetProperty(mixer,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
5,
&audioFormat,
sizeof(audioFormat));
err = AudioUnitSetProperty(mixer,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
6,
&audioFormat,
sizeof(audioFormat));
err = AudioUnitSetProperty(mixer,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
7,
&audioFormat,
sizeof(audioFormat));
err = AUGraphInitialize(graph);
NSAssert(err == noErr, @"Error initializing graph.");
err = AUGraphStart(graph);
NSAssert(err == noErr, @"Error starting graph.");
CAShow(graph);