[Nexus 5 Android Development] chdloc:
Unfortunately, I have gotten rid of the CM sources on my development machine a while ago, so I cannot go back and compare. I developed my mod based on AOSP sources and, hence, should work on all AOSP-based ROMs. CM has been too much of a moving target and, hence, I decided to not support it. As a "courtesy" I built the "simple" fix for a few CM builds (see links in OP). CM is quite different from AOSP and I'm very surprised that my main (non-CM) mod seems to be working for you. I highly suggest you install the version of the mod that is meant to work with CM

That is correct up to a certain point. As soon as you increase the digital gain such that the digital signal exceeds its full-scale representation ( outside of -32768, ..., 0, ..., +32767 for 16-bit) it will get clipped and non-linear distortions show up in the final signal.

I never bothered to look into the gains for the built-in speaker as it sounds crappy to begin with.

However, I did spend a lot of time looking into how to set the gains properly for the headphone use-case. My final findings are in line with what has been done in the consumer and professional audio space. Keep digital gain at or close to 0 dB (which translates to max Volume on the device, 15/15 chevrons, and "RX1/2 Digital Volume" set to 84 in mixer_paths) to maintain full DAC resolution and modify analog playback gain only (which is the "HPHL/R Volume" knob in mixer_paths). Contrary to popular belief, when paired with high-sensitivity dynamic IEMs, the headphone out of the Nexus 5 has the potential to sound just as good as any other mobile playback device out there. The problem with the Nexus 5 and, I think, all devices that use the Qualcomm WCD9320 DAC/amp combo, is that the final voltage presented to the headphone jack needs to be kept below around 200 mV(RMS) to avoid bad nonlinear distortions in the left audio channel (probably due to bad hardware design of the chip and/or associated circuitry). A good hardware design should allow for low-distortion audio playback all the way up to 1 V(RMS), which corresponds to almost 15 dB higher gain when compared to 200 mV(RMS). While no explanation was given Anandtech reported the same problem. That's why it is important to pair the Nexus 5 with high-sensitivity headphones. I've been meaning to open a new thread on audio playback quality on Android phones with theory and measurements, I just never gotten around to do it. This paragraph is pretty much the executive summary of my findings with the Nexus 5.

So going back to the speaker: I'm guessing that "SPK DRV Volume" is an analog volume control. I would then, in principle, recommend to keep "RX7 Digital Volume" at 0 dB gain (84) and adjust "SPK DRV Volume" to control final playback levels. However, the built-in loudspeaker is not capable of reproducing low frequencies (anything below around 500 Hz). Unless there is a highpass filter somewhere in the processing chain (implemented either in software or hardware), the loudspeaker will be hit with low-frequency sounds which will only result in bad distortions at even moderate playback levels, no matter which of the two gain knobs you adjust. I'll play around with the gains and post an update if I learn anything new.

Try adding

persist.audio.dualmic.config=endfire

to your build.prop file. This will enable echo cancellation and noise control. It will also enable dual-microphone processing which has resulted in mixed results for folks, leading to low TX levels in certain situations.