[Samsung Galaxy S7 (Exynos) ROMs, Kernels, Recoveri] random_n:
I've been working on the audio issues over the last few weeks, and I think I've made some headway. This is based on the LineageOS 14 code, and as such has its own set of idiosyncrasies vs the audio HAL that crDroid for the S7 would normally be using. I can't promise it's the best set of code changes as I've skipped "hello world" and jumped in feet first with this being the only C code I've worked on. Thus far, it's been a tremendous learning experience.

Current known significant bugs

Bluetooth devices with both Media and Call audio support can cause lockups/ANRs. Visit the Settings -> Bluetooth -> gear button -> disable Media Audio to prevent this. Using either HFP or A2DP with any device is fine, just not both at once. This is a Bluetooth stack bug and outside the scope of this fix, but it looks like it won't be an issue in Oreo/LOS15.1.

New in version 10 (2018-01-21):

Activation of DSPs for major improvements to speakerphone on cell and VoIP calls

Fixed audio stalling when one stream in a multi-stream playback scenario is stopped

Restored fast call path switching from v6 without bugs from v8

Always uses 16kHz call sampling (audio_hal.force_voice_config=wide) regardless of build.prop setting unless an 8kHz Bluetooth headset is in active use

Further improvements to routing path selection

Code cleanup

src-v10b update on 2018-01-24 to ensure compilability (very small corrections). No new binaries.

New in version 9 (2018-01-11):

Resolved all known voice call mic failure scenarios.

New in version 8 (2018-01-10):

Resolved kernel panic when using some Bluetooth SCO applications (WhatsApp calls when toggling between BT and handset)

Improved resiliency against mic failure on cell calls after extended routing changes

Bug! Voice call mic will not work after an 8KHz Bluetooth HFP media path is used except for further BT calls. Establish a 16KHz HFP media session or reboot to resolve.

New in version 7 (2018-01-09):

Improved reliability in audio route selection, small bug fixes

New in version 6 (2018-01-06):

Initial support for Bluetooth Hands Free Profile 1.6 16KHz eSCO "HD Voice". The HAL should automatically detect supported devices and switch between 8KHz and 16KHz modes when available. Old build.prop flag from v1 to v3 is now ignored.

Bluetooth HFP is working again for non-cellular calls and apps. Should function fine in Whatsapp, Hangouts, ReadItToMe, etc.

There is a bug with Google Assistant (and likely other apps) when using Bluetooth devices that support both handsfree and A2DP (music streaming) at once. During the rapid changes between HFP and A2DP, the BT driver locks up, and will freeze/eventually crash the whole Android OS with a soft reboot. Currently, visit the Settings -> Bluetooth -> gear button -> disable Media Audio to prevent this. Using either HFP or A2DP is fine, just not both at once.

Fast audio path switching for cellular calls (handset -> speaker -> bluetooth without 5-10 seconds of audio cutting in and out)

More mixer adjustments, but more to come yet.

There are still some bugs I would like to resolve, but I think this version is worth posting up for some further testing. Action sequences that result in the wrong input/output audio device choice or inappropriate volume levels (too low/high) are of particular interest right now.

------------

OLD INFO

This will accept a new build.prop flag to modify behaviour:

voice.bluetooth_wb=true or false. False or no setting will use 8KHz Bluetooth SCO for voice calls. That should work with most devices, but setting true will force 16KHz for either improved quality, or horribly scrambled sound. Use of 8 or 16 should be detected and automatically set based on device capabilities, but I haven't figured out how to do that yet, and also don't have any 16KHz-supporting headset profile devices to test with.

Fixed (I think) bugs and adjustments from stock LineageOS audio HAL:

-Scrambled audio on Bluetooth SCO calls (edit: for some devices at least... more work required)

-Loss of handset mic when switching an active call off Bluetooth

-Low mic on recordings

-Extreme feedback on speakerphone (there is still some yet though)

-Crashing on various audio routing changes

-Failure to output audio on track change in decompression offload mode

-Tweaks to audio DSP parameters and levels

-Dual speaker mode active for media

Known bugs:

-Bluetooth SCO input/output for anything but regular cell network/UMTS voice calls doesn't work.

I am still trying to sort out the Bluetooth SCO problem for VoIP/Assistant/etc. I can get a frame of output to go if I intentionally cause a crash while output should be running, so I think it's just a matter of applying a little more elbow grease and some lessons learned from the crDroid-similar audio_hw.c I'd found. Bluetooth A2DP (ie: music) is fine. Also, I am still tuning the DSP via the mixer config and some documentation from Cirrus Logic to output/record at more appropriate levels in more scenarios.

Flashable ZIP is attached. Take a NANDROID backup of /system before trying. I think it should be okay in any LineageOS 14/7.1.2-based ROM, but I've only tested with crDroid 3.8 and a G930W8 thus far.

v3 update: assume BT SCO microphone in non-WB config is available when SCO is active; fixes no audio on some BT HFP devices