2 Replies - 7196 Views - Last Post: 14 February 2010 - 02:26 AM

#1 orangeslide8  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 203
  • Joined: 29-December 06

iPhone Audio Unit more than 8 Channel Mixer

Posted 29 December 2009 - 08:47 AM

Ok so I have an Audio Unit and I want to add more than 8 channels to it. I tried using two mixers like below:
-(void)initAudio{

/*

	  Getting the value of kAudioUnitProperty_ElementCount tells you how many elements you have in a scope. This happens to be 8 for this mixer.

	  If you want to increase it, you need to set this property. 

	  */

// Initialize and configure the audio session, and add an interuption listener

	AudioSessionInitialize(NULL, NULL, rioInterruptionListener, self);

	 

//set the audio category

UInt32 audioCategory = kAudioSessionCategory_LiveAudio;

AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), &audioCategory);

	 

	 

	 UInt32 getAudioCategory = sizeof(audioCategory);

AudioSessionGetProperty(kAudioSessionProperty_AudioCategory, &getAudioCategory, &getAudioCategory);

	 

if(getAudioCategory == kAudioSessionCategory_LiveAudio){

NSLog(@"kAudioSessionCategory_MediaPlayback");

	 }

else{

NSLog(@"Could not get kAudioSessionCategory_MediaPlayback");

	 }

	 

	 

//add a property listener

AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, propListener, self);

	 

//set the buffer size as small as we can

	 Float32 preferredBufferSize = .00125;

AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof(preferredBufferSize), &preferredBufferSize);

	 

//set the audio session active

AudioSessionSetActive(YES);

	 

//the descriptions for the components

	 AudioComponentDescription crossFaderMixerDescription, crossFaderMixer2Description, masterFaderDescription, outputDescription;

	 

//the AUNodes

	 AUNode crossFaderMixerNode, masterMixerNode, crossFaderMixer2Node;

	 AUNode outputNode;

	 

//the graph

	 OSErr err = noErr;

	 err = NewAUGraph(&graph);

NSAssert(err == noErr, @"Error creating graph.");





	 

	 crossFaderMixer2Description.componentFlags = 0;

	 crossFaderMixer2Description.componentFlagsMask = 0;

	 crossFaderMixer2Description.componentType = kAudioUnitType_Mixer;

	 crossFaderMixer2Description.componentSubType = kAudioUnitSubType_MultiChannelMixer;

	 crossFaderMixer2Description.componentManufacturer = kAudioUnitManufacturer_Apple;

	 err = AUGraphAddNode(graph, &crossFaderMixer2Description, &crossFaderMixer2Node);

NSAssert(err == noErr, @"Error creating mixer node 2.");	 

	 

//the cross fader mixer

	 crossFaderMixerDescription.componentFlags = 0;

	 crossFaderMixerDescription.componentFlagsMask = 0;

	 crossFaderMixerDescription.componentType = kAudioUnitType_Mixer;

	 crossFaderMixerDescription.componentSubType = kAudioUnitSubType_MultiChannelMixer;

	 crossFaderMixerDescription.componentManufacturer = kAudioUnitManufacturer_Apple;

	 err = AUGraphAddNode(graph, &crossFaderMixerDescription, &crossFaderMixerNode);

NSAssert(err == noErr, @"Error creating mixer node.");	 

	 

		  

//the master mixer

	 masterFaderDescription.componentFlags = 0;

	 masterFaderDescription.componentFlagsMask = 0;

	 masterFaderDescription.componentType = kAudioUnitType_Mixer;

	 masterFaderDescription.componentSubType = kAudioUnitSubType_MultiChannelMixer;

	 masterFaderDescription.componentManufacturer = kAudioUnitManufacturer_Apple;

	 err = AUGraphAddNode(graph, &masterFaderDescription, &masterMixerNode);

NSAssert(err == noErr, @"Error creating mixer node.");

	 

//the output

	 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 cross fader

	 err = AUGraphNodeInfo(graph, crossFaderMixerNode, &crossFaderMixerDescription, &crossFaderMixer);

	 

	 err = AUGraphNodeInfo(graph, crossFaderMixer2Node, &crossFaderMixer2Description, &crossFaderMixer2);

//get the master fader

	 err = AUGraphNodeInfo(graph, masterMixerNode, &masterFaderDescription, &masterFaderMixer);

//get the output

	 err = AUGraphNodeInfo(graph, outputNode, &outputDescription, &output);

	 

	 

//the cross fader mixer

AURenderCallbackStruct callbackCrossFader;

	 callbackCrossFader.inputProc = crossFaderMixerCallback;

//set the reference to "self" this becomes *inRefCon in the playback callback

	 callbackCrossFader.inputProcRefCon = self;

	 

//mixer channel 0

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 0, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 0 Cross fader.");

//mixer channel 1

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 1, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 1 Cross fader.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 2, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 2 Cross fader.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 3, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 3 Cross fader.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 4, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 4 Cross fader.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 5, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 5 Cross fader.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 6, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 6 Cross fader.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 7, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 7 Cross fader.");



	 

	 

	 

	 AURenderCallbackStruct callbackCrossFader2;

	 callbackCrossFader2.inputProc = crossFaderMixerCallback2;

//set the reference to "self" this becomes *inRefCon in the playback callback

	 callbackCrossFader2.inputProcRefCon = self;

	 

//mixer channel 0

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixer2Node, 0, &callbackCrossFader2);

NSAssert(err == noErr, @"Error setting render callback 0 Cross fader 2.");

//mixer channel 1

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixer2Node, 1, &callbackCrossFader2);

NSAssert(err == noErr, @"Error setting render callback 1 Cross fader2 .");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixer2Node, 2, &callbackCrossFader2);

NSAssert(err == noErr, @"Error setting render callback 2 Cross fader2.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixer2Node, 3, &callbackCrossFader2);

NSAssert(err == noErr, @"Error setting render callback 3 Cross fader2.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixer2Node, 4, &callbackCrossFader2);

NSAssert(err == noErr, @"Error setting render callback 4 Cross fader2.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixer2Node, 5, &callbackCrossFader2);

NSAssert(err == noErr, @"Error setting render callback 5 Cross fader2.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixer2Node, 6, &callbackCrossFader2);

NSAssert(err == noErr, @"Error setting render callback 6 Cross fader2.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixer2Node, 7, &callbackCrossFader2);

NSAssert(err == noErr, @"Error setting render callback 7 Cross fader2.");

	 

	 

	 AURenderCallbackStruct playbackCallbackStruct;

	 playbackCallbackStruct.inputProc = masterFaderCallback;

//set the reference to "self" this becomes *inRefCon in the playback callback

	 playbackCallbackStruct.inputProcRefCon = self;

	 

	 err = AUGraphSetNodeInputCallback(graph, outputNode, 0, &playbackCallbackStruct);

NSAssert(err == noErr, @"Error setting effects callback.");

			   

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

	 

	 

//set the master fader input properties

	 err = AudioUnitSetProperty(output, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  0, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting RIO input property.");

	 

//set the master fader input properties

	 err = AudioUnitSetProperty(masterFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  0, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting Master fader property.");

	 

//set the master fader input properties

	 err = AudioUnitSetProperty(masterFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Output, 

									  0, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting Master fader property.");	 



	 

//set the crossfader output properties

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Output, 

									  0, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting output property format 0.");

	 

	 

//set the crossfader input properties

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  0, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 0.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  1, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 1.");

	 

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  2, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 2.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  3, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 3.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  4, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 4.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  5, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 5.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  6, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 6.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  7, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 7.");

	 



	 

	 

	 

	 

	 

	 

	 

//set the crossfader output properties

	 err = AudioUnitSetProperty(crossFaderMixer2, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Output, 

									  0, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting output property format 0.");

	 

	 

//set the crossfader input properties

	 err = AudioUnitSetProperty(crossFaderMixer2, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  0, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 0.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer2, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  1, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 1.");

	 

	 

	 err = AudioUnitSetProperty(crossFaderMixer2, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  2, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 2.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer2, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  3, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 3.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer2, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  4, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 4.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer2, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  5, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 5.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer2, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  6, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 6.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer2, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  7, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 7.");

	 

	 

	 





	 

	 err = AUGraphInitialize(graph);

NSAssert(err == noErr, @"Error initializing graph.");

	 

CAShow(graph); 

	 

	 err = AUGraphStart(graph);

NSAssert(err == noErr, @"Error starting graph.");



}


And the callbacks:
static OSStatus crossFaderMixerCallback(void *inRefCon, 

									   AudioUnitRenderActionFlags *ioActionFlags, 

										const AudioTimeStamp *inTimeStamp, 

										UInt32 inBusNumber, 

										UInt32 inNumberFrames, 

										AudioBufferList *ioData) {  

//NSLog(@"%d", inBusNumber);

//get a reference to the djMixer class, we need this as we are outside the class

//in just a straight C method.

	 DJMixer *djMixer = (DJMixer *)inRefCon;

//NSLog(@"%d", inBusNumber);

	 UInt32 *frameBuffer = ioData->mBuffers[0].mData;

	 

	 if (inBusNumber == 0) {

		  for (int j = 0; j < inNumberFrames; j++){

			   frameBuffer[j] = [djMixer.sound1 getNextPacket];

		  }

	 }

	 else if (inBusNumber == 1) {

		  for (int j = 0; j < inNumberFrames; j++){

			   frameBuffer[j] = [djMixer.sound2 getNextPacket];

		  }

	 }

	 else if (inBusNumber == 2) {

		  for (int j = 0; j < inNumberFrames; j++){

			   frameBuffer[j] = [djMixer.sound3 getNextPacket];

		  }

	 }

	 else if (inBusNumber == 3) {

		  for (int j = 0; j < inNumberFrames; j++){

			   frameBuffer[j] = [djMixer.sound4 getNextPacket];

		  }

	 }

	 else if (inBusNumber == 4) {

		  for (int j = 0; j < inNumberFrames; j++){

			   frameBuffer[j] = [djMixer.sound5 getNextPacket];

		  }

	 }

	 else if (inBusNumber == 5) {

		  for (int j = 0; j < inNumberFrames; j++){

			   frameBuffer[j] = [djMixer.sound6 getNextPacket];

		  }

	 }

	 else if (inBusNumber == 6) {

		  for (int j = 0; j < inNumberFrames; j++){

			   frameBuffer[j] = [djMixer.sound7 getNextPacket];

		  }

	 }

	 else if (inBusNumber == 7) {

		  for (int j = 0; j < inNumberFrames; j++){

			   frameBuffer[j] = [djMixer.sound8 getNextPacket];

		  }

	 }

	  

 return0;

}





static OSStatus crossFaderMixerCallback2(void *inRefCon, 

												  AudioUnitRenderActionFlags *ioActionFlags, 

												  const AudioTimeStamp *inTimeStamp, 

												  UInt32 inBusNumber, 

												  UInt32 inNumberFrames, 

												  AudioBufferList *ioData) {  

	 

//NSLog(@"%d", inBusNumber);

//get a reference to the djMixer class, we need this as we are outside the class

//in just a straight C method.

	 DJMixer *djMixer = (DJMixer *)inRefCon;

//NSLog(@"2%d", inBusNumber);

	 UInt32 *frameBuffer = ioData->mBuffers[0].mData;

	 

	 if (inBusNumber == 0) {

		  for (int j = 0; j < inNumberFrames; j++){

			   frameBuffer[j] = [djMixer.sound9 getNextPacket];

		  }

	 }

	 else if (inBusNumber == 1) {

		  for (int j = 0; j < inNumberFrames; j++){

			   frameBuffer[j] = [djMixer.sound10 getNextPacket];

		  }

	 }

	 else if (inBusNumber == 2) {

		  for (int j = 0; j < inNumberFrames; j++){

			   frameBuffer[j] = [djMixer.sound11 getNextPacket];

		  }

	 }

	 else if (inBusNumber == 3) {

		  for (int j = 0; j < inNumberFrames; j++){

			   frameBuffer[j] = [djMixer.sound12 getNextPacket];

		  }

	 }

else {

		  

	 }

 return0;

}





static OSStatus masterFaderCallback(void *inRefCon, 

									   AudioUnitRenderActionFlags *ioActionFlags, 

										const AudioTimeStamp *inTimeStamp, 

										UInt32 inBusNumber, 

										UInt32 inNumberFrames, 

										AudioBufferList *ioData) {  

	 

//get self

	 DJMixer *djMixer = (DJMixer *)inRefCon;

	 OSStatus err = 0;


//get the audio from the crossfader, we could directly connect them but this gives us a chance to get at the audio

//to apply an effect

	 err = AudioUnitRender(djMixer.crossFaderMixer2, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);

	 err = AudioUnitRender(djMixer.crossFaderMixer, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);

		  //apply master effect (if any)

	 return err;

}


This post has been edited by orangeslide8: 29 December 2009 - 08:50 AM


Is This A Good Question/Topic? 0
  • +

Replies To: iPhone Audio Unit more than 8 Channel Mixer

#2 orangeslide8  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 203
  • Joined: 29-December 06

Re: iPhone Audio Unit more than 8 Channel Mixer

Posted 29 December 2009 - 08:52 AM

Sorry Had to do two posts:

But that creates a crackling sound and some high pitch wines. What would be preferable is allow more than 8 channels to one mixer. When I use:
-(void)initAudio{

/*

	  Getting the value of kAudioUnitProperty_ElementCount tells you how many elements you have in a scope. This happens to be 8 for this mixer.

	  If you want to increase it, you need to set this property. 

	  */

// Initialize and configure the audio session, and add an interuption listener

	AudioSessionInitialize(NULL, NULL, rioInterruptionListener, self);

	 

//set the audio category

UInt32 audioCategory = kAudioSessionCategory_LiveAudio;

AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), &audioCategory);

	 

	 

	 UInt32 getAudioCategory = sizeof(audioCategory);

AudioSessionGetProperty(kAudioSessionProperty_AudioCategory, &getAudioCategory, &getAudioCategory);

	 

if(getAudioCategory == kAudioSessionCategory_LiveAudio){

NSLog(@"kAudioSessionCategory_MediaPlayback");

	 }

else{

NSLog(@"Could not get kAudioSessionCategory_MediaPlayback");

	 }

	 

	 

//add a property listener

AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, propListener, self);

	 

//set the buffer size as small as we can

	 Float32 preferredBufferSize = .00125;

AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof(preferredBufferSize), &preferredBufferSize);

	 

//set the audio session active

AudioSessionSetActive(YES);

	 

//the descriptions for the components

	 AudioComponentDescription crossFaderMixerDescription, masterFaderDescription, outputDescription;

	 

//the AUNodes

	 AUNode crossFaderMixerNode, masterMixerNode;

	 AUNode outputNode;

	 

//the graph

	 OSErr err = noErr;

	 err = NewAUGraph(&graph);

NSAssert(err == noErr, @"Error creating graph.");

	 

//the cross fader mixer

	 crossFaderMixerDescription.componentFlags = 0;

	 crossFaderMixerDescription.componentFlagsMask = 0;

	 crossFaderMixerDescription.componentType = kAudioUnitType_Mixer;

	 crossFaderMixerDescription.componentSubType = kAudioUnitSubType_MultiChannelMixer;

	 crossFaderMixerDescription.componentManufacturer = kAudioUnitManufacturer_Apple;

	 err = AUGraphAddNode(graph, &crossFaderMixerDescription, &crossFaderMixerNode);

NSAssert(err == noErr, @"Error creating mixer node.");	 

	 

		  

//the master mixer

	 masterFaderDescription.componentFlags = 0;

	 masterFaderDescription.componentFlagsMask = 0;

	 masterFaderDescription.componentType = kAudioUnitType_Mixer;

	 masterFaderDescription.componentSubType = kAudioUnitSubType_MultiChannelMixer;

	 masterFaderDescription.componentManufacturer = kAudioUnitManufacturer_Apple;

	 err = AUGraphAddNode(graph, &masterFaderDescription, &masterMixerNode);

NSAssert(err == noErr, @"Error creating mixer node.");

	 

//the output

	 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 cross fader

	 err = AUGraphNodeInfo(graph, crossFaderMixerNode, &crossFaderMixerDescription, &crossFaderMixer);

	 

//get the master fader

	 err = AUGraphNodeInfo(graph, masterMixerNode, &masterFaderDescription, &masterFaderMixer);

//get the output

	 err = AUGraphNodeInfo(graph, outputNode, &outputDescription, &output);

	 

	 

//the cross fader mixer

AURenderCallbackStruct callbackCrossFader;

	 callbackCrossFader.inputProc = crossFaderMixerCallback;

//set the reference to "self" this becomes *inRefCon in the playback callback

	 callbackCrossFader.inputProcRefCon = self;

	 

//mixer channel 0

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 0, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 0 Cross fader.");

//mixer channel 1

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 1, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 1 Cross fader.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 2, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 2 Cross fader.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 3, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 3 Cross fader.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 4, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 4 Cross fader.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 5, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 5 Cross fader.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 6, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 6 Cross fader.");

	 

	 err = AUGraphSetNodeInputCallback(graph, crossFaderMixerNode, 7, &callbackCrossFader);

NSAssert(err == noErr, @"Error setting render callback 7 Cross fader.");
		  ///can't add more than this

	 

	 

	 AURenderCallbackStruct playbackCallbackStruct;

	 playbackCallbackStruct.inputProc = masterFaderCallback;

//set the reference to "self" this becomes *inRefCon in the playback callback

	 playbackCallbackStruct.inputProcRefCon = self;

	 

	 err = AUGraphSetNodeInputCallback(graph, outputNode, 0, &playbackCallbackStruct);

NSAssert(err == noErr, @"Error setting effects callback.");

			   

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

	 

	 

//set the master fader input properties

	 err = AudioUnitSetProperty(output, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  0, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting RIO input property.");

	 

//set the master fader input properties

	 err = AudioUnitSetProperty(masterFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  0, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting Master fader property.");

	 

//set the master fader input properties

	 err = AudioUnitSetProperty(masterFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Output, 

									  0, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting Master fader property.");	 



	 

//set the crossfader output properties

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Output, 

									  0, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting output property format 0.");

	 

	 

//set the crossfader input properties

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  0, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 0.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  1, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 1.");

	 

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  2, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 2.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  3, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 3.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  4, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 4.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  5, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 5.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  6, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 6.");

	 

	 err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  7, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 7.");

///when I add any more than this one I get a Sigabrt error then Error setting property format 8

		  err = AudioUnitSetProperty(crossFaderMixer, 

   kAudioUnitProperty_StreamFormat, 

   kAudioUnitScope_Input, 

									  8, 

									  &audioFormat, 

									  sizeof(audioFormat));

NSAssert(err == noErr, @"Error setting property format 8.");


	 

	 





	 

	 err = AUGraphInitialize(graph);

NSAssert(err == noErr, @"Error initializing graph.");

	 

CAShow(graph); 

	 

	 err = AUGraphStart(graph);

NSAssert(err == noErr, @"Error starting graph.");



}


Please help me I looked into kAudioUnitProperty_SupportedNumChannels and I think that is it but I can't figure out how to change it. Basically I either want to change kAudioUnitProperty_SupportedNumChannels or what ever else it is to allow more than 8 channels or want to get the two audio unit mixers working together. Right now which ever one I start second works but makes a very crackly and squeaks and the other one doesn't even play.
Sorry for all the code.

Thnx,
Bryan

This post has been edited by orangeslide8: 29 December 2009 - 08:53 AM

Was This Post Helpful? 0
  • +
  • -

#3 iPhun  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 21
  • Joined: 13-February 10

Re: iPhone Audio Unit more than 8 Channel Mixer

Posted 14 February 2010 - 02:26 AM

Did you figure this out? Is it possible to set the channel count to int channelCount = 8; 0 being the first one and 8 being the 9th channel? It's difficult to read the code posted, but it seems like the logical thing to do.

As for the squeaks and crackles, what frameworks are you importing? I had a similar problem because I didn't import all of the audio frameworks I needed.

Are you getting any error messages? What do your debug logs look like?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1