Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stereo recording on iPhone

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.

like image 617
Tony Weber Avatar asked Oct 19 '13 06:10

Tony Weber


1 Answers

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?

like image 159
Alex Whittemore Avatar answered Oct 19 '22 01:10

Alex Whittemore