Skip to content

Commit 49c7170

Browse files
authored
Add files via upload
* Changed head ahead buffer sizes from 16960 kB to 17000 kB to reduce I/O jitter * Adjusted NrRequests of I/O scheduling * Changed dirty_ratio and dirty_background_ration to be 100 to reduce jitter * Adjusted re-sampling parameters for old devices * Changed adjustSoC_mq for A14 and later clover not to round I/O parameters * Adjusted cfq I/O parameters for SDM69x devices * Changed the way how to get the actual audio policy file path in the service phase because some ROM's fail to execute "dumpsys" in the phase
1 parent 3be6ea4 commit 49c7170

File tree

8 files changed

+222
-154
lines changed

8 files changed

+222
-154
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ For maximizing the audio fidelity, this module reduces less than 50 Hz (longer t
9292
| External examples: | - | - | - | - |
9393
| 100 | 29 | (91) | 109 | AK4493 (Sharp roll-off N-fold over-sampling) |
9494
| 150 | 42 | (91) | 109 | AK4191EQ (Sharp roll-off N-fold over-sampling) |
95-
| 120 | 35 | (97) | 110 | ESS 9038PRO (Fast roll-off N-fold over-sampling) |
96-
| 50 ~ 118 | 34 | 96 | (398) | ESS 9039PRO (Fast roll-off N-fold over-sampling) |
95+
| 120 | 35 | (97) | 110 | ES9038PRO (Fast roll-off N-fold over-sampling) |
96+
| vary 50 ~ 118 | 34 | 96 | (398) | ES9039PRO (Fast roll-off N-fold over-sampling) |
9797
| 110 | 40 | (96) | 109 | CX43131 (Fast roll-off N-fold over-sampling) |
9898
| 98 | 130 | 98.5 | | MacOS Leopard (guess) |
9999
| 159 | 240 | | 99 | iZotope, No-Alias (guess) |

changelog.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
## Change logs
22

3-
# v2.5.8
4-
* Changed adjustSoC_mq for A14 and later clover not to round I/O parameters
5-
* Adjusted cfq I/O parameters for SDM69x devices
6-
73
# v2.5.7
84
* Changed head ahead buffer sizes from 16960 kB to 17000 kB to reduce I/O jitter
95
* Adjusted NrRequests of I/O scheduling
106
* Changed dirty_ratio and dirty_background_ration to be 100 to reduce jitter
117
* Adjusted re-sampling parameters for old devices
8+
* Changed adjustSoC_mq for A14 and later clover not to round I/O parameters
9+
* Adjusted cfq I/O parameters for SDM69x devices
10+
* Changed the way how to get the actual audio policy file path in the service phase because some ROM's fail to execute "dumpsys" in the phase
1211

1312
#v2.5.6
1413
* Added "compatible Magisk-mirroring" message for incompatible Magisk variants

customize.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ case "$configXML" in
113113
chown root:root "$modConfigXML"
114114
chmod -R a+rX "${modConfigXML%/*}"
115115
REPLACE="/system${configXML} $REPLACE"
116+
117+
# If "${configXML}" isn't symbolically linked to "$/system/{configXML}",
118+
# disable Magisk's "magic mount" and mount "${configXML}" by this module itself in "service.sh"
119+
if [ ! -e "/system${configXML}" ]; then
120+
touch "$MODPATH/skip_mount"
121+
fi
116122
fi
117123
;;
118124
* )

jitter-reducer-functions.shlib

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function searchDefaultCpuGovernor()
2020
local gov=""
2121
local i
2222
for i in `cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors`; do
23-
if [ "$i" = "sched_pixel" -o "$i" = "schedutil" ]; then
23+
if [ "$i" = "walt" -o "$i" = "sched_pixel" -o "$i" = "schedutil" ]; then
2424
gov="$i"
2525
break;
2626
elif [ ! "$gov" = "schedplus" ]; then
@@ -506,6 +506,24 @@ function isMtkGpuFreqFixed()
506506
fi
507507
}
508508

509+
function validGpuGovernor()
510+
{
511+
if [ $# -eq 2 -a -r "$1" ]; then
512+
local lst
513+
local gov="$2"
514+
local i
515+
lst="`cat <\"$1\"`"
516+
for i in $lst; do
517+
if [ "$i" = "$gov" ]; then
518+
return 0
519+
fi
520+
done
521+
return 1
522+
else
523+
return 1
524+
fi
525+
}
526+
509527
function reduceGovernorJitter()
510528
{
511529
if [ $# -eq 2 ]; then
@@ -553,8 +571,11 @@ function reduceGovernorJitter()
553571
fi
554572
elif [ -w "/sys/class/kgsl/kgsl-3d0/devfreq/governor" ]; then
555573
# For Qcomm GPU's
556-
echo 'performance' >"/sys/class/kgsl/kgsl-3d0/devfreq/governor"
557-
sleep 0.1
574+
if validGpuGovernor "/sys/class/kgsl/kgsl-3d0/devfreq/available_governors" "performance"; then
575+
# Check whether "performance" governor exists or not because some Qcomm recent GPU's don't have the governor
576+
echo 'performance' >"/sys/class/kgsl/kgsl-3d0/devfreq/governor"
577+
sleep 0.1
578+
fi
558579
if [ -w "/sys/class/kgsl/kgsl-3d0/min_pwrlevel" ]; then
559580
# Set the min power level to be maximum
560581
read x <"/sys/class/kgsl/kgsl-3d0/min_pwrlevel"
@@ -563,15 +584,17 @@ function reduceGovernorJitter()
563584
fi
564585
fi
565586
# For some Qcomm GPU's, because they revert the governor after setting min_pwrlevel several times
566-
for i in `seq 1 9`; do
567-
x="`echo \"scale=1;${i}/10\" | bc`"
568-
sleep $x
569-
read x <"/sys/class/kgsl/kgsl-3d0/devfreq/governor"
570-
if [ "$x" = "performance" ]; then
571-
break
572-
fi
573-
echo 'performance' >"/sys/class/kgsl/kgsl-3d0/devfreq/governor"
574-
done
587+
if validGpuGovernor "/sys/class/kgsl/kgsl-3d0/devfreq/available_governors" "performance"; then
588+
for i in `seq 1 9`; do
589+
x="`echo \"scale=1;${i}/10\" | bc`"
590+
sleep $x
591+
read x <"/sys/class/kgsl/kgsl-3d0/devfreq/governor"
592+
if [ "$x" = "performance" ]; then
593+
break
594+
fi
595+
echo 'performance' >"/sys/class/kgsl/kgsl-3d0/devfreq/governor"
596+
done
597+
fi
575598
elif [ -w "/proc/gpufreq/gpufreq_opp_freq" ]; then
576599
# Maximum fixed frequency setting for MediaTek GPU's
577600
local freq="`getMtkGpuFreqKhz \"max\"`"
@@ -1095,10 +1118,10 @@ function adjustForSoC_mq()
10951118
;;
10961119
* )
10971120
if [ "`getprop ro.build.product`" = "clover" -a "`getprop ro.build.version.release`" -eq "13" ]; then
1098-
# Round off (<5) and up (>=5); for Nyx and SouthWest kernels of only A13
1099-
echo "`expr '(' '(' $1 + 5 ')' / 10 ')' '*' 10`"
1100-
elif [ "`getprop ro.build.product`" = "clover" -a "`getprop ro.build.version.release`" -ge "14" ]; then
1101-
# Not Round for A14 and later
1121+
# Round off (<7) and up (>=7); for Nyx and SouthWest kernels of only A13
1122+
echo "`expr '(' '(' $1 + 3 ')' / 10 ')' '*' 10`"
1123+
elif [ "`getprop ro.build.product`" = "clover" -a "`getprop ro.build.version.release`" -ge "14" ]; then
1124+
# Not Round for A14 and later (1000Hz kernels)
11021125
echo "$1"
11031126
else
11041127
adjustForSoC "$1"
@@ -1233,7 +1256,7 @@ function getSchedulerValues()
12331256
echo "94 0 36 516 0"
12341257
;;
12351258
sdm* | msm* | sd* | exynos* )
1236-
echo "95 0 34 516 0"
1259+
echo "97 0 36 515 0"
12371260
;;
12381261
mt68* )
12391262
echo "96 0 36 516 0"
@@ -1608,9 +1631,14 @@ function reduceIoJitter()
16081631
sleep 0.05
16091632
fi
16101633

1634+
local kerVersion="`uname -r`"
1635+
kerVersion=${kerVersion%%.*}
16111636
if [ "`getprop ro.build.product`" = "jfltexx" ] && validScheduler "/sys/block/$i/queue/scheduler" "deadline"; then
16121637
echo 'deadline' >"/sys/block/$i/queue/scheduler"
16131638
sleep 0.05
1639+
elif [ "$kerVersion" -ge 6 ] && validScheduler "/sys/block/$i/queue/scheduler" "mq-deadline"; then
1640+
echo 'mq-deadline' >"/sys/block/$i/queue/scheduler"
1641+
sleep 0.05
16141642
elif validScheduler "/sys/block/$i/queue/scheduler" "cfq"; then
16151643
echo 'cfq' >"/sys/block/$i/queue/scheduler"
16161644
sleep 0.05

module.prop

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
id=hifi-maximizer-mod
22
name=Hifi Maximizer
3-
version=v2.5.6
4-
versionCode=2506
3+
version=v2.5.7
4+
versionCode=2507
55
author=zyhk
66
description=A module for maximizing the digital audio fidelity by reducing jitters on audio outputs (USB DACs, Bluetooth a2dp, DLNA, etc.)

service-functions.sh

Lines changed: 52 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,74 @@
11
#!/system/bin/sh
22

3-
# MODDIR=${0%/*} will be nherited from the parent sh module
4-
5-
# This script functions will be used in services mode
6-
7-
. "$MODDIR/jitter-reducer-functions.shlib"
8-
9-
function disableAdaptiveFeatures()
10-
{
11-
# Reducing jitter by battery draining and charging manager, and 5G data manager
12-
settings put global adaptive_battery_management_enabled 0
13-
settings put secure adaptive_charging_enabled 0
14-
settings put secure adaptive_connectivity_enabled 0
15-
# Reducing wifi jitter by suspend wifi optimizations
16-
settings put global wifi_suspend_optimizations_enabled 0
17-
}
18-
19-
function setVolumeMediaSteps()
3+
function reloadAudioServer()
204
{
21-
# Volume medial steps to be 100 if a volume steps facility is used
22-
settings put system volume_steps_music 100
23-
}
24-
25-
function forceIgnoreAudioEffects()
26-
{
27-
local force_restart_server=0
28-
29-
if [ "`getprop persist.sys.phh.disable_audio_effects`" = "0" ]; then
30-
# Workaround for recent Pixel Firmwares (not to reboot when resetprop'ing)
31-
resetprop --delete ro.audio.ignore_effects 1>"/dev/null" 2>&1
32-
# End of workaround
33-
resetprop ro.audio.ignore_effects true
34-
force_restart_server=1
35-
fi
36-
37-
# Stop Tensor device's AOC daemon for reducing significant jitter
38-
if [ "`getprop init.svc.aocd`" = "running" ]; then
39-
setprop ctl.stop aocd
40-
force_restart_server=1
41-
fi
42-
43-
# Nullifying the volume listener for no compressing audio (maybe a peak limiter)
44-
if [ "`getprop persist.sys.phh.disable_soundvolume_effect`" = "0" ]; then
45-
if [ -r "/system/phh/empty" -a -r "/vendor/lib/soundfx/libvolumelistener.so" ]; then
46-
mount -o bind "/system/phh/empty" "/vendor/lib/soundfx/libvolumelistener.so"
47-
force_restart_server=1
48-
fi
49-
if [ -r "/system/phh/empty" -a -r "/vendor/lib64/soundfx/libvolumelistener.so" ]; then
50-
mount -o bind "/system/phh/empty" "/vendor/lib64/soundfx/libvolumelistener.so"
51-
force_restart_server=1
52-
fi
53-
54-
elif [ "`getprop persist.sys.phh.disable_soundvolume_effect`" != "1" ]; then
55-
# for non- phh GSI's (Qcomm devices only?)
56-
if [ -r "/vendor/lib/soundfx/libvolumelistener.so" ]; then
57-
mount -o bind "/dev/null" "/vendor/lib/soundfx/libvolumelistener.so"
58-
force_restart_server=1
5+
if [ -n "`getprop init.svc.audioserver`" ]; then
6+
setprop ctl.restart audioserver
7+
sleep 1.2
8+
if [ "`getprop init.svc.audioserver`" != "running" ]; then
9+
# workaround for Android 12 old devices hanging up the audioserver after "setprop ctl.restart audioserver" is executed
10+
local pid="`getprop init.svc_debug_pid.audioserver`"
11+
if [ -n "$pid" ]; then
12+
kill -HUP $pid 1>"/dev/null" 2>&1
13+
fi
5914
fi
60-
if [ -r "/vendor/lib64/soundfx/libvolumelistener.so" ]; then
61-
mount -o bind "/dev/null" "/vendor/lib64/soundfx/libvolumelistener.so"
62-
force_restart_server=1
63-
fi
64-
65-
fi
66-
67-
if [ "$force_restart_server" = "1" -o "`getprop ro.system.build.version.release`" -ge "12" ]; then
68-
reloadAudioServer
6915
fi
7016
}
7117

72-
# This function has six arguments:
73-
# 1. Enable $1:thermal core control, $2:Camera service (interfering in jitters on audio outputs), $3:Selinux enforcing, $4:Doze (battery optimizations)
74-
# and $5:Logd service or not, respectively ("yes" or "no")
75-
# 2. Disable $6:clearest tone ("yes" or "no"), perhaps for sensitive Bluetooth earphones.
76-
77-
function optimizeOS()
78-
{
79-
if [ $# -neq 6 ]; then
80-
exit 1
81-
fi
82-
18+
# Sleep some secs needed for Audioserver's preparation
19+
function waitAudioServer()
20+
{
8321
# wait for system boot completion and audiosever boot up
22+
sleep 11
8423
local i
85-
for i in `seq 1 30` ; do
24+
for i in `seq 1 10` ; do
8625
if [ "`getprop sys.boot_completed`" = "1" -a -n "`getprop init.svc.audioserver`" ]; then
8726
break
8827
fi
89-
sleep 0.9
28+
sleep $i
9029
done
91-
92-
if [ "$1" = "no" ]; then
93-
reduceThermalJitter 1 0
94-
fi
95-
if [ "$2" = "no" ]; then
96-
reduceCameraJitter 1 0
97-
fi
98-
if [ "$3" = "no" ]; then
99-
reduceSelinuxJitter 1 0
100-
fi
101-
if [ "$4" = "no" ]; then
102-
reduceDozeJitter 1 0
103-
fi
104-
if [ "$5" = "no" ]; then
105-
reduceLogdJitter 1 0
106-
fi
107-
reduceGovernorJitter 1 0
108-
if [ "$6" = "no" ]; then
109-
reduceIoJitter 1 '*' 'boost' 0
110-
else
111-
reduceIoJitter 1 '*' 'medium' 0
112-
fi
113-
reduceVmJitter 1 0
114-
forceIgnoreAudioEffects
115-
disableAdaptiveFeatures
116-
setVolumeMediaSteps
11730
}
11831

119-
# Get the active audio policy configuration fille from the audioserever
120-
121-
function getActivePolicyFile()
32+
# A rewritten version because some ROM's fail to execute "dumpsys media.audio_policy" on the service phase
33+
# arg1 : Magisk's module folder path, typically "/data/adb/modules/<module name>"
34+
function remountFiles()
12235
{
123-
dumpsys media.audio_policy | awk '
124-
/^ Config source: / {
125-
print $3
126-
}'
127-
}
128-
129-
function remountFile()
130-
{
131-
local configXML
36+
local modPath flist x deletePat forceReload=0
37+
38+
if [ $# -eq 1 -a -e "$1" ]; then
39+
modPath="$1"
40+
else
41+
return
42+
fi
13243

133-
# Set the active configuration file name retrieved from the audio policy server
134-
configXML="`getActivePolicyFile`"
44+
deletePat=$(echo "${modPath}/system" | sed -e 's/\//\\\//g')
45+
46+
# Get absolute paths for Magisk's magic mount, then remount by itself
47+
flist="`find \"${modPath}/system\" -type f | sed -e \"s/$deletePat//\"`"
13548

136-
# Check if the audio policy XML file mounted by Magisk is still unmounted.
49+
# Check if the audio policy XML file and others mounted by Magisk is still unmounted.
13750
# Some Qcomm devices from Xiaomi, OnePlus, etc. overlays another on it in a boot process
138-
# and phh GSI on Qcomm devices unmount it
139-
140-
if [ -r "$configXML" -a -r "${MODDIR}/system${configXML}" ]; then
141-
cmp "$configXML" "${MODDIR}/system${configXML}" >"/dev/null" 2>&1
142-
if [ "$?" -ne 0 ]; then
143-
umount "$configXML" >"/dev/null" 2>&1
144-
umount "$configXML" >"/dev/null" 2>&1
145-
mount -o bind "${MODDIR}/system${configXML}" "$configXML"
146-
reloadAudioServer
51+
# and phh GSI's on Qcomm devices unmount it for the phh settings of the GSI's.
52+
53+
for x in $flist; do
54+
if [ -e "${modPath}/skip_mount" -a "${x##*/}" = ".replace" ]; then
55+
# Mount a directory instead of ".replace" file if skipping Magisk's magic mount
56+
mount -o bind "${modPath}/system${x%/.replace}" "${x%/.replace}"
57+
forceReload=1
58+
elif [ -r "$x" -a -r "${modPath}/system${x}" ]; then
59+
cmp "$x" "${modPath}/system${x}" >"/dev/null" 2>&1
60+
if [ "$?" -ne 0 ]; then
61+
umount "$x" >"/dev/null" 2>&1
62+
umount "$x" >"/dev/null" 2>&1
63+
mount -o bind "${modPath}/system${x}" "$x"
64+
forceReload=1
65+
fi
14766
fi
67+
done
68+
69+
if [ "$forceReload" -gt 0 ]; then
70+
# Since this library file may be shared multiple modules, it is needed to disperse the timing of each module not to collide
71+
sleep $(expr $RANDOM % 20)
72+
reloadAudioServer
14873
fi
14974
}

0 commit comments

Comments
 (0)