Default iOSAudioIODevice number of available input channels is weird


#1

On most iOS devices I’m testing on (e.g. iPhone S), if I request 2 input channels, I get 1…
On some later devices (e.g. iPhone X, iPad Air), if I request 2 input channels, I get 2…

If these 2 channels gave me different audio input (e.g. coming from different microphones, or somehow processed to make stereo effects), then I could understand and appreciate the feature. However, it looks as though both channels are giving me exactly identical live audio data.

This is a problem for me, because until I discovered this, I assumed that if I had access to 2 channels of audio, the audio must be coming from an external device with very different data on channels 0 and 1. Furthermore, even with an external device plugged in (via Camera Kit) that is not an iOS device, the audiodevicemanager’s current audio device is still an iOSAudioIODevice with the type name ‘iOS Audio’.

So:

  1. How can I differentiate between the two scenarios: 2 (identical) input channels from an iPhone X versus 2 input channels coming from an external device plugged in with a camera kit? I’m hoping the answer is not to do a sample-by-sample comparison of the data from each channel to see if they are equal or not.

  2. What is the intended purpose of an iPhone giving me access to 2 identical channels of input audio?


#2

I have definitely found a bug of some kind.

If I start up my app with no devices attached, i can look at the channel names and i get:
input : ‘iPhone Microphone’
output : ‘Speaker’

Super.

If I then plug in my device, I get a list of both input and output channel names (more than one for each) that correspond to the device I’ve plugged in.

Super.

However, if I start with the device plugged in, and then start my app, the single input channel name is ‘iPhone Microphone’ and not the (multiple) input channels for my device. However, the output channel list is correct - corresponding to my device’s >1 output channels, and my app is definitely taking audio input from my device and not the mic.

This is true for a couple of different devices I’ve tried plugging in.


#3

Bumping this as its currently a blocker on my project.
Any input/suggestions gratefully received!


#4

I have solved this issue, so I thought I’d report it in case it comes up for anyone else.

I natively queried the portType on the [AVAudioSession sharedInstance].currentRoute

On SOME devices, not all, there is some iOS issue where on app startup, audio input is correctly routed from a connected USB audio device, but the portType is still reported to be the buildItMic or is completely blank. However, querying the output device’s portType correctly reports ‘USBAudio’ for me. This issue does not arise on subsequent audio routing changes… only on app startup.

My solution was, only on app startup, to use the output port type as a proxy if the input port type does not report itself to be USBAudio. Not a perfect solution, but works given the set of devices I’m expecting to interface with.


#5

Thank you for reporting back!

Getting USB device info correct on iOS is painful and full of these kinds of quirks. I’ll have another look at it next week when I have access to a selection of hardware but I suspect that I’ll be unable to do anything better than what you’ve suggested.