Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is kAudioSessionProperty_InputSources actually good for?

I've tried to fetch the list of available audio input devices on an iPhone by using this code:

CFArrayRef arrayRef;
UInt32 size = sizeof(arrayRef);
OSStatus status = AudioSessionGetProperty(kAudioSessionProperty_InputSources, &size, &arrayRef);
assert(status == noErr);
NSArray *array = (__bridge NSArray *)arrayRef;

The call works and returns without error, but the results array is always empty, no matter what hardware I have connected to it. I've tried two usual headsets for mobiles, an original one from Apple and one from Samsung and two kinds of USB microphones (an iXY from Rode and an iM2X from Tascam), but the array always stays empty. So I wonder what kinds of input sources would actually be listed by this property? Is it usable at all?

By using a listener callback on the audio routes, I was able to verify that all 4 devices are detected correctly. I was also able to record audio with each of the devices, so they all work properly. I use an iPhone 4S with iOS 6.1.3 (10B329).

like image 289
Daniel S. Avatar asked Jul 25 '13 17:07

Daniel S.


2 Answers

The property you are referring to is only for audio input sources in a USB audio accessory attached through the iPad camera connection kit, as mentioned in the AudioSessionServices class reference.

To get an array that is not nil you will need to test with say a USB Audio Workstation that plugs into the iPad camera connection kit.

Here is a link that lists some hardware that uses the iPad camera connection kit.

Connecting USB audio interfaces using the Apple iPad Camera Connection Kit.

Also from the class reference

If there is no audio input source available from the attached accessory, this property’s value is an empty array.

So from the list found in the above link (scroll down to List of some compatible devices sub heading), devices you would be interested in, that yield a !nil result, would be some device that offers audio input such as the Alesis iO4, iO2, or iO2 express.

EDIT: there's merit in the answer provided by Shawn Hershey, with regards to using a non-deprecated objective-c alternative. However you would be most interested in the portType property of the AVAudioSessionPortDescription class. (available from iOS 6.0) Two constants of interest are - AVAudioSessionPortLineIn and AVAudioSessionPortUSBAudio. The first one mentioned is for audio input through the dock connector, which is the way your test microphones mentioned connect.

In iOS 7.0 and later you can query the availableInputs property of the AVAudioSession class. In iOS 6 you can only query the currentRoute property.

I found this Technical Q&A very helpful - AVAudioSession - microphone selection

like image 69
Bamsworld Avatar answered Sep 20 '22 20:09

Bamsworld


I'm very new to audio programming on iPhones so I don't have an answer to the question of what that particular property is good for, but if you want the list of audio inputs, I think this will work:

NSArray * ais = [[AVAudioSession sharedInstance] availableInputs];

This provides an array of AVAudioSessionPortDescription objects.

for (id object in ais) {
    AVAudioSessionPortDescription * pd = (AVAudioSessionPortDescription*)object;
    NSLog(@"%@",pd.portName);
}
like image 28
Shawn Hershey Avatar answered Sep 18 '22 20:09

Shawn Hershey