AVAudioEngine : Split 1x4 channel bus into 4x1 channel busses?

I'm using a 4 channel USB Audio interface, with 4 microphones, and want to process them through 4 independent effect chains. However the output from AVAudioInputNode is a single 4 channel bus. How can I split this into 4 mono busses?

The following code splits the input into 4 copies, and routes them through the effects, but each bus contains all four channels. How can I remap the channels to remove the unwanted channels from the bus? I tried using channelMap on the mixer node but that had no effect.

I'm currently using this code primarily on iOS but it should be portable between iOS and MacOS. It would be possible to do this through a Matrix Mixer Node, but that seems completely overkill, for such a basic operation. I'm already using a Matrix Mixer to combine the inputs, and it's not well supported in AVAudioEngine.

AVAudioInputNode *inputNode=[engine inputNode];
[inputNode setVoiceProcessingEnabled:NO error:nil];

NSMutableArray *micDestinations=[NSMutableArray arrayWithCapacity:trackCount];
for(i=0;i<trackCount;i++)
{

    fixMicFormat[i]=[AVAudioMixerNode new];
    [engine attachNode:fixMicFormat[i]];
   // And create reverb/compressor and eq the same way...
    
    [engine connect:reverb[i] to:matrixMixerNode fromBus:0 toBus:i format:nil];
    [engine connect:eq[i] to:reverb[i] fromBus:0 toBus:0 format:nil];
    [engine connect:compressor[i] to:eq[i] fromBus:0 toBus:0 format:nil];
    [engine connect:fixMicFormat[i] to:compressor[i] fromBus:0 toBus:0 format:nil];
    [micDestinations addObject:[[AVAudioConnectionPoint alloc] initWithNode:fixMicFormat[i] bus:0] ];
}
AVAudioFormat *inputFormat = [inputNode outputFormatForBus: 1];
[engine connect:inputNode toConnectionPoints:micDestinations fromBus:1 format:inputFormat];

Still frustrated with this one. I now realise a matrix mixer won't help as while that can shuffle the outputs they still would output on a single bus.

I'm now wondering if the only option is to write an audio unit? Surely there's a way to do this with existing nodes? It's a required function of every DAW to be able to run each mic through a seperate channel strip.

Any hints?

I think a matrix mixer should be able to do this. Here is an old post on the topic.

For your case I think you'd need to first set up the elements and formats:

  1. Set the number of input elements to 1
  2. Set the format for the single input element to 4 channels
  3. Set the number of output elements to 4
  4. Set the format on output elements 0-3 to mono

Then set the gains:

  1. Set the master gain to 1.0
  2. Set the input gain for each input channel on the input element to 1.0
  3. Set the output gain for each output channel to 1.0
  4. Set the crosspoint gains to 1.0 on the following elements: ((0 << 16) | 0), ((1 << 16) | 1) , ((2 << 16) | 2) ,((3 << 16) | 3)

In the end I think you'd end up with the following non-zero values in the 5x5 array of matrix levels (kAudioUnitProperty_MatrixLevels):

// Crosspoint gains
[0][0] = 1.0
[1][1] = 1.0
[2][2] = 1.0
[3][3] = 1.0
// Input gains
[0][4] = 1.0
[1][4] = 1.0
[2][4] = 1.0
[3][4] = 1.0
// Output gains
[4][0] = 1.0
[4][1] = 1.0
[4][2] = 1.0
[4][3] = 1.0
// Global gain
[4][4] = 1.0

It's been a few years since I've looked at this, but hopefully this might help.

AVAudioEngine : Split 1x4 channel bus into 4x1 channel busses?
 
 
Q