What is kAudioSessionProperty_InputSources, is this really good?

I tried to get a list of available audio input devices on iPhone 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 errors, but the array of results is always empty, regardless of what equipment I connected to it. I tried two ordinary headsets for mobile phones, the original one from Apple and one from Samsung and two types of USB microphones ( iXY from Rode and iM2X from Tascam ), but the array always remains empty. So I wonder, what source data sources will really be listed by this property? Can it even be used?

Using the listener callback on the audio tracks, I was able to verify that all 4 devices were detected correctly. I could also record audio from each of the devices, so they all work fine. I am using iPhone 4S with iOS 6.1.3 (10B329).

+6
source share
2 answers

I am very new to the audio program on iPhone, so I have no answer to the question of what this particular property is suitable for, but if you need a list of audio inputs, I think it 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); } 
+2
source

The property you are talking about applies only to the audio input sources in the USB audio device attached via the iPad> connection kit, as indicated in the link of the AudioSessionServices class.

To get an array that is not null, you will need to test, say, USB Audio Workstation, which connects to the iPad camera kit.

Here is a link listing some of the hardware that uses the iPad Camera Connection Kit.

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

Also from class reference

If there is no audio source available from the supplied accessory, this property value is an empty array.

So, from the list found in the link above (scroll down to the list of some subtitles of compatible devices), the devices that are of interest to you will produce the result! nil, will be some device that offers audio input, such as Alesis iO4 , iO2 or iO2 express .

EDIT: There is merit in the answer provided by Sean Hershey regarding the use of the obsolete alternative to objective-c. However, you are 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 is mentioned for audio input through the dock connector that connects your test microphones.

In iOS 7.0 and later, you can request the property of an available entry of the AVAudioSession class. In iOS 6, you can only request the currentRoute property.

I found this Technical Q & Very Helpful - AVAudioSession - Microphone Selection

+2
source

Source: https://habr.com/ru/post/950290/


All Articles