Skip to content

A Magisk module for maximizing the digital audio fidelity by reducing jitters on audio outputs (USB DACs, Bluetooth a2dp, DLNA, etc.)

License

Notifications You must be signed in to change notification settings

TeaqariaWTF/hifi-maximizer-mod

Repository files navigation

A Magisk module for maximizing the digital audio fidelity by reducing jitters on audio outputs (USB DACs, Bluetooth a2dp, DLNA, etc.)

This module reduces jitters on audio outputs by optimizing kenel tunables (CPU & GPU governors, thermal control, CPU hotplug, I/O scheduler, Virtual memory), Selinux mode, WIFI parameters, etc. as follows,

  • For Reducing Jitters:
    1. CPU & GPU governor
      change their governors to "performance" (additionally fixed at the max frequency).
    2. I/O scheduler
      scheduler preference: "deadline" ("cfq" if "deadline" doesn't exist); optimize its tunables.
    3. Virtual memory
      change "swappiness" to 0%, "laptop mode" to 1, etc.
    4. Thermal Control
      disable Qcomm "core control" and stop thermal servers (e.g., "thermald", "thermal-engine", "thermal", "mi_thermald", etc.).
    5. CPU hotplug
      stop "MPDecision" server (if exists).
    6. Disable MediaTek EAS+ scheduler
      `echo '1' > "/proc/cpufreq/cpufreq_sched_disable"`
    7. Doze
      stop the Android doze server.
    8. Selinux mode
      change the mode to "permissive".
    9. Adaptive battery saving features
      disable wifi suspend optimizations, the adaptive battery management, the adaptive charging management and the adaptive connectivity management.
    10. Kill effect chains
      force ignoring `/vendor/etc/audio_effects.xml` to disable equalizers, virtualizers, reverb's, visualizer, echo cancelers, automatic gain controls, etc. (very few vulnerable equalizers may crash by this killing, but please ignore it)
    11. Disable the android built-in spatial audio feature (A13 or higher; especially Tensor devices)
      bypass an otiose audio pass.
    12. Disable aocd service
      disable "aocd server" generating significant jitter on audio outputs, esp. on USB.
    13. Disable pre-installed Moto Dolby and Digital Wellbeing features
      hide their apps (no modifications); please manually uninstall Digital Wellbeing app if remaining as a usual app.
    14. Disable Logd service
      disable "logd server", "traced server" and "traced_probes server" interfering jitter on audio outputs.
    15. Disable camera service
      disable "camera server" interfering jitter on audio outputs.

  • For Convenience and Audio Quality:
    1. Disable DRC (Dynamic Range Control, i.e., a kind of compression)
      modify `/vendor/etc/*/audio_policy_configuration*.xml` to disable DRC if DRC has been enabled on a stock firmware.
    2. Volume steps
      change the number of steps in media volume to 100 steps (0.4~0.7dB per step).
    3. Resampling quality
      change AudioFlinger's resampling quality from the AOSP standard one (stop band attenuation 90dB & cut off 100% of the Nyquist frequency & half filter length 32) to a very mastering quality (179dB & 99% & 408, 167dB & 106% & 368 or 160db & 91% & 480 (or 320 for low performance devices), i.e., no resampling distortion in a real sense even though the 160dB targeted attenuation is not accomplished in the AOSP implementation).
    4. Adjust a USB transfer period of the USB HAL driver (not the hardware offload USB driver)
      for directly reducing the jitter of a PLL in a DAC (even in an asynchronous mode); Use "USB_SampleRate_Changer" to switch from the usual hardware offload USB driver to the USB HAL one.
    5. Set a higher bitrate limit of bluetooth codec SBC (dual channel mode)
      for EDR 2Mbps entry class earphones (not for EDR 3Mbps performance ones, but including AV amplifiers and BT speakers).
    6. Set an audio scheduling tunable "vendor.audio.adm.buffering.ms" "2"
      to reduce jitter on all audio outputs.
    7. Nullify volume listener libraries in "soundfx" folders for disabling slight compression (maybe a peak limiter only on Qcomm devices).



  • Don't forget to install "Audio jitter silencer" together and uninstall "Digital Wellbeing" app (for reducing very large jitters which this module cannot reduce as itself)!

  • This module has been tested on LineageOS and ArrowOS ROM's, and phh GSI's (Android 10 ~ 13, Qualcomm & MediaTek SoC, and Arm32 & Arm64 combinations).

  • Note: Entry class USB DAC's usually adopt an interface chip communicating with the adaptive mode or the synchronous one defined in the USB audio standard. As in these modes an Android host controller sends audio sampling rate clock signals to the DAC, jitter generated at the host side affects the audio quality of the DAC tremendously. Higher class DAC's communicate with the asynchronous mode (also defined in the standard) to a host controller, but they actually use a PLL to reduce jitter from the host not to stutter even in heavy jitter situations. As this result, they behave as the adaptive mode with a feedback loop to dynamically adjust the host side sampling clock signals while referring a DAC side clock in a real sense, so even with asynchronous mode they are more or less affected by host side jitter. You can see the mode of your USB DAC by opening "/proc/asound/card1/stream0" on your phone while playing music. Please see a word in parentheses at "Endpoint:" lines; "SYNC", "ADAPTIVE" or "ASYNC" means that your DAC uses "synchronous", "adaptive" or "asynchronous" mode to communicate to your phone, respectively. Moreover, almost all audio peripherals, e.g., bluetooth earphones, internal DAC's, network audio devices have a PLL in themselves and are affected by host side jitter for the same reason.

  • I recommend expert users not to install "Audio jitter silencer", but manually to disable "Manage apps automatically" in "Battery manager" (or "Adaptive battery" of "Adaptive preferences") in the battery section (needless to say, don't enable battery savers, performance limiters and the like), turn off "Adaptive connectivity" in the Network & internet section (if exists), and changing "Battery optimization" from "Optimize" to "Don't optimize" (or change "Battery usage" from "Optimized" to "Unrestricted") for following app's manually through the settings UI of Android OS (to lower less than 10Hz jitter making extremely short reverb or foggy sound like distortion) even though disabling the Android doze itself: music (streaming) player apps, their licensing apps (if exist), "AirMusic" (if exists), "AirMusic Recording Service" (system app; if exists), equalizer apps (if exist), "Bluetooth" (system app), "Bluetooth MIDI Service" (system app), "MTP Host" (system app), "NFC Service" (system app; if exists), "sManager" or the like (if exists), "Magisk" (if exists), System WebView apps (system app), Browser apps, "PhhTrebleApp" (system app; if exists), "Android Services Library" (system app), "Android Shared Library" (system app), "Android System" (system app), "System UI" (system app), "Input Devices" (system app), {Gesture, 3 Button, 2 Button} Navigation Bar apps (which you are using only; system app), "crDroid System" (system app; if exists), "LineageOS System" (system app; if exists), launcher app, "Google Play Store" (system app), "Google Play services" (system app), "Styles & wallpaper" or the like (system app), {Lineage, crDroid, Arrow, etc.} themes app (system app; if exists), "AOSP panel" (system app; if exists), "OmniJaws" (system app; if exists), "OmniStyle" (system app; if exists), "Active Edge Service" (system app; if exists), "Android Device Security Module" (system app; if exists), "Call Management" (system app; if exists), "Phone" (system app; if exists), "Phone Calls" (system app; if exists), "Phone Services" (system app; if exists), "Phone and Messaging Storage" (system app; if exists), "Storage Manager" (system app), "Default" (system app; if exists), "Default StatusBar" (system app; if exists), "Wfd Service" (system app; if exists), "Wallpaper" or the like (system app), "Adreno Graphics Drivers" (system app; if exists), "com.android.providers.media" (system app), "Files by Google" (system app; if exists), "Google Play Services for AR" (system app; if exists), "Google Services Framework" (system app), "Waterfall cutout" (system app), "Network Manager" (system app), "Companion Device Manager" (system app), "Intent Filter Verification Service" (system app), "Calendar", camera apps, keyboard app, kernel adiutors (if exist), etc. And uninstall "Digital Wellbeing" (system app; if it exists) itself or change "Battery usage" from "Optimized" to "Restricted" (this is very harmful for audio like camera servers). Because "Audio jitter silencer" isn't complete and needs some maintenance after its installation.

  • See also my companion script "USB_SampleRate_Changer" to change the sample rate of the USB (HAL) audio class driver and a 3.5mm jack on the fly like Bluetooth LDAC or Windows mixer to enjoy high resolution sound or to reduce resampling distortion (actually pre-echo, ringing and intermodulation) ultimately.

  • Tips: If you use "AirMusic" to transmit audio data, I recommend setting around 4589 msec additional delay to reduce jitter distortion on the AirMusic panel to display target device(s).

  • Note1: Please remember that this module will stop the thermal control (including CPU core controls, CPU hotplugs and thermal services), the "logd server" and the "camera server" (interfering jitter on audio outputs), disable SELinux enforcing mode and doze (battery saver while idling) on your device. If you like to disable these features, modify variables in "service.sh", respectively.

  • Note2: If you prefer (too sensitive?) Bluetooth earphones to wired headphones and DLNA renderers, set "DisableClearestTone" variable to be "yes" in "service.sh".


DISCLAIMER

  • I am not responsible for any damage that may occur to your device, so it is your own choice to attempt this module.

About

A Magisk module for maximizing the digital audio fidelity by reducing jitters on audio outputs (USB DACs, Bluetooth a2dp, DLNA, etc.)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%