[Android Software/Hacking General [Developers Only]] zyhk:
Maximizing the audio quality of bluetooth

I have enjoyed SBC XQ on TWS earphones very much and find modifications to maximize the audio quality by reducing jitters on audio outputs

DISCLAIMER: I am not responsible for any damage that may occur to your device, it is your own choice to attempt these modifications.

1. Disable battery optimizations for apps (to avoid less than 10Hz vibrato like distortion jitter)

music players, licensing apps, "bluetooth" (system app), "Android Services Library", "Android Shared Library", "Android System", launcher app, "Google Play Services", "Magisk", "PhhTrebleApp", keyboard app, kernel adiutor, etc.

2. Disable bluetooth absolute volume and set -4dB~-6dB gain level

In developer options, you can disable bluetooth absolute volume. Reduce the sender side volume to -4dB~-6dB gain level to avoid distortion of the receiver side DAC. (DACs on portable devices are easily distorted by loudly compressed music with near full gain level)

3. Disable DRC

In /vendor/etc/audio_policy_configuration.xml, there may be a line containing 'speaker_drc_enabled="true"'. This means that all audio output on your device is deeply compressed. Edit the line to replace "true" with "false" and reboot. Then, the DRC go away.

(Note: Pie GSI roms may have a bug that cannot disable DRC on bluetooth audio output.)

4. Modify kernel tunables by using a kernel adiutor

Change CPU&GPU governors to "performance". Change I/O schedulers to

"deadline" and set their tunables like:

Deadline Scheduler Tunable
fifo_batch:19
front_merge:0
read_expire:4
write_expire:464
writes_starved:0
RQ_Affinity:2
read ahead buffer size:8192kB
NoMerges:2
NrRequests:6144

In the virtual memory section, change the 'Laptop mode' on and swaps

to be disabled like:

swappiness:0
dirty_ratio:50
dirty_background_ratio:25
dirty_expire_centisecs:60000
dirty_writeback_centisecs:11100
laptop_mode:1

In the thermal control section, if there is core control then

set it off. If there is CPU hotplug (MPDecision), set it off too.

5. for MediaTek CPUs

MediaTek is using the EAS+ scheduler that affects CPU governors. To let

really performance mode, edit /vendor/etc/init/hw/init.mt????.rc to replace a line

'write /proc/cpufreq/cpufreq_sched_disable 0' with

'write /proc/cpufreq/cpufreq_sched_disable 1' .

6. Remove effects

In /vendor/etc/audio_effects.xml, remove effects relating to equalizing

(equalizer, reverb, base boost, virtualizer, etc.) and visualizer. This makes Audio Flinger to kill effect chains bound to mixers and reduces jitter on audio outputs. For example,

<?xml version="1.0" encoding="UTF-8"?>
<audio_effects_conf version="2.0" xmlns="http://schemas.android.com/audio/audio_effects_conf/v2_0">
<libraries>
<library name="bundle" path="libbundlewrapper.so"/>
<library name="downmix" path="libdownmix.so"/>
</libraries>
<effects>
<effect name="volume" library="bundle" uuid="119341a0-8469-11df-81f9-0002a5d5c51b"/>
<effect name="downmix" library="downmix" uuid="93f04452-e4fe-41cc-91f9-e475b6d1d69f"/>
</effects>
</audio_effects_conf>

7. Reduce wifi jitters for streaming services and DLNA playback

settings put global wifi_suspend_optimizations_enabled 0

Enjoy it!

Note: these modifications can maximize also 3.5mm Jack, USB DAC and DLNA (or Google cast mirroring) audio quality.