Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How avoid automatic gain control with AudioRecord?

How can I do audio recordings using android.media.AudioRecord without any smartphone-manufacturer-dependent fancy signal processing like automatic gain control (AGC) and/or equalization, noise suppression, echo cancellation, ... just the pure microphone signal?

Background

MediaRecorder.AudioSource provides nine constants,

  • DEFAULT and MIC initially being there,
  • VOICE_UPLINK, VOICE_DOWNLINK, and VOICE_CALL added in API level 4,
  • CAMCORDER and VOICE_RECOGNITION added in API 7,
  • VOICE_COMMUNICATION added in API 11,
  • REMOTE_SUBMIX added in API 19 but not available to third-party applications.

But none of them does a clean job across all smartphones. Rather, I have to find out myself it seems, which device uses which combinations of signal processing blocks for which MediaRecorder.AudioSource constant.

Would be nice to have a tenth constant like PURE_MIC added in API level 20.

But as long as this is not available, what can I do instead?

like image 314
Hartmut Pfitzinger Avatar asked Jan 17 '13 10:01

Hartmut Pfitzinger


People also ask

How do I turn off auto gain control?

Right-click on 'Microphone' and select the 'Properties' option. In the new 'Microphone Properties' window that pops up, move to 'Advanced' tab and uncheck the option marked against 'Allow applications to take exclusive control of this device'.

What is a disadvantage of AGC?

The most important advantage of AGC is that it is very fast to apply and does not require complicated processing parameters to be selected accurately. However, it also has a very substantial disadvantage: it completely removes relative amplitude information embedded in the seismic data.

What is use of AGC in MI TV?

Automatic Gain Control (AGC) is an audio pre-processor which automatically normalizes the output of the captured signal by boosting or lowering input from the microphone to match a preset level so that the output signal level is virtually constant.

What is automatic gain control in radar?

Automatic Gain Control (AGC) AGC is a technique which controls receiver gain automatically as and when the radar return signal changes in amplitude. The simplest type of AGC adjusts the receiver gain according to the average level of the received signal.


3 Answers

Short answer is "Nothing".

The AudioSources correspond to various logical audio input devices depending on the accessories that you have connected to the phone and the current use-case, which in turn corresponds to physical devices (primary built-in mic, secondary mic, wired headset mic, etc) with different tunings.

Each such combination of physical device and tuning is trimmed by the OEM to meet both external requirements (e.g. CTS, operator requirements, etc) and internal acoustic requirements set by the OEM itself. This process may cause the introduction of various filters - such as AGC, noise suppression, equalization, etc - into the audio input path at the hardware codec or multimedia DSP level.

While a PURE_MIC source might be useful in for some applications, it's not something that's available today.
On many devices you can control things like microphone gain, and possibly even the filter chain, by using amixer to write to the hardware codec's ALSA controls. However, this would obviously be a very platform-specific approach, and I also suspect that you have to be running as either the root or audio user to be allowed to do this.

like image 170
Michael Avatar answered Sep 27 '22 19:09

Michael


Some devices add AGC effect to the sound input tract by default. Therefore, you need to obtain reference to corresponding AudioEffect object and force it to disable.

First, obtain AutomaticGainControl object linked to the AudioRecord audio session, and then just set it disabled:

if (AutomaticGainControl.isAvailable()) {
    AutomaticGainControl agc = AutomaticGainControl.create(
            myAudioRecord.getAudioSessionId()
        );
    agc.setEnabled(false);
}
like image 21
AterLux Avatar answered Sep 27 '22 17:09

AterLux


Note: Most of the audio sources (including DEFAULT) apply processing to the audio signal. To record raw audio select UNPROCESSED. Some devices do not support unprocessed input. Call AudioManager.getProperty("PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED") first to verify it's available. If it is not, try using VOICE_RECOGNITION instead, which does not employ AGC or noise suppression. You can use UNPROCESSED as an audio source even when the property is not supported, but there is no guarantee whether the signal will be unprocessed or not in that case.

Android documentation Link https://developer.android.com/guide/topics/media/mediarecorder.html#example

    AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    if(audioManager.getProperty(AudioManager.PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED) !=null)
        mRecorder.setAudioSource(MediaRecorder.AudioSource.UNPROCESSED);
    else
        mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_RECOGNITION);
like image 30
Arun Shankar Avatar answered Sep 27 '22 17:09

Arun Shankar