I'm extending an AudioUnit to generate multi-channel output, and trying to write a unit test using AVAudioEngine. My test installs a tap on the AVAudioNode's output bus and ensures the output is not silence. This works for stereo. I've currently got:
auto avEngine = [[AVAudioEngine alloc] init];
[avEngine attachNode:avAudioUnit];
auto format = [[AVAudioFormat alloc] initStandardFormatWithSampleRate:44100. channels:channelCount];
[avEngine connect:avAudioUnit to:avEngine.mainMixerNode format:format];
where avAudioUnit is my AU.
So it seems I need to do more than simply setting the channel count for the format when connecting, because after this code, [avAudioUnit outputFormatForBus:0].channelCount is still 2.
Printing the graph yields:
AVAudioEngineGraph 0x600001e0a200: initialized = 1, running = 1, number of nodes = 3
******** output chain ********
node 0x600000c09a80 {'auou' 'ahal' 'appl'}, 'I'
inputs = 1
(bus0, en1) <- (bus0) 0x600000c09e00, {'aumx' 'mcmx' 'appl'}, [ 2 ch, 44100 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved]
node 0x600000c09e00 {'aumx' 'mcmx' 'appl'}, 'I'
inputs = 1
(bus0, en1) <- (bus0) 0x600000c14300, {'augn' 'brnz' 'brnz'}, [ 2 ch, 44100 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved]
outputs = 1
(bus0, en1) -> (bus0) 0x600000c09a80, {'auou' 'ahal' 'appl'}, [ 2 ch, 44100 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved]
node 0x600000c14300 {'augn' 'brnz' 'brnz'}, 'I'
outputs = 1
(bus0, en1) -> (bus0) 0x600000c09e00, {'aumx' 'mcmx' 'appl'}, [ 2 ch, 44100 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved]
So AVAudioEngine just silently ignores whatever channel counts I pass to it.
If I do:
auto numHardwareOutputChannels = [avEngine.outputNode outputFormatForBus:0].channelCount;
NSLog(@"hardware output channels %d\n", numHardwareOutputChannels);
I get 30, because I have an audio interface connected. So I would think AVAudioEngine would support this. I've also tried setting the format explicitly on the connection between the mainMixerNode and the outputNode to no avail.