AVAudioEngine Input Node only seeing first device inputs from connected Aggregate Audio Device Swift macOS

Viewed 93

I am trying to process the individual channels of a multichannel Soundcard, using AVAudioEngine.

In order to do that, I first discover the DeviceID of the Soundcard I want to connect to my AVAudioEngine. Then I assign the device to the auAudioUnit of the AVAudioEngine Input Node. Finally, I install a tap on the input node, where I can read the buffer.

I have some code that mostly works, but I have a bug where if I connect an Aggregate Audio Device, my Input Node only sees the input channels of the first audio device within the Aggregate Audio Device.

For example if my Aggregate Audio Device comprises of two sound cards, one with 6 inputs and the second with two inputs, my Input Node AVAudioFormat would see 6 inputs, not 8.

I add the device like so:

try inputNode.auAudioUnit.setDeviceID(deviceID)

Then I get the buffer format like so:

let input = self.inputNode
    let bus = 0
    bufferFormat = input.inputFormat(forBus: bus)

Finally, I install the tap:

input.installTap(onBus: bus, bufferSize: 1024, format: bufferFormat) { [weak self] (buffer, time) in     
      self?.process(buffer: buffer, time: time)
   }

With this method, my Input Node auAudioUnit ends up with two input busses and two output busses, the second input bus format seems to have the correct channel count, but I'm not sure why these channels are not passed to the associated input node.

Any help would be greatly appreciated!

Thanks,

Dan

0 Answers
Related