I was wondering is there's a way to capture stereo audio using an AVCaptureSession. iOS 14 adds support for stereo audio for AVAudioRecorder, but so far I have been unsuccessful is capturing stereo audio through an AVCaptureSession.
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];
[audioSession setActive:YES error:NULL];
NSArray *portDescriptions = audioSession.availableInputs;
AVAudioSessionPortDescription *builtInMicPort = nil;
for (AVAudioSessionPortDescription *port in portDescriptions) {
if ([port.portType isEqualToString:AVAudioSessionPortBuiltInMic]) {
builtInMicPort = port;
break;
}
} // end input iteration
[audioSession setPreferredInput:builtInMicPort error:nil];
NSArray *supportedPolarPatterns = audioSession.preferredInput.dataSources.firstObject.supportedPolarPatterns;
[audioSession.preferredInput.dataSources.firstObject setPreferredPolarPattern:AVAudioSessionPolarPatternStereo error:nil];
[audioSession.preferredInput setPreferredDataSource:audioSession.preferredInput.dataSources.firstObject error:nil];
[audioSession setPreferredInputOrientation:AVAudioStereoOrientationPortrait error:nil];
device = [AVCaptureDevice defaultDeviceWithDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionBack];
deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
if([videoSession canAddInput:deviceInput]){
[videoSession addInput:deviceInput];
}
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput *audioDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error];
if([videoSession canAddInput:audioDeviceInput]){
[videoSession addInput:audioDeviceInput];
}
Try this:
videoSession.usesApplicationAudioSession = true
videoSession.automaticallyConfiguresApplicationAudioSession = false
I was able to get stereo working in iOS 14 with this added.