Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Set an audio scheduling tunable "vendor.audio.adm.buffering.ms" "2" to reduce jitter on all audio outputs.
Adjusted a USB period to reduce jitter on the USB audio output.
  • Loading branch information
yzyhk904 authored Jun 1, 2022
1 parent f39b26f commit 97022bf
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ This module,
<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>adjusts a USB transfer period for directly reducing the jitter of a PLL in a DAC (even in an asynchronous mode),</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),</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>
</ol><br/>
for improving audio quality effectively in a simple manner.
<br/>
Expand All @@ -17,7 +18,7 @@ This module,

* 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 a 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 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.
* 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 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.

* Please 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 change "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 Disable "Digital Wellbeing" (system app; if it exists) itself or change "Battery usage" from "Optimized" to "Unrestricted" (this is very harmful for audio like camera servers).

Expand Down Expand Up @@ -54,4 +55,7 @@ This module,
# v1.0
* Initial Release

# v1.1
* Set new properties related to an audio scheduling

##
22 changes: 12 additions & 10 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

# Replace system property values for old Androids and some low performance SoC's

function replaceSystemProps()
function replaceSystemProps_Old()
{
sed -i \
-e 's/ro\.audio\.usb\.period_us=.*$/ro\.audio\.usb\.period_us=5375/' \
-e 's/ro\.audio\.usb\.period_us=.*$/ro\.audio\.usb\.period_us=3875/' \
-e 's/ro\.audio\.resampler\.psd\.enable_at_samplerate=.*$/ro\.audio\.resampler\.psd\.enable_at_samplerate=48000/' \
-e 's/ro\.audio\.resampler\.psd\.stopband=.*$/ro\.audio\.resampler\.psd\.stopband=167/' \
-e 's/ro\.audio\.resampler\.psd\.halflength=.*$/ro\.audio\.resampler\.psd\.halflength=368/' \
-e 's/ro\.audio\.resampler\.psd\.tbwcheat=.*$/ro\.audio\.resampler\.psd\.tbwcheat=106/' \
"$MODPATH/system.prop"
sed -i \
-e 's/ro\.audio\.usb\.period_us=.*$/ro\.audio\.usb\.period_us=5375/' \
-e 's/ro\.audio\.usb\.period_us=.*$/ro\.audio\.usb\.period_us=3875/' \
-e 's/ro\.audio\.resampler\.psd\.halflength=.*$/ro\.audio\.resampler\.psd\.halflength=320/' \
"$MODPATH/system.prop-workaround"
}
Expand All @@ -27,13 +27,13 @@ function replaceSystemProps_Kona()
"$MODPATH/system.prop-workaround"
}

function replaceSystemProps_MT68()
function replaceSystemProps_MTK_some()
{
sed -i \
-e 's/ro\.audio\.usb\.period_us=.*$/ro\.audio\.usb\.period_us=1125/' \
-e 's/ro\.audio\.usb\.period_us=.*$/ro\.audio\.usb\.period_us=875/' \
"$MODPATH/system.prop"
sed -i \
-e 's/ro\.audio\.usb\.period_us=.*$/ro\.audio\.usb\.period_us=1125/' \
-e 's/ro\.audio\.usb\.period_us=.*$/ro\.audio\.usb\.period_us=875/' \
"$MODPATH/system.prop-workaround"
}

Expand All @@ -43,14 +43,16 @@ if "$IS64BIT"; then
replaceSystemProps_Kona
;;
mt68* )
replaceSystemProps_MT68
if [ "`getprop ro.vendor.build.version.release`" -ge "11" ]; then
replaceSystemProps_MTK_some
fi
;;
mt67[56]? )
replaceSystemProps
mt67[56]* )
replaceSystemProps_Old
;;
esac
else
replaceSystemProps
replaceSystemProps_Old
fi

# AudioFlinger's resampler has a bug on an Android OS of which version is less than 12.
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.0.9
versionCode=1009
version=v1.1.0
versionCode=1100
author=zyhk
description=Setting audio misc. configuration values (e.g. 100 volume steps, raising the resampling quality, disabling the effects framework, etc.)
20 changes: 18 additions & 2 deletions service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,29 @@ function additionalSettings()
return 1
fi

if [ "`getprop init.svc.audioserver`" = "running" ]; then
if [ -n "`getprop init.svc.audioserver`" ]; then
setprop ctl.restart audioserver
sleep 1.2
if [ "`getprop init.svc.audioserver`" != "running" ]; then
# workaround for Android 12 old devices hanging up the audioserver after "setprop ctl.restart audioserver" is executed
local pid="`getprop init.svc_debug_pid.audioserver`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>&2
fi
fi
fi

elif [ "`getprop ro.system.build.version.release`" -ge "12" ]; then
if [ "`getprop init.svc.audioserver`" = "running" ]; then
if [ -n "`getprop init.svc.audioserver`" ]; then
setprop ctl.restart audioserver
sleep 1.2
if [ "`getprop init.svc.audioserver`" != "running" ]; then
# workaround for Android 12 old devices hanging up the audioserver after "setprop ctl.restart audioserver" is executed
local pid="`getprop init.svc_debug_pid.audioserver`"
if [ -n "$pid" ]; then
kill -HUP $pid 1>"/dev/null" 2>&1
fi
fi
fi

fi
Expand Down
6 changes: 5 additions & 1 deletion system.prop
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
ro.config.media_vol_steps=100
audio.safemedia.bypass=true
ro.audio.ignore_effects=true
ro.audio.usb.period_us=4000
ro.audio.usb.period_us=3375
audio.adm.buffering.ms=2
vendor.audio.adm.buffering.ms=2
audio_hal.period_multiplier=2
vendor.audio_hal.period_multiplier=2
persist.bluetooth.sbc_hd_higher_bitrate=1
af.resampler.quality=7
ro.audio.resampler.psd.enable_at_samplerate=44100
Expand Down
6 changes: 5 additions & 1 deletion system.prop-workaround
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
ro.config.media_vol_steps=100
audio.safemedia.bypass=true
ro.audio.ignore_effects=true
ro.audio.usb.period_us=4000
ro.audio.usb.period_us=3375
audio.adm.buffering.ms=2
vendor.audio.adm.buffering.ms=2
audio_hal.period_multiplier=2
vendor.audio_hal.period_multiplier=2
persist.bluetooth.sbc_hd_higher_bitrate=1
af.resampler.quality=7
ro.audio.resampler.psd.enable_at_samplerate=44100
Expand Down

0 comments on commit 97022bf

Please sign in to comment.