The iPhone 5 has three microphones - top front, top back, and bottom. I would like to record on all of them at the same time to do some signal processing. I've tried for several days unsuccessfully.
Using AVAudioSession, I can see the microphones:
NSLog(@"%@", [AVAudioSession sharedInstance].availableInputs);
"<AVAudioSessionPortDescription: 0x14554400, type = MicrophoneBuiltIn; name = iPhone Microphone; UID = Built-In Microphone; selectedDataSource = Back>"
NSLog(@"%@", [AVAudioSession sharedInstance].availableInputs[0].inputDataSources);
"<AVAudioSessionDataSourceDescription: 0x145afb00, ID = 1835216945; name = Bottom>",
"<AVAudioSessionDataSourceDescription: 0x145b1870, ID = 1835216946; name = Front>",
"<AVAudioSessionDataSourceDescription: 0x145b3650, ID = 1835216947; name = Back>"
I can use AVAudioSessionPortDescription -setPreferredDataSource:error:
to record from one of the three. But I cannot record on more than one simultaneously. If I set the number of input channels to 2, I get two identical tracks from the same microphone.
AVAudioRecorder has a property channelAssignments
which seems like it should work, but AVAudioSession inputNumberOfChannels
and maximumInputNumberOfChannels
are both 1. The property channelAssignments
is designed for auxiliary microphones which have multiple channels.
I tried using the low-level AudioUnit, but I get the same result. I could not find any properties on AudioUnit to change the input source.
Any help would be appreciated.
My understanding, after all my research trying to do the same thing, is just what you've described - you can't prefer multiple data sources for the one device, thus you can't record from multiple built-in mics at once. If anyone can prove me wrong, I'd VERY much love to hear it!
Sidenote: I can't seem to run your code. As written, I get
Property availableInputs not found on object of type 'id'
Even after massaging what you've got into a format that doesn't require any explicit casts:
NSLog(@"%@", [[[AVAudioSession sharedInstance] availableInputs][0] inputDataSources]);
I get SIGABRT:
-[AVAudioSessionPortDescription inputDataSources]: unrecognized selector sent to instance 0xd59dbe0'
what SDK are you using that your code actually compiles, much less runs?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With