[MOD] [ROOT] Camcorder Audio Quality Fix with Stereo Recording and Playback Support

Search This thread

dr_iggy

Senior Member
Nov 5, 2011
352
91
Belgrade
Alternatively, simply run
Code:
adb logcat
or
Code:
adb shell logcat
as you did before and copy-and-paste the output in its entirety.

Edit: Please also paste the complete output of the following commands
Code:
adb shell ls -alZ /system/lib/hw
Code:
adb shell ls -alZ /system/etc

Ok, here it is.

For adb shell ls -alZ /system/lib/hw:
Code:
-rw-r--r-- root     root              u:object_r:system_file:s0 audio.a2dp.default.so
-rw-r--r-- root     root              u:object_r:system_file:s0 audio.primary.default.so
-rw-r--r-- root     root              u:object_r:system_file:s0 audio.primary.msm8974.so
-rw-r--r-- root     root              u:object_r:system_file:s0 audio.r_submix.default.so
-rw-r--r-- root     root              u:object_r:system_file:s0 audio.usb.default.so
-rw-r--r-- root     root              u:object_r:system_file:s0 audio_policy.default.so
-rw-r--r-- root     root              u:object_r:system_file:s0 bluetooth.default.so
-rw-r--r-- root     root              u:object_r:system_file:s0 camera.hammerhead.so
-rw-r--r-- root     root              u:object_r:system_file:s0 flp.msm8974.so
-rw-r--r-- root     root              u:object_r:system_file:s0 gatekeeper.default.so
-rw-r--r-- root     root              u:object_r:system_file:s0 gps.msm8974.so
-rw-r--r-- root     root              u:object_r:system_file:s0 gralloc.default.so
-rw-r--r-- root     root              u:object_r:system_file:s0 gralloc.msm8974.so
-rw-r--r-- root     root              u:object_r:system_file:s0 hwcomposer.msm8974.so
-rw-r--r-- root     root              u:object_r:system_file:s0 keystore.default.so
-rw-r--r-- root     root              u:object_r:system_file:s0 keystore.msm8974.so
-rw-r--r-- root     root              u:object_r:system_file:s0 lights.hammerhead.so
-rw-r--r-- root     root              u:object_r:system_file:s0 local_time.default.so
-rw-r--r-- root     root              u:object_r:system_file:s0 memtrack.msm8974.so
-rw-r--r-- root     root              u:object_r:system_file:s0 nfc_nci.bcm2079x.default.so
-rw-r--r-- root     root              u:object_r:system_file:s0 power.default.so
-rw-r--r-- root     root              u:object_r:system_file:s0 power.hammerhead.so
-rw-r--r-- root     root              u:object_r:system_file:s0 power.msm8974.so-bak
-rw-r--r-- root     root              u:object_r:system_file:s0 vibrator.default.so

And for adb shell ls -alZ /system/etc:
Code:
-rw-r--r-- root     root              u:object_r:system_file:s0 .installed_su_daemon
-rw-r--r-- root     root              u:object_r:system_file:s0 DxHDCP.cfg
-rw-r--r-- root     root              u:object_r:system_file:s0 NOTICE.html.gz
drwxr-xr-x root     root              u:object_r:system_file:s0 acdbdata
-rw-r--r-- root     root              u:object_r:system_file:s0 apns-conf.xml
-rw-r--r-- root     root              u:object_r:system_file:s0 audio_effects.conf
-rw-r--r-- root     root              u:object_r:system_file:s0 audio_policy.conf
drwxr-xr-x root     root              u:object_r:system_file:s0 bluetooth
-rw-r--r-- root     root              u:object_r:system_file:s0 clatd.conf
drwxr-xr-x root     root              u:object_r:system_file:s0 dhcpcd
-rw-r--r-- root     root              u:object_r:system_file:s0 event-log-tags
-rw-r--r-- root     root              u:object_r:system_file:s0 fallback_fonts.xml
drwxr-xr-x root     root              u:object_r:system_file:s0 firmware
-rw-r--r-- root     root              u:object_r:system_file:s0 flp.conf
-rw-r--r-- root     root              u:object_r:system_file:s0 fonts.xml
-rw-r--r-- root     root              u:object_r:system_file:s0 gps.conf
-rw-r--r-- root     root              u:object_r:system_file:s0 hosts
drwxr-xr-x root     root              u:object_r:system_file:s0 init.d
-rwxr-xr-x root     root              u:object_r:system_file:s0 install-recovery.sh
-rw-r--r-- root     root              u:object_r:system_file:s0 libnfc-brcm-20791b05.conf
-rw-r--r-- root     root              u:object_r:system_file:s0 libnfc-brcm.conf
-rw-r--r-- root     root              u:object_r:system_file:s0 media_codecs.xml
-rw-r--r-- root     root              u:object_r:system_file:s0 media_codecs_google_audio.xml
-rw-r--r-- root     root              u:object_r:system_file:s0 media_codecs_google_telephony.xml
-rw-r--r-- root     root              u:object_r:system_file:s0 media_codecs_google_video.xml
-rw-r--r-- root     root              u:object_r:system_file:s0 media_profiles.xml
-rw-r--r-- root     root              u:object_r:system_file:s0 mixer_paths.xml
-rw-r--r-- root     root              u:object_r:system_file:s0 mkshrc
drwxr-xr-x root     root              u:object_r:system_file:s0 permissions
drwxr-xr-x root     root              u:object_r:system_file:s0 ppp
drwxr-xr-x root     root              u:object_r:system_file:s0 preferred-apps
-rw-r--r-- root     root              u:object_r:system_file:s0 preloaded-classes
-rw-r--r-- root     root              u:object_r:system_file:s0 qcril.db
-rw-r--r-- root     root              u:object_r:system_file:s0 recovery-resource.dat
-rw-r--r-- root     root              u:object_r:system_file:s0 resolv.conf
-rw-r--r-- root     root              u:object_r:system_file:s0 sec_config
drwxr-xr-x root     root              u:object_r:system_file:s0 security
-rw-r--r-- root     root              u:object_r:system_file:s0 sensor_def_hh.conf
-rw-r--r-- root     root              u:object_r:system_file:s0 spn-conf.xml
drwxr-xr-x root     root              u:object_r:system_file:s0 sysconfig
-rw-r--r-- root     root              u:object_r:system_file:s0 system_fonts.xml
-rw-r--r-- root     root              u:object_r:system_file:s0 thermal-engine-8974.conf
drwxr-xr-x root     root              u:object_r:system_file:s0 updatecmds
drwxr-xr-x root     root              u:object_r:system_file:s0 wifi
 

Attachments

  • log.txt
    210.7 KB · Views: 6
Last edited:
  • Like
Reactions: chdloc

chdloc

Senior Member
Jul 19, 2010
1,140
1,724
Ok, here it is.

For adb shell ls -alZ /system/lib/hw:
<snip>
And for adb shell ls -alZ /system/etc:

Did you run these commands while your phone was "boot looping"?
If so, I'm running out of ideas. The only interesting line in your logcat refers to a dead media server. There is no indication as to why it may have died.
I wonder whether the simple mod (the one without noise suppression) would allow M Preview to boot. I'm starting to think that the published sources don't line up with the factory image...


Edit: did you see errors in the recovery when trying to install the mod? (the logs can be found in /cache/recovery/last_log)
 
Last edited:

KimSeiji

Member
May 3, 2012
6
0
São Paulo
This is the aroma installer of chdloc's audio fix for Android 5.1 stock rom. Other installers of the fix are available for 5.0.1 stock rom (see post #235) and 4.4.4 AOSP-based roms (see post #3).
I will keep this post updated if there will be a new version of the installer.

2015-03-13: Updated installer (v1.1) for Android 5.1 stock rom, including fix for "no TX audio bug" when on speakerphone (see post #645)

The installer has the following features:
  • Camcorder Audio Fix. You can select the level of noise suppression, microphone gain, mono or stereo recording and audio bitrate. Optionally the stereo playback mod and the sidetone config can be installed. You can choose the phone's orientation for stereo playback (micro-usb port to the right or to the left), the gain levels for ear speaker and bottom speaker, the sidetone level for headset and handset use cases. When installing the "advanced" audio fix (6dB or 12dB noise suppression), you can optionally install the prerequisites (tinymix binary and scripts) for chdloc's aMGC implementation. To actually use aMGC you will also have to install the aMGC apk or the Tasker project provided by chdloc.
  • Install stock audio libs+config. Optionally the stereo playback mod and the sidetone config can be installed. You can choose the phone's orientation for stereo playback (micro-usb port to the right or to the left), the gain levels for ear speaker and bottom speaker, the sidetone level for headset and handset use cases. The aMGC prerequisites (tinymix binary and scripts) will be deleted.

Please make a backup of the system partition by using the recovery (e.g. TWRP) prior to installing this zip, so you can just restore the system partition if you don't like the changes. And there's always a (small) risk that something goes wrong when flashing a zip. Anything you do, you are doing at your own risk. :fingers-crossed:

The installer will overwrite the following files:
  • /system/etc/media_profiles.xml
  • /system/etc/mixer_paths.xml
  • /system/lib/hw/audio.primary.msm8974.so
  • /system/lib/libaudioflinger.so
  • /system/lib/soundfx/libaudiopreprocessing.so
  • /system/vendor/etc/audio_effects.conf
Additionally the following file and directory may be installed or deleted:
  • /system/bin/tinymix
  • /data/local/tmp/camera/ (containing some scripts)

Please do not forget to post your experiences with this fix! Happy flashing! :)

Hello,
Does it work on 5.1.1 LMY48B??

Thanks!
 

mpiwosal

Senior Member
Feb 20, 2013
65
10
it influences my microphone volume in calls somehow. the other person can't hear me almost at all. does anyone have the same problem? i'm on cataclysm 5.1.1, installed 6db + aMGC and it is a perfection aside from calling :(
 

chdloc

Senior Member
Jul 19, 2010
1,140
1,724
it influences my microphone volume in calls somehow. the other person can't hear me almost at all. does anyone have the same problem? i'm on cataclysm 5.1.1, installed 6db + aMGC and it is a perfection aside from calling :(

Can you confirm that in-call microphone volume is consistently higher when you remove the mod?
The only instance where my mod is modifying in-call audio in any way is when the sidetone option is installed. Even then, though, the microphone level is not modified.

By default, an adaptive dual-microphone noise suppression scheme is used (by pretty much any modern smartphone) while using the handset in a call. Both microphones need to be working properly. Here are some trouble shooting tips:
  • Have you by any chance installed a new case that may block one of the microphones?
  • Do you happen to cover one of the microphones with your finger when holding the phone to your ear?
  • does the microphone seem to work properly when using (any) sound recording app (most use the main/bottom microphone)?
  • does the microphone seem to work properly when switching to speakerphone during a call (uses the top/auxiliary microphone)?
  • do you have any other sound mod installed?

If you'd like you can post (or PM) the contents of your /system/etc/mixer_paths.xml file and I'll take a look
 

mpiwosal

Senior Member
Feb 20, 2013
65
10
Can you confirm that in-call microphone volume is consistently higher when you remove the mod?
The only instance where my mod is modifying in-call audio in any way is when the sidetone option is installed. Even then, though, the microphone level is not modified.

By default, an adaptive dual-microphone noise suppression scheme is used (by pretty much any modern smartphone) while using the handset in a call. Both microphones need to be working properly. Here are some trouble shooting tips:
  • Have you by any chance installed a new case that may block one of the microphones?
  • Do you happen to cover one of the microphones with your finger when holding the phone to your ear?
  • does the microphone seem to work properly when using (any) sound recording app (most use the main/bottom microphone)?
  • does the microphone seem to work properly when switching to speakerphone during a call (uses the top/auxiliary microphone)?
  • do you have any other sound mod installed?

If you'd like you can post (or PM) the contents of your /system/etc/mixer_paths.xml file and I'll take a look

*no case at all
*no way I cover my mic with anything
*when using camera everything is okay, you know the situation during calls, and i THINK that when recording something in any app it's reasonably quiter than it should (and used to) be
*when on speaker everythings seems to be fine (just checked)
*stable cataclysm, your mode is the only one on my phone

I'll PM you with my mixer_paths.xml in a moment, it's a bit too much to post here.

One more question: during the recording (google camera) aMGC acts a bit strange. i know it takes time after the click to change the value on screen but it seems to change by itself. ex. I had -47db for a moment and after a second it changed to +6db with no interaction on my side. maybe I don't understand it, but isn't it supposed to represent the value that i choose?
 

chdloc

Senior Member
Jul 19, 2010
1,140
1,724
One more question: during the recording (google camera) aMGC acts a bit strange. i know it takes time after the click to change the value on screen but it seems to change by itself. ex. I had -47db for a moment and after a second it changed to +6db with no interaction on my side. maybe I don't understand it, but isn't it supposed to represent the value that i choose?

This is actually the intended behavior. The number that is constantly changing is the instantaneously measured RMS level of the recorded sound. After you change the gain it flashes the current gain differential with respect to the stock setting. For example you start the camcorder app, wait for aMGC to become active and tap the downward arrow, it should quickly flash -6 dB (as each short tap changes the gain by 6 dB) and then go back to updating the current level. If you tap the same arrow again it should quickly flash -12 dB, and so on.
Not well documented, I have to admit...
 
Last edited:
  • Like
Reactions: jeffreywedwards

mpiwosal

Senior Member
Feb 20, 2013
65
10
This is actually the intended behavior. The number that is constantly changing is the instantaneously measured RMS level of the recorded sound. After you change the gain it flashes the current gain differential with respect to the stock setting. For example you start the camcorder app, wait for aMGC to become active and tap the downward arrow, it should quickly flash -6 dB (as each short tap changes the gain by 6 dB) and then go back to updating the current level. If you tap the same arrow again it should quickly flash -12 dB, and so on.
Not well documented, I have to admit...

Oh that is right! I didn't notice that. Thank you, i know everything now, the mod rocks! (i'll finally be able to record a concert gig at decent quality! i'll feedback with my results from MUSE concert next tuesday;))

///Edit:
To everyone facing the same problem as I: I managed to fix it by reflashing the zip. turns out that the last time i flashed it, it left unfinished mixer_paths.xml resulting in not being heard on voice calls :)
 
Last edited:
  • Like
Reactions: chdloc

mpiwosal

Senior Member
Feb 20, 2013
65
10
After a few more test i have one thought: what about if you placed "current RMS level" next to the dB switcher? IMO this would make it much easier. it wouldnt take much more space, and this way there would be no confusion. user could see all the time the dB level he is over (or under) the default settings. because (again, IMO) when you want to change the settings quickly it is really hard to do it (even in peaceful environment, not to mention at a gig). This would make this MOD perfect. I wasn't even sure this kind of thing was possible, and when i finally saw this thread my pulse went up to 200 for a moment. consider my idea, please :)
 

chdloc

Senior Member
Jul 19, 2010
1,140
1,724
After a few more test i have one thought: what about if you placed "current RMS level" next to the dB switcher? IMO this would make it much easier. it wouldnt take much more space, and this way there would be no confusion. user could see all the time the dB level he is over (or under) the default settings. because (again, IMO) when you want to change the settings quickly it is really hard to do it (even in peaceful environment, not to mention at a gig). This would make this MOD perfect. I wasn't even sure this kind of thing was possible, and when i finally saw this thread my pulse went up to 200 for a moment. consider my idea, please :)

I think having two dB numbers show simultaneously will confuse most people, unless there is some sort of explanation in the UI, for which there is no room. Note that aMGC is also compatible with "Cinema FV-5" which offers much less screen real estate to place the UI.
Also, no two acoustic environments are the same, so I'm not sure whether your approach will speed things up for folks.

Two notes on aMGC that may not be widely known:
  • you can flash the current gain delta for a second at any time when tapping on the text showing the instantaeous RMS measurement
  • a long-tap on one of the arrows will move the gain by 12 dB as opposed to 6 dB when the arrows are short-tapped
 

chdloc

Senior Member
Jul 19, 2010
1,140
1,724
Update on camcorder mod and M Preview

Just finished running some tests on M Preview. The simple mod (no noise suppression) works as expected. The stereo recording/playback as well as sidetone options work as well.
However, the mod with noise suppression which requires a modified libaudioflinger fails. Even when I push an unmodified libaudioflinger that I've built from the M Preview sources the phone refuses to boot.
This leads me to believe that the updated sources which are required to build libaudioflinger that ships with the Preview image have not been pushed to AOSP yet.
 
Last edited:

mpiwosal

Senior Member
Feb 20, 2013
65
10
A week late (sorry for that) but i'm here to show you some recordings from concerts using this mod.

Let me start with telling you how I have achieved my results:
*had no time to switch between db -6 and db -12 during the concert so i stayed with -6db (aroma)
*reduced my default mic gain to the lowest possible (80/81 if i'm correct?) option in aroma
*aMGC (obviously) switched on
*nothing more really, stereo on but it doesn't matter in this case
***during recording I had to go -24dB or even -30dB from the default level, from my observations you need to keep the RMS level around -30dB (max. -20dB, otherwise it won't record well)

next let me say: there is an improvement. really. i didn't record (sadly) any video without the mod for comparison, but anyone who has ever tried recording something in loud environments knows the pain.
problems:
*first seconds of my videos are terrible. this is due to the time needed to set the right dB level, after that it's much better
*reduced gain lowers the loudness, so the videos (or more accurately audio tracks) need to be enhanced. Instructions on how to do this are at the end of this post.

so, here are the videos: [listen on headphones!]
Bastille 1: (-24dB-> it was enough because it wasn't the headliner so it wasn't that loud and i was far away from the stage)
https://youtu.be/OlbkCZKTV00
Bastille 2: (kept -24dB, i was closer to the stage but it was still fine)
//edit: you can hear how the stereo works on 0:30 (when i'm turning the camera), provided you have good headphones
https://youtu.be/DMp58LJfaWQ
Muse 1: (so, here goes the headliner... -30dB was a must since it was veeeery loud. and i was in like the 3rd row directly in front of the speakers, also the people singing and screaming. that was a tough one to record i must say...) [completely skip the first 20 seconds...]
https://youtu.be/mEwv7PNnMtk
Muse 2: (-30dB, obviously... but listen to the drums! it would never be possible without this mod!) [also skip first 15sec]
https://youtu.be/nr1fPIxF4Cw

ok that's it from the videos. now for the "editing". note that i'm not a proffesional, i'll be describing my own way to achieve it, you can share if you have a better one.
programs you'll need: VLC player, audacity, mkvmerge GUI (or similar)

instructions:
1. You'll need to separate the video from the audio. it can be done in VLC:
*open VLC-> media-> convert/save-> add file (here you should choose your video)->convert (or alt+o)-> on the next window, choose tools icon ("edit selected profile")-> on "encapsulation" tick "wav", next on "video codec" untick "video", on "audio codec" tick audio, set codec to wav, change bitrate to 320 and sample rate to highest possible-> click save,set destination file and click start. you're done for now, and you have separated your audio from video.
2. audacity. firstly go to edit->preferences->libraries and make sure that ffMPEG library is installed. if not, download and install from there.
next: open your audio file in audacity and turn the volume up by marking your entire (or not) track and selecting effect->amplify and choosing the right amplification (trials and errors). after you're done with that, go to effect->normalize->ok, and later go to effect->compressor-> ok.
Lastly, go to file->export audio, and choose the path you want.
3. open mkvmerge click add, and choose your video and NEW (!!) audio file. On the second window (tracks, blablabla) UNTICK something starting with AAC, and start muxing. You're done. you have your video mixed with reworked audio. uff that was tiring, wasn't it?... i'm looking for a simpler method. anyone?

ok that's it. i know the videos aren't perfect but hey, it was my first try. and i didn't think my nexus 5 would ever be able to record a concert like that! uff that was a lot of typing. sorry for the delay again and don't hestitate to ask questions and discuss :)
 
Last edited:
  • Like
Reactions: chdloc

chdloc

Senior Member
Jul 19, 2010
1,140
1,724
A week late (sorry for that) but i'm here to show you some recordings from concerts using this mod.
This is great. Thanks for sharing!
Please allow me to add a few thoughts below.

*had no time to switch between db -6 and db -12 during the concert so i stayed with -6db (aroma)
I don't think you want 12 db of noise suppression when you record music. Even 6 db is really pushing it. I decided to couple aMGC with the noise suppression scheme, so my mod will have minimum impact on the rest of the system. I can elaborate more on that if desired.

***during recording I had to go -24dB or even -30dB from the default level, from my observations you need to keep the RMS level around -30dB (max. -20dB, otherwise it won't record well)

I personally was only able to test this while blasting my car stereo at (for me) insane volumes. This still would not compare to a live concert. I was able to get decent quality audio at RMS levels of -6 dB, but I always start out at the default level. Not sure whether that may make a difference.

One idea I'm kicking around is to show a "concert" button before the aMGC UI comes up. If pressed, the levels will be low right out of the gate. What do you guys think?
 
  • Like
Reactions: MrMarques01

Top Liked Posts

  • There are no posts matching your filters.
  • 108
    Updates
    • Lollipop: The attached archive named camcorder_audio_fix_plus_stereo_playback_LMY47D_v1_1.tar.gz or this Aroma installer is fully supported on any AOSP-based Lollipop build greater than or equal to 5.1
    • M-Preview: The "simple" fix (without noise suppression) offered by this Aroma installer should work any of the M-Preview builds. The "advanced" mod, however, is incompatible with M-Preview builds.
    • October 8, 2015: Full Marshmallow support available here
    • August 26, 2016: Nougat support for simple fix available here

    The Problem

    The audio of a camcorder recording made by the Nexus 5 has often been described as "under-water" or "bubbly":
    Speech signals sound distorted and low-level background sounds fade in and out. Overall, an embarrassingly bad audio quality.
    As it turns out, the audio recording is fed to a noise suppression algorithm that is way too aggressive.
    Also, the Nexus 5 is not able to record anything useful in very loud acoustic environments, such as a concert.
    The mod presented here is aimed to fixing these issues.

    Simple fix: Turning off noise suppression

    I found a very simple way to turn off noise suppression altogether. All this fix does is to select a different audio device that bypasses noise suppression.
    Unfortunately, this change requires modification of a system library which means that your phone needs to be rooted.
    To experience the effect of the simple fix you can listen to some audio samples here.

    Advantages of this "simple" version of the mod
    - the recording is now devoid of any signal processing, i.e. no additional distortion is being introduced to the sound
    - the mod should work with pretty much any Lollipop AOSP-based ROM. Separate mods are available for CM11 and CM12, see link below.
    - the simple fix should not interfere with any other app

    Disadvantages of this "simple" version of the mod
    - since noise suppression has been disabled, the (white) noise that the acoustic front-end (microphone, preamp, analog circuitry) of the Nexus 5 produces is now very audible. While I do not see this a problem in high-noise and/or outdoor environments, the high level of white noise can be problematic in quiet environments
    - by default, the volume of the recorded sound is now lower than stock. Refer to the section "Changing the microphone gain" below for more details
    - aMGC (see below) is not supported

    A new simpler "simple" version of the mod that does not require modification of a system library can be found here


    Advanced Fix: Applying moderate noise suppression

    After having spent a significant amount of time tinkering with the Android audio stack, I found a way to apply a moderate amount of noise suppression to the camcorder signal.
    This new fix makes use of the webRTC noise suppression algorithm available in AOSP (but it was missing the required plumbing). For now, I'm giving you guys two options to play with: 6 dB and 12 dB of suppression.

    Note that although 6dB of noise suppression is generally considered as "low", I can still hear some artifacts, but they are significantly reduced when compared to the stock experience. (The stock library adds about 20 dB of noise suppression)
    For my taste 12 dB adds too much distortion, but it may fit the bill for some of you.
    Keep in mind that webRTC's noise suppression algorithm has been optimized for speech signals and, as a result, other types of signals (music, nature sounds etc) may suffer from some distortion.
    To experience the effect of the advanced fix, you can listen to some audio samples here.

    Advantages of the advanced fix
    - users now have the option to select the level of noise suppression that suits their needs.
    I'm personally torn between no noise suppression and 6 dB of noise suppression due to some (barely audible) distortion still present when 6 dB of noise suppression is applied.
    - aMGC is supported (see below)

    Disadvantages of the advanced fix
    - this fix may not work with ROMs other than Stock Android 4.4.4/5.0.x/5.1.x as fundamental changes to the Android audio subsystem (audioflinger) were necessary to feed audio to the built-in effects processor
    - there may be problems with this fix in combination with other audio mods (e.g. DSP Manager). Please report back if you experience problems with this fix and other audio mods on stock Android

    Known issues
    - having either "hotword detection from any screen" or "touch sounds" enabled results in the audio bypass the effects processor, which means that either of these features will disable noise suppression completely!


    Installation instructions:
    Please refer to the README provided with the attached archive.

    assisted Manual Gain Control (aMGC)

    The Problem
    By default, the microphone setup used for camcorder recordings is tuned to be fairly sensitive. The idea is that distant sources are still recorded with sufficient level. The disadvantage is that loud signals, such as music or screaming kids, will cause a great deal of distortions, thereby rending recordings in noisy environments virtually useless. Android does not offer any way to adjust the microphone gain by the user.
    In looking into this issue, I have played around with automatic gain control (AGC) as offered by a webRTC component that ships with Android. I found that AGC as implemented (optimized for speech signals) is not suitable for camcorder recordings as it more often than not causes wild swings of level fluctuations.

    An attempt to arrive at a solution
    The idea as implemented in this "app" (more accurately a background service) is to show a UI with gain control during a camcorder recording along with a VU meter to assist the user to adjust the gain during a particular recording. I'm calling this approach assisted manual gain control (aMGC).


    The attached apk for aMGC has been generated directly from a Tasker project by using the Tasker App Factory app.
    A Tasker project that can be imported into your own Tasker setup is also supplied.
    Note that the minimum API level for this app is 21. Hence, it is only compatible with Android > 5.0

    The app does the following:
    • pretty much nothing if you click on the icon, as it is a service that starts automatically on boot. However, you may need to start it manually in case Android decides to kill it.
    • it kicks in whenever the Google Camera launches
    • it observes the state of the soundcard; if the microphone is opened (i.e. a camcorder recording is started), it displays a small floating and blocking UI in the lower right-hand corner of the screen with which the microphone gain can be adjusted
    • it uses the LED to display a VU meter, going from faint green (very low signal level detected) to yellow to orange to red (very high signal level detected)
    • by default it uses the gain as defined in mixer_paths.xml (indicated as 0 dB in the UI). Each short-press on the "down" button decreases the microphone gain by 6dB; a long-press decreases the gain by 12 dB; similarly each press on the "up" button increases the gain by 6 dB and a long-press by 12 dB. Additional gain is limited to +12 dB
    • Whenever a recording is stopped, the UI disappears and the LED VU meter stops. When the record button is pressed again, everything starts over again with the default values from mixer_paths.xml. Note that it is an Android implementation detail that mixer_paths.xml edits need a system reboot to be applied.

    Prerequisites
    • latest "advanced" camcorder audio mod available here
    • tinymix (attached; uncompress, copy to /system/bin, and make executable)
    • NEW: all attached shell scripts, see shell_scripts.tar.gz; unpack, create a directory /data/local/tmp/camera, copy all scripts to that directory, and make all files executable. I had originally thought that Tasker automatically incorporates all shell scripts into the apk, but it does not. Currently, aMGC expects these files to reside in /data/local/tmp/camera . I'll try to fix that in a future revision of the app, by integrating the shell scripts into Tasker.
    • app needs root privileges
    • busybox
    • app needs Accessibility permissions. After installation go to Settings->Accessibility and enable CamcorderMGC. Unfortunately, this permission is required to detect Camera start/stop events. Don't worry, I'm not doing anything nasty
    • Android >= 5.0
    • If you are using Tasker (also needs Accessibility privileges) you need to run at least version v4.6. Running the attached Tasker project, i.e. CamcorderMGC.prj.xml, is generally preferred over using the app. Note that you will also need to copy the attached shell scripts to /data/local/tmp/camera when using the Tasker project.

    Usage
    Hit record and observe the VU meter. If the UI and VU meter do not start you may need to start the app manually as Android may have killed it.
    You want the color of the LED to remain yellow/orange. Long periods of red means bad clipping. In that case you may want to lower the gain either gradually (6 dB steps) in moderately noisy environments or more aggressively (12 dB steps) in noisy environments until the LED keeps blinking yellow or orange. Short bursts of red are probably OK. I need you guys to give me feedback on that.
    If the levels seem too low after a recording has been made, simply boost the gain by using a decent video editing app on your PC.

    Known issues/limitation
    • Each interaction with the UI takes a couple of seconds to complete. Short-press or long-press the buttons once and be patient for the task to complete. Once completed, the current gain adjustment with respect to the default levels will be displayed.
    • aMGC currently does not work as expected when hotword detection is allowed from any screen.
    • aMGC currently does not work when "Touch sounds" are enabled in Settings -> Sound & notification -> Other sounds
    • Whenever the user changes the microphone gain(s) during a recording a very short click may be audible while the codec (WCD9320) changes the gains as requested. This occurs due to the discontinuity in the audio signal while the gain modification is being applied. Conventional remedies, such as cross-fading cannot be applied as the actual audio data is not available to the aMGC method. For "critical" recordings I recommend running a quick "sound check" first to find the appropriate gain and then quickly apply it at the onset of the actual recording. I suggest to be conservative with the gain as an overall low gain can be easily corrected for by post-processing while excessive gain may result in irreparable distortion.

    Installation instructions:
    Please refer to the separate README provided with the attached archive.

    Aroma installer
    Thanks to @spacetaxi there are extremely flexible Aroma installers available for added convenience.
    The latest installer for Lollipop < 5.1.0 can be found here and the one for Lollipop 5.1 here.
    The installer for KitKat (now deprecated) can be found here


    Confirmed working ROM/kernel setups


    • stock Android 4.4.4/5.0.x/5.1 with stock kernel
    • Cataclysm (Jan 23) with Code Blue kernel
    • Cataclysm (Jan 23) with Cataclysm kernel
    • CM11 (simple fix only, no aMGC)
    • CM12 (simple fix only, no aMGC)
    • stock Android 4.4.x with stock kernel (no aMGC)



    Additional mods
    In this section I describe mods that don't have anything to do with camcorder recordings, but still appear (or will be appearing) in the modified mixer_paths.xml

    Stereo playback
    Based on prior work by @sshafranko (but originally discovered by @dontbelive) I enabled "true" stereo playback on our device by turning on and tuning the earpiece loudspeaker.
    Refer to this post for details.

    Sidetone for telephony
    Closed-type headphones, noise canceling headphones, and IEM earphones are very good at shutting out environmental sounds. Unfortunately, they also block your own voice. While wearing these headsets you are actually hearing the sound of your own voice via means of bone conduction and resonances of head cavities. It sounds extremely low-pass filtered and it is very difficult to conduct a conversation while wearing headphones. This is where sidetone comes in. Please refer to this post for details.

    Using external microphones
    A tweak to the main mod is presented here, which allows an external microphone (via headset port) to be used instead of the built-in one. An important advantage of doing so is to be able to utilize a better-quality microphone. (The ultimate improvement in sound-quality can be achieved by using a (mono/stereo) microphone that connects via a good-quality preamp and ADC to the phone's USB port, if supported by an app.)

    Additional information

    Changing the microphone gain

    Background:
    The microphone path used by this mod is "voice-rec-mic-mod", which is derived from "voice-rec-mic" already present in the stock version of /system/etc/mixer_paths.xml .
    The default microphone gain is set to 97 ("DEC6 Volume"). If one feels that microphone "sensitivity" is insufficient, this gain can be increased significantly. According to ALSA mixer data, the maximum level can be set 124. Measurements have shown that each "tick" (integer increase of this value) adds about 1 dB of gain).
    You can actually also modify the "ADC1 Volume" parameter, which ranges from 0 to 19 (and adds about 1.5 dB per tick), but I have not seen any real advantage of modifying this value over the other in my tests. The abbreviation "ADC" (Analog-to-Digital Converter) suggests an analog gain which would result in a better
    SNR (signal-to-noise ratio) if that gain is adjusted rather the one associated with DEC (which for sure is a digital gain and thus has no effect on SNR if used inside the signal's full digital scale). My tests, however, have shown no advantage of using the "ADC1 Volume" setting in terms of SNR.

    Of course, there is a tradeoff between microphone gain and background noise, i.e. higher gain results in more audible microphone/preamp ("white") self-noise. As a matter of fact it is this noise that the original library tries to fight with its poorly implemented/configured noise suppression algorithm.

    Static modification of microphone gain:
    - method 1: The gain can easily be changed by editing the new mixer_paths.xml file directly via a file browser, like Root Explorer. The values can range from 0 to 124. Your phone needs to be rebooted for the changes to take effect.
    - method 2: run the Aroma installer

    Dynamic modification of microphone gain using tinymix:
    Once the recording has started, the microphone gain can quite easily be modified with the help of the attached tinymix binary, which can be built from the AOSP tree.
    The syntax (after it has been uncompressed), copied to, e.g., /system/bin, and made executable is:
    > tinymix "DEC6 Volume" X
    where X=[0,124]. Again, there will be a tradeoff between microphone gain and noise amplification.
    The big caveat is that the gain is reset to the one listed in the file /system/etc/mixer_paths.xml every time a new recording is started.
    If you are running the "advanced" mod, then you may want to try aMGC which helps you adjust the gain depending on the acoustic environments (see the section on aMGC).


    Links to the simple mod for CM

    Go here for CM11-based ROMs
    and here for a CM12 (and CM12.1)-based ROMs

    Thoughts on in-call voice quality

    As the question regarding in-call audio quality has come up a few times, let me elaborate on my findings:

    Most modern smartphones use two microphones when making phone calls. Dual-microphone processing can be very sensitive to the relative position of the talkers mouth and the microphone, in particular in varying background noise scenarios.
    Especially when the main microphone on the N5 (the one behind the grille) is far away from the mouth the local talker may be mistaken for background noise and, hence, get suppressed.

    As dumb as it sounds, try to hold your phone "right" when making calls, i.e. talk directly into the microphone and try not to move the phone much.
    A second very important "good practice" suggestion is to keep the loudspeaker volume as low as possible and try to talk in low background noise environments (I know that the latter one is not always possible). The reason is the rather nasty subject of double-talk.
    When a phone detects a double-talk situation, i.e. a loud RX signal combined with a strong TX signal (talker + background noise), the AEC (acoustic echo canceler) will typically start "clipping" the near-end speech, which results the other end not being able to hear you.

    Other than these two basic suggestions, there are a couple of things a brave soul can try to fight this issue.
    Note there is no (and possibly never will be a) real fix without Qualcomm's and LG's intervention. I'm currently using what's
    behind door #2 below with success...

    1. Changes in build.prop (not an endorsed workaround)
    ========================================

    consider this change
    - persist.audio.dualmic.config=endfire
    + persist.audio.dualmic.config=broadside

    What this does is change the dual-microphone algorithm to an alternate one. In my (limited) testing, however, "broadside" was worse than the "endfire" configuration. Actually, I never got many complaints about other people not being able to hear me using "endfire"
    However, it may work for you. If it does, great, and you don't need to move on to try other stuff, such as another change:

    - persist.audio.dualmic.config=endfire
    + persist.audio.dualmic.config=none

    This change turns off dual-microphone processing altogether. The big caveat is, however, is that this change seems to disable other vital signal processing as well, in particular AEC.

    Other issues I have seen with these two changes is that the first call after a reboot is often "bad", which can be fixed by quickly switching to speakerphone mode and back. Not good.

    2. A very complicated workaround (which works for me)
    =========================================

    As I mentioned earlier in the thread, I spent a lot of time trying to fix the in-call RX distortion issue when recording from the line.
    I found a workaround that works for me that may partially address the issue of occasional low TX level as well. I say partial since low TX level may be caused by both the dual-microphone processing as well as the AEC in double-talk situations. This workaround only addresses (turns off) the dual-microphone processing while still enabling AEC as well as some noise suppression. Low TX levels in double-talk situations can only be improved by Qualcomm, but somewhat alleviated by an educated user (see suggestions above).

    The fix requires:
    * turning off dual-microphone processing (persist.audio.dualmic.config=none in build.prop)
    * custom AOSP kernel (3.4.0-gd59db4e) that allows for injecting proper (?) audio calibration data via Qualcomm's acdb interface, which enables AEC as well as single-channel noise suppression
    * a bunch of Tasker scripts
    * a shell script
    * a binary that commits the calibration data to the kernel/CPU upon a system reboot, or when needed as determined by the Tasker and shell scripts

    Ultimately, in finding a fix for this issue, I got stuck at the lack of documentation of Qualcomm's audio interface.
    My solution is just a huge hack to address a problem that really can only be fixed by Qualcomm and LG (and maybe Google) as
    all processing during cellular calls is done by Qualcomm deep within the MSM/DSP. It is my understanding that the signal processing within that chip is controlled by some of the proprietary vendor blobs.


    Some gory details

    Up until now, the device identifier used for camcorder recordings in the audio HAL, i.e. audio.primary.msm8974.so, has been selected
    as "SND_DEVICE_IN_VOICE_REC_MIC" (while stock uses the "CAMCORDER" device identifier with disastrous quality consequences).
    Many people have been observing that the Nexus 5 is unable to produce any useable recordings in loud acoustic environments, in particular
    club or concert hall settings. After spending a lot of time doing detective work, I found that the problem can be traced to a high-pass filter (HPF)
    being active in either the codec itself (WCD9320) or the main chipset (MSM8974) while most available device identifiers are used, including
    "CAMCORDER" and "SND_DEVICE_IN_VOICE_REC_MIC". I'm suspecting two problems with this HPF. One, I think that the HPF itself may be causing
    distortions. Second, by filtering out low frequencies, the microphone level estimate that I'm performing inside the audioflinger service is biased in that it
    cannot take into consideration the low frequencies that actually hit the analog-to-digital converter, which will eventually cause it to clip.
    I found that the "ACDB_ID_VOICE_DMIC_EF_TMUS" identifier in the audio HAL disables the HPF filter. Now the level estimate that is being used by
    aMGC is bias-less. Clipping can be properly detected and action can be taken with the aMGC UI to appropriately lower the microphone gain as needed.

    An explanation why low-frequency clipping is much worse than clipping at higher frequencies:
    In general, clipping (when a signal exceeds full-scale representation of a digital system) causes the introduction of even-order harmonics.
    Assume you want to record a 50 Hz sinusoidal signal. Clipping of that signal will cause the recording to not only include a 50 Hz tone (0-th order harmonic),
    but also a 150 Hz tone (2-nd order harmonic), a 250 Hz tone (4-th order harmonic), etc. In all, more than a hundred additional tones will show up in your
    recording, albeit at progressively lower levels than the 0-th order harmonic. That original pure sine wave now sounds more like a "rectangular wave".
    Imagine what happens when a more complex low-frequency signal is getting clipped. The recording is ruined.
    On the other hand, a clipped 1000 Hz sinusoidal signals will "only" produce seven additional harmonics in the frequency range that the Nexus 5 is capable
    of recording (approximately less than 16 kHz). Don't get me wrong, clipping is bad no matter the frequency (and a professional avoids clipping like the plague),
    but the effect is much more dramatic when clipping is happening at low frequencies.


    Thanks

    Big thanks go to @spacetaxi for the Aroma installers and @skvalex without whom I would probably never have looked into any of this.

    XDA:DevDB Information
    [MOD] [ROOT] Camcorder Audio Quality Fix with Stereo Recording and Playback Support, Device Specific App for the Google Nexus 5

    Contributors
    chdloc

    Version Information
    Status: Testing

    Created 2015-03-06
    Last Updated 2015-03-06
    47
    Aroma installer of chdloc's camcorder audio fix for Android 5.0.1 stock rom

    This is the aroma installer of chdloc's camcorder audio fix for Android 5.0.1 stock rom. Other installers of the fix are available for 5.1 stock rom (see post #627) and 4.4.4 AOSP-based roms (see post #3).

    The installer has the following features:
    • Install camcorder audio fix. You can select the level of noise suppression, microphone gain, mono or stereo recording and audio bitrate. Optionally the stereo playback mod can be installed. You can choose the phone's orientation for stereo playback (micro-usb port to the right or to the left) and the gain levels for ear speaker and bottom speaker. When installing the "advanced" audio fix (6dB or 12dB noise suppression), you can optionally install the prerequisites (tinymix binary and scripts) for chdloc's aMGC implementation. To actually use aMGC you will also have to install the aMGC apk or the Tasker project provided by chdloc.
    • Install stock audio libs+config. Optionally the stereo playback mod can be installed. You can choose the phone's orientation for stereo playback (micro-usb port to the right or to the left) and the gain levels for ear speaker and bottom speaker. The aMGC prerequisites (tinymix binary and scripts) will be deleted.

    Please make a backup of the system partition by using the recovery (e.g. TWRP) prior to installing this zip, so you can just restore the system partition if you don't like the changes. And there's always a (small) risk that something goes wrong when flashing a zip. Anything you do, you are doing at your own risk. :fingers-crossed:

    The installer will overwrite the following files:
    • /system/etc/media_profiles.xml
    • /system/etc/mixer_paths.xml
    • /system/lib/hw/audio.primary.msm8974.so
    • /system/lib/libaudioflinger.so
    • /system/lib/soundfx/libaudiopreprocessing.so
    • /system/vendor/etc/audio_effects.conf
    Additionally the following file and directory may be installed or deleted:
    • /system/bin/tinymix
    • /data/local/tmp/camera/ (containing some scripts)

    Please do not forget to post your experiences with this fix! Happy flashing! :)
    45
    Camcorder mod for Marshmallow (Android 6.0.0 and 6.0.1)

    This post is a placeholder for all camcorder mods that work on Marshmallow. Both the mod itself -- as a flashable zip based on the great work by @spacetaxi -- and aMGC are posted here. More details on aMGC (assisted manual gain control) are provided in the OP. Note that you will only need to install either the aMGC apk or the Tasker project from the attached archive if you selected aMGC support in the Aroma installer.

    Changelog:
    • v0.9: initial revision (October 7)
    • v1.0: added aMGC support (October 8)
    • v1.01: aMGC only -- fixed a problem that may prevent the aMGC UI to appear in some configurations (October 20, aMGC)
    • December 9: added support for Android 6.0.1, build MBB29K
    39
    Aroma installer of chdloc's audio fix for Android 5.1 stock rom

    This is the aroma installer of chdloc's audio fix for Android 5.1 stock rom. Other installers of the fix are available for 5.0.1 stock rom (see post #235) and 4.4.4 AOSP-based roms (see post #3).
    I will keep this post updated if there will be a new version of the installer.

    2015-03-13: Updated installer (v1.1) for Android 5.1 stock rom, including fix for "no TX audio bug" when on speakerphone (see post #645)

    The installer has the following features:
    • Camcorder Audio Fix. You can select the level of noise suppression, microphone gain, mono or stereo recording and audio bitrate. Optionally the stereo playback mod and the sidetone config can be installed. You can choose the phone's orientation for stereo playback (micro-usb port to the right or to the left), the gain levels for ear speaker and bottom speaker, the sidetone level for headset and handset use cases. When installing the "advanced" audio fix (6dB or 12dB noise suppression), you can optionally install the prerequisites (tinymix binary and scripts) for chdloc's aMGC implementation. To actually use aMGC you will also have to install the aMGC apk or the Tasker project provided by chdloc.
    • Install stock audio libs+config. Optionally the stereo playback mod and the sidetone config can be installed. You can choose the phone's orientation for stereo playback (micro-usb port to the right or to the left), the gain levels for ear speaker and bottom speaker, the sidetone level for headset and handset use cases. The aMGC prerequisites (tinymix binary and scripts) will be deleted.

    Please make a backup of the system partition by using the recovery (e.g. TWRP) prior to installing this zip, so you can just restore the system partition if you don't like the changes. And there's always a (small) risk that something goes wrong when flashing a zip. Anything you do, you are doing at your own risk. :fingers-crossed:

    The installer will overwrite the following files:
    • /system/etc/media_profiles.xml
    • /system/etc/mixer_paths.xml
    • /system/lib/hw/audio.primary.msm8974.so
    • /system/lib/libaudioflinger.so
    • /system/lib/soundfx/libaudiopreprocessing.so
    • /system/vendor/etc/audio_effects.conf
    Additionally the following file and directory may be installed or deleted:
    • /system/bin/tinymix
    • /data/local/tmp/camera/ (containing some scripts)

    Please do not forget to post your experiences with this fix! Happy flashing! :)
    36
    Aroma installer package of chdloc's fix for Android 4.4.4 stock / AOSP-based roms

    This is the aroma installer package of chdloc's camcorder audio fix for 4.4.4 stock / AOSP-based roms. Other installers of the fix are available for Android 5.1 (see post #627), Android 5.0 (see post #235) and for CM11 (see post #56).

    Flashing the installer, you will get four options:
    1. Install Audio Fix - simple: no noise suppression, bitrate 288 kbps
    2. Install Audio Fix - advanced (6 dB): 6 dB noise suppression, bitrate 288 kbps
    3. Install Audio Fix - advanced (12 dB): 12 dB noise suppression, bitrate 288 kbps
    4. Install Stock KTU84P Audio: 20 dB noise suppression, bitrate 96kbps (stock audio libs and config from build KTU84P)
    So if you are using Google's stock firmware build KTU84P, option 4 will revert the system files changed by options 1-3 (audio libs and config files) to their stock versions.

    If you are using a different firmware build or if you've changed the config files and want to be able to revert the files to their current state, please make a backup of the system partition by using the recovery (CWM / TWRP) prior to installing this zip. Then you can just restore the system partition if you don't like the changes.

    Every option will overwrite the following files:
    • /system/etc/media_profiles.xml
    • /system/etc/mixer_paths.xml
    • /system/lib/hw/audio.primary.msm8974.so
    • /system/lib/libaudioflinger.so
    • /system/lib/soundfx/libaudiopreprocessing.so
    • /system/vendor/etc/audio_effects.conf
    By the way, you should make a backup of the system partition in any case! There's always a (small) risk that something goes wrong when flashing a zip. Anything you do, you are doing at your own risk. :fingers-crossed:

    And please do not forget to post your experiences with this fix!

    Happy flashing! :)