[Magisk] Rezmir99:
Hi Zackptg5. Thanks for great work on sound mods.

I made some modification to patch_cfg function. It may help to reduce the code size and more compatibility.

patch_cfg() {
#set -x
local opt file lib=false effect=false outsp=false proxy=false libname libpath effname uid libname_sw uid_sw libname_hw uid_hw libpathsw libpathhw libpathproxy conf xml
OPTIND=1; while getopts :leoapr opt; do
case "$opt" in
l) lib=true;;
e) effect=true;;
o) outsp=true; conf=output_session_processing; xml=postprocess;;
r) outsp=true; conf=pre_processing; xml=preprocess;;
p) proxy=true;;
a) lib=true; effect=true; outsp=true; conf=output_session_processing; xml=postprocess;;
\?) printf 'Error: Unknown option "--%s"\n' "$OPTARG" 1>&2; return 1;;
:) printf 'Error: "--%s" requires an argument\n' "$OPTARG" >&2; return 1;;
*) return 1;;
esac
done; shift "$((OPTIND-1))"
file=$1; shift
[ "$OPTIND" -eq 1 ] && { lib=true; effect=true; }
set -e
if $proxy; then
effect=false; outsp=false;
effname=$1; uid=$2; shift 2
$lib && { libpathproxy=$1; shift; }
libname_sw=$1; uid_sw=${2:?}; shift 2
$lib && { libpathsw=$1; shift; }
libname_hw=$1; uid_hw=${2:?}; shift 2
$lib && { libpathhw=${1:?}; shift; }
else
$outsp && { type=${1:?}; shift; }
{ $effect || $outsp; } && { effname=${1:?}; shift; }
$effect && { uid=${1:?}; shift; }
{ $lib || $effect; } && { libname=${1:?}; shift; }
$lib && { libpath=${1:?}; shift; }
fi
set +e
case "$file" in
*.conf)
if $proxy; then
sed -i "/^effects {/,/^}/ {/^ $effname {/,/^ }/d}" "$file"
sed -i "/^effects {/ a\\
$effname {\\
library proxy\\
uuid $uid\\
\\
libsw {\\
library $libname_sw\\
uuid $uid_sw\\
}\\
\\
libhw {\\
library $libname_hw\\
uuid $uid_hw\\
}\\
}" "$file"
if $lib; then
patch_cfg -l "$file" "proxy" "$libpathproxy"
patch_cfg -l "$file" "$libname_sw" "$libpathsw"
patch_cfg -l "$file" "$libname_hw" "$libpathhw"
fi
return
fi
if $lib; then
sed -i "/^libraries {/,/^}/ {/^ $libname {/,/^ }/d}" "$file"
sed -i "/^libraries {/ a\\
$libname {\\
path $(echo "$libpath" | sed 's/[&/\]/\\&/g')\\
}" "$file"
fi
if $effect; then
sed -i "/^effects {/,/^}/ {/^ $effname {/,/^ }/d}" "$file"
sed -i "/^effects {/ a\\
$effname {\\
library $libname\\
uuid $uid\\
}" "$file"
fi
if $outsp && [ "$API" -ge 26 ]; then
[ -z "$(sed -n "/^$conf {/,/^}/p" "$file")" ] && printf "$conf {\n}\n" >> "$file"
[ -z "$(sed -n "/^$conf {/,/^}/ {/^ $type {/,/^ }/p}" "$file")" ] && sed -i "/^$conf {/ a\\
$type {\\
}" "$file"
[ -z "$(sed -n "/^$conf {/,/^}/ {/^ $type {/,/^ }/ {/^ $$effname {/,/^ }/p}}" "$file")" ] &&
sed -i -e "/^$conf {/,/^}/ {/^ $type {/ a\\
$effname \{\\
\}" -e "}" "$file"
fi;;
*)
if $proxy; then
sed -i "/<effects>/,/<\/effects>/ {/^ *<effectProxy name=\"$effname\"/,/^ *<\/effectProxy>/d}" "$file"
sed -i "/<effects>/ a\\
<effectProxy name=\"$effname\" library=\"proxy\" uuid=\"$uid\">\\
<libsw library=\"$libname_sw\" uuid=\"$uid_sw\"\/>\\
<libhw library=\"$libname_hw\" uuid=\"$uid_hw\"\/>\\
<\/effectProxy>" "$file"
if $lib; then
patch_cfg -l "$file" "proxy" "$libpathproxy"
patch_cfg -l "$file" "$libname_sw" "$libpathsw"
patch_cfg -l "$file" "$libname_hw" "$libpathhw"
fi
return
fi
if $lib; then
sed -i "/<libraries>/,/<\/libraries>/ {/^ *<library name=\"$libname\"/d}" "$file"
sed -i "/<libraries>/ a\\
<library name=\"$libname\" path=\"$(basename "$libpath")\"\/>" "$file"
fi
if $effect; then
sed -i "/<effects>/,/<\/effects>/ {/^ *<effect name=\"$effname\"/d}" "$file"
sed -i "/<effects>/ a\\
<effect name=\"$effname\" library=\"$libname\" uuid=\"$uid\"\/>" "$file"
fi
if $outsp && [ "$API" -ge 26 ]; then
[ -z "$(sed -n "/<$xml>/,/<\/$xml>/p" "$file")" ] &&
sed -i "/<\/audio_effects_conf>/ i\\
<$xml>\\
<\/$xml>" "$file"
[ -z "$(sed -n "/<$xml>/,/<\/$xml>/ {/<stream type=\"$type\">/,/<\/stream>/p}" "$file")" ] &&
sed -i "/<$xml>/ a\\
<stream type=\"$type\">\\
<\/stream>" "$file"
[ -z "$(sed -n "/<$xml>/,/<\/$xml>/ {/^ *<stream type=\"$type\">/,/^ *<\/stream>/ {/^ *<apply effect=\"$effname\"\/>/p}}" "$file")" ] &&
sed -i -e "/<$xml>/,/<\/$xml>/ {/<stream type=\"$type\">/ a\\
<apply effect=\"$effname\"\/>" -e "}" "$file"
fi;; esac
}

This makes it easy to patch for proxy effects.For example Dolby Atmos:

for FILE in ${CFGS}; do
if [ "$MODID" = AxAxon7 ]; then
patch_cfg -pl $AMLPATH$FILE dax 9d4921da-8225-4f29-aefa-6e6f69726861 $LIBDIR/libeffectproxy.so dax_sw 6ab06da4-c516-4611-8166-6168726e6f69 $LIBDIR/libswdax.so dax_hw a0c30891-8246-4aef-b8ad-696f6e726861 $LIBDIR/libhwdax.so
else
patch_cfg $AMLPATH$FILE dax 9d4921da-8225-4f29-aefa-6e6f69726861 dax $LIBDIR/libswdax.so
fi
done; unset FILE

Tested with Dolby AxAxon7 & lepro3, Jamesdsp and Viper4android on xml and conf files.