Android microphone sensitivity change after a phone call

My application measures the volume of captured sound depending on the absolute amplitude of the sample.

I noticed unexpected behavior in the android.media.AudioRecord Android SDK. Let the following flow be assumed:

  • Application starts
  • Sound volume is measured
  • Answer a phone call / dialed phone
  • Sound volume is measured

The noise around the microphone is made by a television with constant volume control. The values โ€‹โ€‹measured for point 2 are in the range [55โ€“65], and the values โ€‹โ€‹measured for point 4 are in the range [15โ€“25] (see Sound visualization for 2. and 4. below).

I understand that when you make a phone call, there is some volume control. Can these adjustments be controlled or eliminated?

I tried AutomaticGainControl, but it is not supported on my Nexus 5, and I do not want to use it, since the target devices may also not support it.

Update This volume control does not only happen after a telephone conversation. I just noticed the same behavior when the phone just lay on the table, measuring the volume.

PCM sound before and after a phone call

+5
source share
1 answer

As for the resources that your application shares with other applications (the microphone in this matter) - you should always be careful about them and assume that the configuration may change during a phone call or other use, for example, switching to another application that uses the microphone.

Instead of trying to track changes in the gain, which may require root privileges or other elevated privileges, I would take a different approach and do the following:

  • Save the microphone sensitivity level in the configuration file (shared_prefs) in your recording activity when the user records. do the same if the user changes it, of course, while using your application.
  • In onResume proc of your recording activity - load the value of the microphone sensitivity level and set it before continuing recording ( How to adjust the microphone sensitivity while recording sound in android - Baxin )

If there is a phone call that throws your application into the background and controls the microphone as soon as it is finished, your application will return to the foreground and save the microphone sensitivity level for further recording.

Hope this helps.

+1
source

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


All Articles