Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android microphone sensitivity change after phone call

My application is measuring volume of captured audio as a function of samples absolute amplitude.

I've noticed and unexpected behavior in android.media.AudioRecord of Android SDK. Let's assume following flow:

  1. Application is launched
  2. Audio volume is being measured
  3. Phone call is answered/dialed
  4. Audio volume is being measured

The noise around the microphone is produced by TV with constant volume setting. Values measured for point 2 are in range [55-65] and values measured for point 4 are in range [15-25] (please see the audio visualization for 2. and 4. below).

I understand that there must be some volume adjustment going on when phone call occurs. Is it possible to monitor those adjustments or to get rid of them?

I've tried AutomaticGainControl but it is not supported on my Nexus 5 and I do not want to use it since the target devices might not support it as well.

Update This volume adjustment is happening not only after phone call. I've just noticed the same behavior when phone was just lying on the table measuring volume.

PCM audio before and after the phone call

like image 581
Maciej Donajski Avatar asked Oct 30 '22 11:10

Maciej Donajski


1 Answers

In regard to resources that your app is sharing with other apps (the microphone in this matter) - you should always treat them carefully and assume there configuration may change during a phone call or other usage like switching to another app that's using the microphone.

Instead of trying to monitor for changes in gain , which may require root or other elevated privileges - I would take another approach and do the following:

  1. Save the mic sensitivity level to a configuration file (shared_prefs) in your recording activity when the user is recording . do the same if the user changes it of course during usage of your app.
  2. In the onResume proc of your recording activity - load the mic sensitivity level value and set it before continuing to record (How to adjust microphone sensitivity while recording audio in android - Solved)

If there is a phone call that throws your app to the background and takes control of the mic, once it's finished - your app will return to the foreground and retain the mic sensitivity level for further recording.

Hope this helps.

like image 131
FunkSoulBrother Avatar answered Nov 11 '22 12:11

FunkSoulBrother