yashsingh1/xdaforums huggingface dataset:
[Nexus 5 Android Development] chdloc:
I'm not sure I understand what you are trying to accomplish. Would you like to be able to record a phone call with third-party apps or "just" force all audio recording to use the VOICE_RECOGNITION audio source? If the former, there are plenty of apps out there trying to record a phone call. If the latter I'm not sure you will be able to do that unless you modify the audio HAL as each app decides itself which audio source to use.

(Note that the Nexus 5 and LG G2 do share common hardware components, but the software is quite different.)

Three more thoughts:

there may be a way to manipulate the audio HAL without having access to the sources: if your phone has the file /system/etc/audio_platform_info.xml then there is a remote chance that you can force audio source manipulation. I have never played with that file, though.

if you are a developer and have access to sources you can "tee" off and write to file a number of audio streams with this Google API

maybe there exists a Xposed module that does what you are trying to do

Absolutely!
[Nexus 5 Android Development] disiz:
Thanks for your answer. What I'd like to do is snapchat have better sound when I record video. With other camera app I was able to set voice recognition instead of default or camcorder, and sound recoreded in video is way better.

So I'd like snapchat use same audio source for record videos. I can't do with any xposed mod because snapchat block account when xposed is enabled on phone...

And I'm not a developer but I can just edit some files or else I guess.

I've looked in the phone, no audio_platform_info.xml file here (my rom is still KK 4.4.) but there are some media_profiles.xml, media_paths.xml or media_paths_auxpcm.xml that can be good, I can give them to you if you think something is possible to set voice recognition for all audio in videos recorded :)

Thanks a lot.
[Nexus 5 Android Development] Gabriel1495:
On my Nexus 5x, after a reboot, it works very good. Thanks!
[Nexus 5 Android Development] chdloc:
Unless you are running a custom ROM to which you have source code access, I think the only chance of getting this to work is to hope that your ROM is looking for the file /system/etc/audio_platform_info.xml. One way to find out is to reboot your phone and immediately after your system has come up (within seconds) run the following command in an adb shell

logcat | grep audio_platform

If you see something like

"platform_info: platform_info_init: Failed to open /system/etc/audio_platform_info.xml, using defaults."

then you may be in luck. In that case open an editor and create a file called audio_platform_info.xml with the following content:

<?xml version="1.0" encoding="ISO-8859-1"?>
<audio_platform_info>
<acdb_ids>
<device name="SND_DEVICE_IN_CAMCORDER_MIC" acdb_id="61"/>
</acdb_ids>
<backend_names>
</backend_names>
<config_params>
</config_params>
</audio_platform_info>

Copy this new file to /system/etc on your phone, adjust the permissions to 644 (rw-r--r--), and reboot.

On the Nexus 5, the acdb_id for the CAMCORDER device is 61. No idea what the number would be on your LG G2. You will need to experiment with the acdb_id (start with 62) followed by a reboot. No guarantee this will work or completely mute all audio. If audio disappears completely, remove the file again and there is likely nothing else you can do other than ask the Snapchat developers to allow the user to select the recording device.
[Nexus 5 Android Development] chdloc:
New simpler "simple" mod?

For those of you only using the "simple" camcorder audio quality mod -- the one without noise suppression -- I think I just found a simpler method which does not require modifying a system library (audio.primary.msm8974.so). Instead, this one involves the addition of a simple text/XML file. If you'd like to try it, use the Aroma installer to revert to stock (or flash a new system.img), copy a file called audio_platform_info.xml with the following contents to /system/etc (permission 644, i.e. rw-r--r--), followed by a reboot:

<?xml version="1.0" encoding="ISO-8859-1"?>
<audio_platform_info>
<acdb_ids>
<device name="SND_DEVICE_IN_CAMCORDER_MIC" acdb_id="89"/>
</acdb_ids>
<backend_names>
</backend_names>
<config_params>
</config_params>
</audio_platform_info>

You may need to adjust the gains in mixer_paths.xml ("camcorder" device).

So, really, the only advantage of doing it this way is for you guys not needing me to create a new library when (if) a new version of Android comes out for our Nexus 5, unless you would like to continue to use the "advanced" mod.
[Nexus 5 Android Development] chdloc:
I don't think that the files that you quoted will help you achieve what you are trying to do and I'm afraid that you've hit a brick wall.
[Nexus 5 Android Development] disiz:
OK that's bad news then. And maybe you think something is editable in snapchat apk before or after install to change the audio source record ?

And another question, if I edit those xml/conf files in system/etc with text editor, the phone probably won't reboot if I break something ? :)

Thanks a lot.
[Nexus 5 Android Development] ler01:
Hi, chdloc, thank you for your work!

I'm having a problem on my n5 when using my headphones (without mic) during a phone call. As I figured out while testing phone uses both mics during call when hp are plugged in, so when I'm having a phone call in noisy area noise cancellation doesn't work and my opponent hardly hear my voice because of noise and when I plug headphones out he hears me much much better (i assume because second mic is starting to work for noise cancellation). So my question is if there are something I can do to turn on noise cancellation while my headphones are plugged in?

If it's important - I use cataclysm MM with advanced audio mod applied. Also earlier when my headphones were pluged in during call my phone used only second (one near the headphones hole) mic until I made change that I found in this topic (link). After this change my opponent hears me much better during call but only in quiet places.
[Nexus 5 Android Development] chdloc:
You can try to decompile the Snapchat apk, change the audio source, and recompile. I have never done that, so I cannot be of further assistance. I suggest you start with this post. Good luck!

It is certainly possible that you end up in a boot loop if you "mess up" the xml files (often a simple permission problem). However, it is very easy to recover from those types of boot loops once you realize that you can actually use adb from your PC to get into the phone during the (Android-level) boot loop and make all necessary repairs (have the stock version of the offending file handy!), followed by a reboot. I've been there numerous times.

Note that this approach will not work if you end up in a kernel-level boot loop, which you won't if you mess only with Android-level files (such as everything is /system/etc)

For this phone, noise suppression comes in two flavors:

Single microphone noise suppression. This type of noise suppression really only gets rid of "white noise" and is not able to suppress localized interferers such as other people, TVs, traffic noise, etc.

Dual-microphone noise suppression. This type of noise suppression does allow for "spatial noise reduction", which means that localized interferers (typically in the farfield) can be suppressed. I do not know the exact algorithm used in the Nexus 5, but my educated guess is that it assumes that the desired signal (you) is talking directly into the main microphone at very close proximity (nearfield). The auxiliary microphone on top of the phone senses signals around you (farfield) and the algorithm subtracts those signal from the main microphone signal (by assuming that the farfield signal is approximately identical between the two microphones), thereby only recording your voice with, ideally, all other signals removed.

Even though we could theoretically use both microphones in use-cases other than handset mode, I'm pretty sure that the spatial noise suppression algorithm used is optimized for the handset mode only and would fail miserably in other situations. I'm not sure there is anything you can do other than hold the active microphone close to your mouth when making a phone call while wearing microphone-less headphones.
[Nexus 5 Android Development] disiz:
Thanks for this answer, I guess it's something like that I was looking for. I'll give a try to see if it's possible to change this on apk.

Thanks.
[Nexus 5 Android Development] Flyview:
That's interesting you mention Snapchat. I noticed my sound in Snapchat videos I record has a crackling in the background. I wondered if it's due to this mod but didn't uninstall it to check. Are you hearing the same?
[Nexus 5 Android Development] disiz:
I just notice that sound is horrible because recorded with mic, but with others apps with voice recognition sound is much better, less metalic or electronic sound that break ears... :)

But no difference between sound recorded in snapchat and with stock camera that uses same audio source. Note I have LG G2 and not Nexus 5 :)
[Nexus 5 Android Development] chdloc:
I've recently tested Snapchat myself. Yes, the crackling in the background is due to the "advanced" camcorder mod. The reason is that Snapchat opens the CAMCORDER audio device with a request for noise suppression. Incidentally, this is the only parameter combination where my advanced mod kicks in. The problem is that the webRTC noise suppressor (which I added the necessary plumbing for) does not expect the data to come at 44.1 kHz sampling rate (which Snapchat is requesting, the Camcorder requests a sampling rate of 48 kHz which is supported by webRTC). Since I wanted to add the least amount of complexity to libaudioflinger I decided against implementing my own audio buffer management which 44.1 kHz sampling rate would require (due to the necessary resampling). Long story short, if you cannot live with the "crackling" audio produced by Snapchat and you'd like to maintain decent camcorder audio recordings you basically have two choices:

switch to the "simple" camcorder mod as it does not modify libaudioflinger, hence no crackling sound produced by Snapchat. The disadvantages would be a higher noise floor in your recordings (6 or 12 dB) and the inability to use aMGC.

try going the Snapchat decompilation route mentioned in a previous post and figure out how to modify the decompiled code to either switch the audio recording device from CAMCORDER to something else or change the sampling rate to 48 kHz.
[Nexus 5 Android Development] Flyview:
Thanks. I primarily use this mod just for the stereo speakers as I rarely record video with the phone anymore. Is there a way to install just that?

Sent from my Nexus 5
[Nexus 5 Android Development] chdloc:
I haven't really tried it, but you should be able to achieve that by applying the appropriate options in the Aroma installer.
[Nexus 5 Android Development] Flyview:
Yup that worked, thanks! For some reason I thought the "stock" option (first step in Aroma installer) would just return everything to stock.

Sent from my Nexus 5
[Nexus 5 Android Development] kostelo:
Is there any way to achieve better sound and higher gain in-call by the main mic using this mod ? Sorry if it has been mentioned already but I'm lost in all the technical definitions in the thread.

I'm just asking because I'm facing serious problems with calls as my voice can barely be heard by the other person in line.

Thanks in advance.

Sent from my Nexus 5 CAF
[Nexus 5 Android Development] Neutrality:
Hi again)

Any ideas about decreasing the noise reduction level in the N5X? On a video there is something like a white noise...
[Nexus 5 Android Development] chdloc:
Take a look at the "Thoughts on in-call voice quality" section in the OP. It may give you a couple of hints on what you could try to improve things. If that does not help we can move to changing the microphone gains. For that we will need to know which audio device is in use when you make a phone call. Run the following command in an adb shell (or terminal emulator on your phone) while you are on a phone call and post the output

logcat | grep select_device

Post a sample video so I can evaluate whether the Nexus 5x suffers from the same noisy microphone issue that the Nexus 5 does. If it is, indeed, a white noise problem, then the webRTC noise suppressor that I integrated for the Nexus 5 may help the Nexus 5x as well.
[Nexus 5 Android Development] Neutrality:
https://drive.google.com/open?id=0B8kfnHfER5HINUhsMWxhaFlJTlU
[Nexus 5 Android Development] chdloc:
OK, yes, the Nexus 5x also seems to be using a noisy (cheap) microphone. From your short clip it is hard to tell whether Google is adding some noise suppression or whether I'm hearing coding artifacts, but there is something that makes the white noise sound slightly "unnatural".

I'm guessing that the Nexus 5x could benefit from low to moderate noise suppression as offered by webRTC. We should discuss further offline (PM).
[Nexus 5 Android Development] kostelo:
[MENTION=2760454]chdloc[/MENTION] The latest zip for MM roms seems to break the microphone in CM13. Can it be fixed somehow?

Also I have tried every single rom and kernel with almost every voice recording app. However the voice quality recorded is total crap. I compare it with recordings from my old HTC desire and it's clarity beats the nexus 5 anytime. Is it a hardware limitation in N5 or can we do something to improve the voice recording clarity?

Thanks in advance and sorry for the long post.
[Nexus 5 Android Development] chdloc:
If you are using the "simple" mod you may be able to get back on track by going back fully stock CM13 and following this post. In general, though, this mod is designed for AOSP and AOSP-based ROMs. CM and CM-derivatives are totally different beasts which require customized source code modifications.

This problem is related to improper setup of audio calibration data by OEMs for many Qualcomm-based devices, see here for a related comment by [MENTION=2859866]skvalex[/MENTION] .
[Nexus 5 Android Development] daun20:
Regarding the simpler simple mod: I'm on CM13 CAF and there's already a file called audio_platform_info.xml. Should I replace the whole file or only this line:

<device name="SND_DEVICE_IN_CAMCORDER_MIC" acdb_id="4"/>

with

<device name="SND_DEVICE_IN_CAMCORDER_MIC" acdb_id="89"/>

? Thank You!
[Nexus 5 Android Development] chdloc:
Just modify that one line and reboot. Please report back.
[Nexus 5 Android Development] daun20:
Hi chdloc,

thanks - it worked!

PS.: How does the system know what is ID 89? (before it was 4)
[Nexus 5 Android Development] chdloc:
The ACDB id's are numbers that are associated with completely undocumented and closed-source audio calibration data/procedures. Some references are given in the audio HAL's sources. The number 4 seems to be associated with the "CAMCORDER" device, which applies excessive noise suppression. As I don't have access to Qualcomm's audio calibration software, I had to apply the good old method of trial-end-error to find an ACDB id that bypasses Qualcomm's noise suppression.
[Nexus 5 Android Development] jshames:
why doesn't google incorporate this fix?

Hello,

I have recently discovered this fix and I am thrilled with it. I am using the latest Pure Nexus and the simple mod works fine. I have found that the advanced mod interferes will other recording apps (sound recorders simply wont work), and with the in-call microphone. With the simple mod the sound recording is SO much better, and I don't mind the hiss. Before I installed this I found it extremely frustrating that video recording was basically useless because the sound (particularly music) was so bad.

Does anybody have an explanation as to why Google has not applied this fix (or some other) into their updates? It seems breathtakingly irresponsible that there can be such a glaring problem, fixable with software, and that Google doesn't fix it. This is a Google device and Google has been supporting this device for 3 years with updates, for God's sake! This same question can be asked to the speaker volume problem that is also fixed by a simple mod. It just seems SO stupid that every time I do a firmware update I have to reapply these patches.

This makes me revisit the old Apple/Android dilemma. On one hand with Apple products you wouldn't even be able to apply a mod in the first place. On the other, if there was such a glaring defect, you could pretty much count on Apple eventually fixing a problem like this in one of their updates, so you wouldn't need a patch.

I'm interested in what people have to say about this.
[Nexus 5 Android Development] chdloc:
Just to clarify, there is no way the advanced mod interferes with the in-call microphone in the cellular telephony use-case as audio does not flow through audioflinger. It may, however, interfere with VoIP-based apps.

If setup correctly, the advanced mod works just fine with, for instance, "Easy Voice Recorder" (I use the "Pro" version which allows me to record in stereo) or "Voice Recorder". In setting up these apps you need to avoid a sampling rate of 44.1 kHz and use either 32 kHz or 48 kHz.

We can all only speculate. As far as I remember, Google actually added aggressive noise suppression with one of the KitKat updates because users were complaining about the hiss. They would have faced a new wave of complaints if they reversed their decision. A typical "damn if you do and damn if you don't" scenario. Now they certainly don't care about the Nexus 5 anymore. Sure, Google could (should?) add the proper plumbing for a decent software-based noise suppressor (like I do with the one provided by webRTC) in cases where noisy microphones are employed by the OEMs.
[Nexus 5 Android Development] scorpeeon:
Hi guys!

I was on a concert and tried to record just a little from it, but the sound indeed turned out to be completely unusable. It's really hard to believe the audio recording is this badly broken even in the latest versions. All this 5 years after my Galaxy S1 with Voodoo Sound would record pretty much any sound in perfect quality...

Thanks for this mod, I'll definitely try it.

Also a question: if a video is already made with the default horrendously distorted audio, do you think there's a moderately easy way to make the the sound a bit more acceptable with post processing? Like cutting off certain frequencies?
[Nexus 5 Android Development] chdloc:
I'm afraid there is absolutely nothing you can do to save your recordings.
[Nexus 5 Android Development] scorpeeon:
Yeah, that's what I thought. I played around a bit in Audacity just trying to make it a bit more bearable, tried clip fix, noise reduction, treble cut, normalize, etc but no avail, doesn't sound better in any meaningful way. It's garbage.

Well, at least I know next time not to try recording in a loud place without the mod. :) I suspect the white noise the mod introduces would be much easier to correct in post-processing.
[Nexus 5 Android Development] chdloc:
The mod does not introduce the white noise. The white noise is generated by the microphones themselves.

If you plan on recording in loud environments I would suggest you use the "advanced" mod (6 dB of noise suppression) with assisted manual gain control (aMGC). That way you can monitor for microphone clipping and intervene, if necessary. Remember that a recording with clipped microphone signals is irreparably ruined. The fundamental issue here is that the Nexus 5 does not offer any type of automatic gain control, like other phones do.
[Nexus 5 Android Development] scorpeeon:
Yeah I know (I meant it compared to the default noise filtering which is said to work fairly well on not so noisy environments - though it's the same filter that completely destroys sound in loud environments) but thanks for clarifying.

Thanks for the tip, I'll definitely check it out!
[Nexus 5 Android Development] scorpeeon:
Just a few things to clarify:

-will this work on the latest (like June 2016) ROMs?

-both methods needs root and modifying system, so on stock I can no longer install monthly OTAs after applying any of these, right? Or is there a way around this?
[Nexus 5 Android Development] chdloc:
Yes, I haven't seen any reports that would suggest otherwise.

Yes, both methods modify the system partition. You can go back to stock by either using the Aroma installer or by flashing the most recent stock system image prior to applying the OTA update.
[Nexus 5 Android Development] scorpeeon:
Well I went through with it, installed with aroma installer for 6.0.1, (I have MOB30M) the flashing seemed to be OK, then afterwards I installed the apk (CamcorderMGC) from the other zip. Now I'm not sure what should I see. When I click to the app it requests su permission which I granted, but nothing else is happening. When I record a video with the stock Camera app, I don't see any overlay or LED that would indicate anything. I'm not even sure what should I see or how could I confirm it's working?
[Nexus 5 Android Development] chdloc:
Have you given the app accessibility privileges (Settings->Accessibility)?
[Nexus 5 Android Development] scorpeeon:
Thanks, I missed that part. Drawing over other apps is also enabled (it was by default). However, it still doesn't seem to work. I can see toast message that the app has been granted su permissions when I launch the camera, so something is going on, but still can't see any indicators when recording a video. One time the camera app even froze after starting a video saying it can't connect to the camera.. Maybe I should try with Tasker instead?
[Nexus 5 Android Development] chdloc:
OK, before we get into more intense debugging, please make sure that you have busybox installed, as it is another prerequisite for aMGC to function.
[Nexus 5 Android Development] scorpeeon:
Wow it really was missing. For some reason I assumed aroma installed it because I selected to install it's prequisites.

Now it's working with the app and also with Tasker, great, thanks! Which one do you recommend btw from the two?
[Nexus 5 Android Development] chdloc:
Glad it's working for you. It doesn't matter which one you are using.

The advantage of going the Tasker route would be that you could try to figure out what's going on under the hood and maybe even extend the aMGC functionality to other apps.
[Nexus 5 Android Development] scorpeeon:
Great, thanks!
[Nexus 5 Android Development] scorpeeon:
Was playing around with it a bit, just a practical observation: I don't think it's a very good idea to display the current RMS and the mic gain on the same place. Initially I thought the app was not working properly and had to search this thread to verify that this value is the RMS, and gain is only displayed for a very short (sometimes extremely short) time when changing it or tapping on the number. This could be more clarified in the first post or readme.. :)

I see this is all implemented in Tasker (wondering btw how did you manage to get the same overlay UI in the standalone app? :) ), I'm very beginner at it, but might try to play around in it and see if I can come up with something that I like more.

Thanks again for this great work!
[Nexus 5 Android Development] chdloc:
You can tap the number (RMS) displayed between the arrows at any time to get the modified microphone gain. As acoustic environments are very diverse I see only limited usefulness in knowing the microphone gain and I'm focussing on continually updating the RMS instead . I tried to keep the overlay as compact as possible and this is the best I could come up with. I agree, though, that documentation could be better.

With the help of the "Tasker App Factory" app you can export profiles and even single tasks. Very powerful stuff. You can create pretty complicated apps without any Java knowledge, see for instance this Tasker-created app that I'm also currently maintaining.