The iPhone 5 has 3 mics. Can I change from which o

2019-05-06 16:48发布

The iPhone 5 has 3 microphones, according to its product presentation:

iPhone 5 presentation

After looking through the website of iFixit and others I now know where the bottom microphone is and I've identified the one on the back, right next to the camera.

There should be another one on the front, at the top, but I can't see it, so I assume it's behind the earpiece/receiver opening. (Is this correct?)

I would like to record from two different microphones while the iPhone 5 is lying on it's back. (So the rear mic is out of the question).

My question:

Is there some way I can record from both mics at the same time and separately (i.e. in stereo, like some Windows Phone 8 Lumia phones let you do it)? If not, is there a method that I can use to switch between the microphones, e.g. first record from the one at the bottom of the iPhone, then execute some code to switch to the one at the top?

Your tips will be much appreciated.

2条回答
再贱就再见
2楼-- · 2019-05-06 17:21
// set up the audio session
NSError *error = nil;

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
[audioSession setActive:YES error:&error];

if (error != nil) { NSLog(error); }


// all available inputs
NSArray* inputs = [audioSession availableInputs];

// Locate the port corresponding to the built-in microphone
for (AVAudioSessionPortDescription* port in inputs)
{
    if ([port.portType isEqualToString:AVAudioSessionPortBuiltInMic])
    {
        [self setBuiltInMicPort:port];
        break;
    }
}

// list all microphones
for (AVAudioSessionDataSourceDescription *micType in [audioSession inputDataSources]) {
    NSLog(@"%@ -- %@ -- %@ -- %@", micType.dataSourceID, micType.dataSourceName, micType.location, micType.orientation );

    if ([micType.orientation isEqualToString:@"Front"]) // or @"Back" or @"Bottom"
    {
        [micType setPreferredPolarPattern:AVAudioSessionPolarPatternOmnidirectional error:&error]; // optional
        [self.builtInMicPort setPreferredDataSource:micType error:&error];   
    }
}

This is basic example how to select different built-in microphones in the iPhone. Please keep in mind that the number of microphones differs: iPhone 5 and later has three microphones while previous generations have only two microphones (no back mic).

For more information read Apples Technical Q&A.

查看更多
【Aperson】
3楼-- · 2019-05-06 17:21

I've just verified that Skype switches to the top microphone when using the front camera. Now I only need to verify that I can switch quickly between the top and bottom microphone by starting video capturing from the front camera and then stopping it again.

查看更多
登录 后发表回答