Adjusting input volume using AVFoundation (in AVCaptureSession)

I searched everywhere and I cannot find a way to configure the input volume of the input device for AVCaptureSession. The best I can do, which doesn't help me at all, is to get the sound levels from the device by accessing the connections (AVCaptureConnections) from AVCaptureAudioDataOutput, that is, by controlling the levels from the preview output. Is there a way to change the input gain or even get the input level of the audio signal directly in AVFoundation? I'm still a little learning, so I apologize if I missed something obvious.

Edit: I have to point out that this is for OSX.

+4
source share
3 answers

So, I used some information that it was connected, as well as some research in Core Audio, and I turned it into a github project. Thus, other people who want to change the input volume of the device when using AVFoundation do not need to reinvent the wheel. You can find the classes here: https://github.com/ewrobinson/ERVolumeAdjust

+1
source
self.audioSession = [AVAudioSession sharedInstance]; if (self.audioSession.isInputGainSettable) { BOOL success = [self.audioSession setInputGain:sender.value error:&error]; if (!success) NSLog(@"inputGain error: %@",error); } 

This is for ios6 + ... for ios5, you can use the AudioSessionGetProperty / AudioSessionSetProperty functions to achieve the same.

However, not all hardware is capable of adjusting input gain. For example, I get a win installed on an iPhone 3GS / ios6 with a built-in microphone, but the gain is NOT installed on an iPad mini with a built-in microphone. On the iPhone 3GS, the gain is also not set until recording has begun. (edit: iPhone 4S / ios5 also has the ability to configure with a built-in microphone)

Update
As you pointed out, you are looking for an OSX solution, not iOS. I moved this answer (in more detail) to a more convenient place .

For OSX, you can find this Q & useful:

How to set the input level (gain) to the built-in input (OSX Core Audio / Audio Unit)?

+1
source

You can adjust the gain by setting the volume property for your audio output for the session.
Note that a connection can have multiple channels.

I am assuming a link to fileOutput ivar here, which I saved, before adding output to the session.

 AVCaptureConnection* audioConnection = [fileOutput connectionWithMediaType:AVMediaTypeAudio]; if(audioConnection) { for(AVCaptureAudioChannel* audioChannel in [audioConnection audioChannels]) { audioChannel.volume = 0.5; } } 
+1
source

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


All Articles