-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructured source codes to be sharable with hifi-maximizer-mod at my another repository.
- Loading branch information
Showing
5 changed files
with
273 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
#!/system/bin/sh | ||
|
||
# Get the active audio policy configuration fille from the audioserever | ||
function getActivePolicyFile() | ||
{ | ||
dumpsys media.audio_policy | awk ' | ||
/^ Config source: / { | ||
print $3 | ||
}' | ||
} | ||
|
||
function stopDRC() | ||
{ | ||
# stopDRC has two args specifying a main audio policy configuration XML file (eg. audio_policy_configuration.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 audio_policy_configuration.xml file to remove DRC | ||
sed -i 's/speaker_drc_enabled[:space:]*=[:space:]*"true"/speaker_drc_enabled="false"/' "$2" | ||
fi | ||
} | ||
|
||
function toHexString() | ||
{ | ||
if [ $# -ge 1 ]; then | ||
local tmp | ||
tmp=`echo -n "$1" | xxd -p | tr -d ' \n'` | ||
if [ $# -eq 2 ]; then | ||
if [ ${#tmp} -ge $2 ]; then | ||
echo -n ${tmp:0:$2} | ||
else | ||
local strt=`expr ${#tmp} + 1` | ||
echo -n "$tmp" | ||
for i in `seq $strt $2` ; do | ||
echo -n "0" | ||
done | ||
fi | ||
else | ||
echo -n "$tmp" | ||
fi | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
# Patch libalsautils.so to map a property string to another | ||
# arg1: original libalsautils.so file; arg2: patched libalsautils.so file; | ||
function patchMapProperty() | ||
{ | ||
local orig_prop='ro.audio.usb.period_us' | ||
local new_prop='vendor.audio.usb.perio' | ||
|
||
if [ $# -eq 2 -a -r "$1" ]; then | ||
local pat1=`toHexString "$orig_prop"` | ||
local pat2=`toHexString "$new_prop" ${#pat1}` | ||
|
||
xxd -p <"$1" | tr -d ' \n' | sed -e "s/$pat1/$pat2/" \ | ||
| awk 'BEGIN { | ||
foldWidth=60 | ||
getline buf | ||
len=length(buf) | ||
for (i=1; i <= len; i+=foldWidth) { | ||
if (i + foldWidth - 1 <= len) | ||
print substr(buf, i, foldWidth) | ||
else | ||
print substr(buf, i, len) | ||
} | ||
exit | ||
}' \ | ||
| xxd -r -p >"$2" | ||
return $? | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
function makeLibraries() | ||
{ | ||
local MAGISKPATH="$(magisk --path)" | ||
local d lname | ||
|
||
for d in "lib" "lib64"; do | ||
for lname in "libalsautils.so" "libalsautilsv2.so"; do | ||
if [ -r "${MAGISKPATH}/.magisk/mirror/vendor/${d}/${lname}" ]; then | ||
mkdir -p "${MODPATH}/system/vendor/${d}" | ||
patchMapProperty "${MAGISKPATH}/.magisk/mirror/vendor/${d}/${lname}" "${MODPATH}/system/vendor/${d}/${lname}" | ||
chmod 644 "${MODPATH}/system/vendor/${d}/${lname}" | ||
chmod -R a+rX "${MODPATH}/system/vendor/${d}" | ||
if [ -z "${REPLACE}" ]; then | ||
REPLACE="/system/vendor/${d}/${lname}" | ||
else | ||
REPLACE="${REPLACE} /system/vendor/${d}/${lname}" | ||
fi | ||
fi | ||
done | ||
done | ||
|
||
} | ||
|
||
# Replace system property values for old Androids and some low performance SoC's | ||
|
||
function loosenedMessage() | ||
{ | ||
local freq="96kHz" | ||
if [ $# -gt 0 ]; then | ||
freq="$1" | ||
fi | ||
|
||
ui_print "" | ||
ui_print "****************************************************************" | ||
ui_print " Loosened the USB jitter level for more than $freq USB outputs! " | ||
ui_print " (\"USB Samplerate Unlocker\" was detected) " | ||
ui_print "****************************************************************" | ||
ui_print "" | ||
} | ||
|
||
function replaceSystemProps_Old() | ||
{ | ||
if [ -e "${MODPATH%/*/*}/modules/usb-samplerate-unlocker" -o -e "${MODPATH%/*/*}/modules_update/usb-samplerate-unlocker" ]; then | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=3875/' \ | ||
"$MODPATH/system.prop" | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=3875/' \ | ||
"$MODPATH/system.prop-workaround" | ||
|
||
loosenedMessage | ||
|
||
else | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=2625/' \ | ||
"$MODPATH/system.prop" | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=2625/' \ | ||
"$MODPATH/system.prop-workaround" | ||
|
||
fi | ||
|
||
sed -i \ | ||
-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\.resampler\.psd\.halflength=.*$/ro\.audio\.resampler\.psd\.halflength=320/' \ | ||
"$MODPATH/system.prop-workaround" | ||
|
||
} | ||
|
||
function replaceSystemProps_S4() | ||
{ | ||
if [ -e "${MODPATH%/*/*}/modules/usb-samplerate-unlocker" -o -e "${MODPATH%/*/*}/modules_update/usb-samplerate-unlocker" ]; then | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=5000/' \ | ||
"$MODPATH/system.prop" | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=5000/' \ | ||
"$MODPATH/system.prop-workaround" | ||
|
||
loosenedMessage | ||
|
||
else | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=3875/' \ | ||
"$MODPATH/system.prop" | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=3875/' \ | ||
"$MODPATH/system.prop-workaround" | ||
|
||
fi | ||
|
||
sed -i \ | ||
-e 's/ro\.audio\.resampler\.psd\.stopband=.*$/ro\.audio\.resampler\.psd\.stopband=194/' \ | ||
-e 's/ro\.audio\.resampler\.psd\.halflength=.*$/ro\.audio\.resampler\.psd\.halflength=520/' \ | ||
-e 's/ro\.audio\.resampler\.psd\.tbwcheat=.*$/ro\.audio\.resampler\.psd\.cutoff_percent=100/' \ | ||
"$MODPATH/system.prop" | ||
sed -i \ | ||
-e 's/ro\.audio\.resampler\.psd\.halflength=.*$/ro\.audio\.resampler\.psd\.halflength=320/' \ | ||
"$MODPATH/system.prop-workaround" | ||
} | ||
|
||
function replaceSystemProps_kona() | ||
{ | ||
if [ ! "`getprop ro.vendor.build.version.release_or_codename`" -ge "12" -a \ | ||
\( -e "${MODPATH%/*/*}/modules/usb-samplerate-unlocker" -o -e "${MODPATH%/*/*}/modules_update/usb-samplerate-unlocker" \) ]; then | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=20375/' \ | ||
"$MODPATH/system.prop" | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=20375/' \ | ||
"$MODPATH/system.prop-workaround" | ||
|
||
loosenedMessage 192kHz | ||
|
||
else | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=2500/' \ | ||
"$MODPATH/system.prop" | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=2500/' \ | ||
"$MODPATH/system.prop-workaround" | ||
|
||
fi | ||
} | ||
|
||
function replaceSystemProps_SDM() | ||
{ | ||
# Do nothing even if "usb-samplerate-unlocker" exists | ||
: | ||
} | ||
|
||
function replaceSystemProps_MTK_Dimensity() | ||
{ | ||
if [ -e "${MODPATH%/*/*}/modules/usb-samplerate-unlocker" -o -e "${MODPATH%/*/*}/modules_update/usb-samplerate-unlocker" ]; then | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=3250/' \ | ||
-e '$avendor.audio.usb.out.period_us=3250\nvendor.audio.usb.out.period_count=2' \ | ||
"$MODPATH/system.prop" | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=3250/' \ | ||
-e '$avendor.audio.usb.out.period_us=3250\nvendor.audio.usb.out.period_count=2' \ | ||
"$MODPATH/system.prop-workaround" | ||
|
||
loosenedMessage | ||
|
||
else | ||
sed -i \ | ||
-e '$avendor.audio.usb.out.period_us=2500\nvendor.audio.usb.out.period_count=2' \ | ||
"$MODPATH/system.prop" | ||
sed -i \ | ||
-e '$avendor.audio.usb.out.period_us=2500\nvendor.audio.usb.out.period_count=2' \ | ||
"$MODPATH/system.prop-workaround" | ||
|
||
fi | ||
|
||
} | ||
|
||
function replaceSystemProps_Others() | ||
{ | ||
if [ -e "${MODPATH%/*/*}/modules/usb-samplerate-unlocker" -o -e "${MODPATH%/*/*}/modules_update/usb-samplerate-unlocker" ]; then | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=3250/' \ | ||
"$MODPATH/system.prop" | ||
sed -i \ | ||
-e 's/vendor\.audio\.usb\.perio=.*$/vendor\.audio\.usb\.perio=3250/' \ | ||
"$MODPATH/system.prop-workaround" | ||
|
||
loosenedMessage | ||
|
||
fi | ||
|
||
} |
Oops, something went wrong.