Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Added support for Tensor devices to bypass their spatial audio feature for reducing jitter distortion.
  • Loading branch information
yzyhk904 authored Mar 8, 2023
1 parent 108dc85 commit 89056ae
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This module,
<li>changes the number of steps in media volume to 100 steps (0.4~0.7dB per step),</li>
<li>raises the resampling quality of the Android OS mixer (AudioFlinger) to a very mastering quality (i.e., no resampling distortion in a real sense),</li>
<li>disables the effects framework of the mixer (to interface to equalizers, virtualizers, visualizers, echo cancelers, automatic gain controls, etc.) for obtaining a nearly direct low jitter audio pass,</li>
<li>disables the android built-in spatial audio feature (A13 or higher; especially Tensor devices) for obtaining a nearly direct low jitter audio pass too,</li>
<li>adjusts a USB transfer period of the USB HAL driver (not the recently common hardware offloading USB (tunneling) driver) for directly reducing the jitter of a PLL in a DAC (even in an asynchronous mode); Use <a href="https://github.com/yzyhk904/USB_SampleRate_Changer">"USB_SampleRate_Changer"</a> to switch from the usual hardware offloading USB (tunneling) driver to the USB HAL one,</li>
<li>sets 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),</li>
<li>sets an audio scheduling tunable "vendor.audio.adm.buffering.ms" "2" to reduce jitter on all audio outputs,</li>
Expand All @@ -17,7 +18,7 @@ This module,

* 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 1: This module raises the resampling quality from 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 for Android 12 and later devices and 160db & 91% & 480 for Android 9 & 10 & 11 ones (except low performance ones), but 167dB & 106% & 368 for low performance Android 12 and later devices, 160dB & 91% & 320 for low performance Android 9 & 10 & 11 ones; because earlier than Android 12 has a bug relating to aliasing processing around the Nyquist frequency). However, this cannot raise the quality for Android 8.1 and earlier ones. Please keep in mind that those attenuation values are used for a resampler design as targeted ones and may not be accomplished in the AOSP implementation.
* Note 1: This module raises the resampling quality from 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 for Android 12 and later devices and 160db & 91% & 480 for Android 9 & 10 & 11 ones (except low performance ones), but 167dB & 106% & 368 (194dB & 100% & 520 exceptionally for Galaxy S4) for low performance Android 12 and later devices, 160dB & 91% & 320 for low performance Android 9 & 10 & 11 ones; because earlier than Android 12 has a bug relating to aliasing processing around the Nyquist frequency). However, this cannot raise the quality for Android 8.1 and earlier ones. Please keep in mind that those attenuation values are used for a resampler design as targeted ones and may not be accomplished in the AOSP implementation.

* Note 2: 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 the 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.

Expand All @@ -38,6 +39,7 @@ This module,
| 160 | 480 | 91 | | High Performance under A12 |
| 167 | 368 | | 106 | Low Performance A12 |
| 179 | 408 | | 99 | High Performance A12 |
| 194 | 520 | 100 | | Galaxy S4 (USB: 44.1kHz 32bit fixed) |
| External examples: | - | - | - | - |
| 100 | 29 | | 109 | AK4493 (Sharp Roll-Off for N-fold over-sampling) |
| 120 | 35 | | 110 | ESS 9038PRO (Sharp Roll-Off for N-fold over-sampling) |
Expand Down
43 changes: 43 additions & 0 deletions customize-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,46 @@ function replaceSystemProps_Others()
fi

}

function stopSpatializer()
{
# stopSpatializer has two args specifying an audio policy configuration XML file (eg. bluetooth_audio_policy_configuration_7_0.xml)
# and its dummy one to be overridden

if [ $# -eq 2 -a -r "$1" -a -w "$2" ]; then
# Copy and override an original audio_policy_configuration.xml to its dummy file
cp -f "$1" "$2"
# Change an audio_policy_configuration.xml file to remove Spatializer
sed -i 's/flags[:space:]*=[:space:]*"AUDIO_OUTPUT_FLAG_SPATIALIZER"//' "$2"
fi
}

function deSpatializeAudioPolicyConfig()
{
if [ $# -ne 1 -o -z "$1" -o ! -r "$1" ]; then
return 1
fi
local MAGISKPATH="$(magisk --path)"
local configXML="$1"

# Don't use "$MAGISKPATH/.magisk/mirror/system${configXML}" instead of "$MAGISKPATH/.magisk/mirror${configXML}".
# In some cases, the former may link to overlaied "${configXML}" by Magisk itself (not original mirrored "${configXML}").
local mirrorConfigXML="$MAGISKPATH/.magisk/mirror${configXML}"

if [ -n "$configXML" -a -r "$mirrorConfigXML" ]; then
grep -e "flags[[:space:]]*=[[:space:]]*\"AUDIO_OUTPUT_FLAG_SPATIALIZER\"" "$mirrorConfigXML" >"/dev/null" 2>&1
if [ "$?" -eq 0 ]; then
local modConfigXML="$MODPATH/system${configXML}"
mkdir -p "${modConfigXML%/*}"
touch "$modConfigXML"
stopSpatializer "$mirrorConfigXML" "$modConfigXML"
chmod 644 "$modConfigXML"
chmod -R a+rX "$MODPATH/system/vendor/etc"
if [ -z "$REPLACE" ]; then
REPLACE="/system${configXML}"
else
REPLACE="$REPLACE /system${configXML}"
fi
fi
fi
}
1 change: 1 addition & 0 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

REPLACE=""
makeLibraries
deSpatializeAudioPolicyConfig "/vendor/etc/bluetooth_audio_policy_configuration_7_0.xml"

if "$IS64BIT"; then
board="`getprop ro.board.platform`"
Expand Down
4 changes: 2 additions & 2 deletions module.prop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id=audio-misc-settings
name=Audio misc. settings
version=v1.2.3
versionCode=1203
version=v1.2.4
versionCode=1204
author=zyhk
description=Setting audio misc. configuration values (e.g. 100 volume steps, raising the resampling quality, disabling the effects framework, etc.)
1 change: 1 addition & 0 deletions system.prop
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ro.config.media_vol_steps=100
audio.safemedia.bypass=true
ro.audio.ignore_effects=true
ro.audio.spatializer_enabled=false
vendor.audio.usb.perio=2500
vendor.audio.usb.out.period_us=2500
vendor.audio.usb.out.period_count=2
Expand Down
1 change: 1 addition & 0 deletions system.prop-workaround
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ro.config.media_vol_steps=100
audio.safemedia.bypass=true
ro.audio.ignore_effects=true
ro.audio.spatializer_enabled=false
vendor.audio.usb.perio=2500
vendor.audio.usb.out.period_us=2500
vendor.audio.usb.out.period_count=2
Expand Down

0 comments on commit 89056ae

Please sign in to comment.