[Nexus 5 Android Development] chdloc:
On Automatic Gain Control (AGC)

Some folks have noted that the Nexus 5 is unable to produce acceptable recordings in very loud environments, such as concerts.

Compared to telephony/communication applications, there is significant additional gain applied to the microphone in camcorder mode to boost the microphone's "sensitivity" to distant acoustic sources.

The idea of implementing automatic gain control (AGC) was brought up to be able to automatically adjust the microphone gain depending on the challenges of the acoustic environment.

AOSP ships with two instances of AGC, one made by Qualcomm and the other one being part of webRTC. I played around with both.

The Qualcomm one (which is completely disabled in AOSP by default) does not seem to be doing anything. It is likely that the audio HAL (or the proprietary vendor blob) does not offer the actual implementation or required control. The AGC offered by webRTC does do work.

However, gains fluctuate wildly all over the place and there is a lot of "level pumping" going on. It is possible that tuning may address this issue to some extend, but it is important to note that this particular algorithm has been designed for speech signals in telephony applications. I'm reluctant to release anything that will likely do more harm than good in the context of camcorder recordings.

---

The following applies only to recordings made in environments where the SPL is low enough to be "tolerated" by the analog front-end. Without knowing what microphones are being used, I cannot guess what "low enough" would be.

Not all hope is lost. As stated in previous posts, the microphone gain (ADC1 & DEC6 for the main microphone and ADC3 & DEC4 for the secondary micophone) can be adjusted by either the Aroma installer (which edits the mixer_paths.xml file) or even on-the-fly by using a command-line tool called "tinymix", which ships with AOSP but is not installed by default. The problem with the Aroma installer or even a manual edit of mixer_paths.xml is that the phone needs to be rebooted every time a change is made to the mixer gains. The on-the-fly adjustment has the problem that it needs to be done every time the "record" button is pressed as the camcorder app always applies the default levels in mixer_paths.xml as soon as a new recording is started.

I've been using a somewhat useful workaround by showing on-screen volume controls with Tasker which in turn invoke tinymix. It works actually quite well, but it is very difficult to know what gain settings are useful, especially in very loud environments.

What we need is an audio recording app that displays a VU meter representing the SPL of the sampled sound field along with ADC1/DEC6 and ADC3/DEC4 mixer controls. With the help of the mixer controls one can lower the mixer gains until the VU meter stays "in the green". The resulting values could then be applied by on-screen gain controls during the actual recording. Unfortunately, only one app can access the microphone at a given time, so these two apps cannot run concurrently. (An ideal solution would be a custom camera app that shows a live

audio VU meter during a recording along with the required mixer gain controls).

Are there any seasoned Android developers out there that would be interested in implementing this?