Stereo Recording on iPhone

The iPhone 5 has three microphones: top, top and bottom. I would like to record everything on them at the same time to do some signal processing. I tried several days unsuccessfully.

Using AVAudioSession, I see 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 three. But I can’t record more than one at a time. If I set the number of input channels to 2, I get two identical tracks from the same microphone.

AVAudioRecorder has a channelAssignments property that seems to work, but AVAudioSession inputNumberOfChannels and maximumInputNumberOfChannels are 1. The channelAssignments property is for auxiliary microphones that have multiple channels.

I tried to use low-level AudioUnit, but I get the same result. I could not find any properties in AudioUnit to change the input source.

Any help would be appreciated.

+6
source share
1 answer

My understanding, because all my research trying to do the same thing is what you described - you cannot prefer multiple data sources for one device, so you cannot record data from several built-in microphones once. If someone can prove that I'm wrong, I really enjoyed hearing it!

Sidenote: I cannot run your code. As written, I get

 Property availableInputs not found on object of type 'id' 

Even after massaging what you have in a format that does not require any explicit tricks:

 NSLog(@"%@", [[[AVAudioSession sharedInstance] availableInputs][0] inputDataSources]); 

I get SIGABRT:

 -[AVAudioSessionPortDescription inputDataSources]: unrecognized selector sent to instance 0xd59dbe0' 

which SDK are you using, what is your code really compiling, much less working?

+4
source

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


All Articles