-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path.aml.sh
executable file
·118 lines (115 loc) · 7.86 KB
/
.aml.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/system/bin/sh
alias xmlstarlet="$mod/tools/xmlstarlet"
alias sed="$mod/tools/sed"
patch_xml() {
local NAME=$(echo "$3" | sed -r "s|^.*/.*\[@.*=\"(.*)\".*$|\1|")
local NAMEC=$(echo "$3" | sed -r "s|^.*/.*\[@(.*)=\".*\".*$|\1|")
local VAL=$(echo "$4" | sed "s|.*=||")
[ "$(echo $4 | grep '=')" ] && local VALC=$(echo "$4" | sed "s|=.*||") || local VALC="value"
case "$1" in
"-d") xmlstarlet ed -L -d "$3" $2;;
"-u") xmlstarlet ed -L -u "$3/@$VALC" -v "$VAL" $2;;
"-s") if [ "$(xmlstarlet sel -t -m "$3" -c . $2)" ]; then
xmlstarlet ed -L -u "$3/@$VALC" -v "$VAL" $2
else
local SNP=$(echo "$3" | sed "s|\[.*$||")
local NP=$(dirname "$SNP")
local SN=$(basename "$SNP")
xmlstarlet ed -L -s "$NP" -t elem -n "$SN-ainur_narsil" -i "$SNP-ainur_narsil" -t attr -n "$NAMEC" -v "$NAME" -i "$SNP-ainur_narsil" -t attr -n "$VALC" -v "$VAL" -r "$SNP-ainur_narsil" -v "$SN" $2
fi;;
esac
}
process_effects() {
case $1 in
*.conf) local REMLIBS="$(sed -n "/^libraries {/,/^}/ {/^ *path / {s|.*/\(.*.so\)|\1|g;p}}" $1)"
local LIBRS="$(sed -n "/^libraries {/,/^}/ {/^libraries {/d;/^ *#/d;/^ *.*{/{s/^ *//;s/ {.*//;p}}" $1)"
for i in ${KEEPLIBS}; do
REMLIBS="$(echo $REMLIBS | sed "s| *$i.so *| |")"
local TMP=$(sed -n "/^libraries {/,/^}/ {/^ *path .*\/$i.so/=}" $1)
TMP=$((TMP-1))
[ "$TMP" == "-1" ] && continue
TMP="$(sed -n "$TMP p" $1 | sed -e "s|^ *||" -e "s| {||")"
LIBRS="$(echo $LIBRS | sed "s| *$TMP *| |")"
done
for i in ${LIBRS}; do
local SP="$(sed -n "/^libraries {/,/^}/ {/^ *$i/p}" $1 | sed -r "s/( *).*/\1/")"
sed -i "/^libraries {/,/^}/ {/^$SP$i {/,/^$SP}/d}" $1
sed -n "/^effects {/,/^}/p" $1 | while read j; do
case $j in
"#"*) ;;
*" {")
[ "$(sed -n "/^effects {/,/^}/ {/$SP$j/{p; :loop n; p; /^$SP}/q; b loop}}" $1 | sed -n "/library $i/p")" ] && {
local LN=$(sed -n "/^effects {/,/^}/ {/^$SP$j/=}" $1)
local TMP="$(sed -n "/^effects {/,/^}/ {/^$SP$j/{:loop n; /^$SP}/=; b loop}}" $1)"
TMP="$(echo $TMP | sed -r "s/^([0-9]*).*/\1/")"
[ "$LN" ] && sed -i "$LN,$TMP d" $1; }
;;
esac
done
done
;;
*.xml) local REMLIBS="$(sed -n "/<libraries>/,/<\/libraries>/p" $1 | grep "path=" | awk '{gsub("path=\"|\"/>","",$3); print $3}')"
local LIBRS="$(sed -n "/<libraries>/,/<\/libraries>/p" $1 | grep "name=" | awk '{gsub("name=\"|\"","",$2); print $2}')"
for i in ${KEEPLIBS}; do
REMLIBS="$(echo $REMLIBS | sed "s| *[^ ]*$i.so *| |")"
local TMP="$(sed -n "/<libraries>/,/<\/libraries>/ {/path=\"$i.so/ {s|.* name=\"\(.*\)\" .*|\1|g;p}}" $1)"
[ -z "$TMP" ] || LIBRS="$(echo $LIBRS | sed "s| *[^ ]*$TMP *| |")"
done
for i in ${LIBRS}; do
sed -i "/<libraries>/,/<\/libraries>/ {\|^ *.*name=\"$i\" path.*|d}" $1
local TMP="$(sed -n "/<effects>/,/<\/effects>/{s/ *//;s/$/~/;p}" $1 | grep "library=\"$i\" uuid")"
local OIFS=$IFS IFS='~'
for j in $TMP; do
local IFS=$OIFS
j="$(echo $j | sed "s|~$||")"
local LN=$(sed -n "\|$j|=" $1)
case "$j" in
"<!--"*|*"-->") ;;
"<effectProxy"*"library=\"$i"*) local LN2=$((LN+1)); sed -i "$LN,$LN2 d" $1;;
"<libsw library=\"$i"*) local LN=$((LN-1)) LN2="$((LN+2))"; sed -i "$LN,$LN2 d" $1;;
"<libhw library=\"$i"*) local LN=$((LN-2)) LN2="$((LN+1))"; sed -i "$LN,$LN2 d" $1;;
"<effect"*"library=\"$i"*) sed -i "$LN d" $1;;
esac
local IFS='~'
done
local IFS=$OIFS
done
;;
esac
}
FILES=$(find $MODPATH/system -type f)
for FILE in $FILES; do
OFILE="$amldir/ainur_narsil$(echo $FILE | sed "s|^$MODPATH||")"
case $FILE in
*audio_policy.conf) if $AP; then
for AUD in "direct_pcm" "direct" "raw" "multichannel" "compress_offload" "high_res_audio"; do
[ "$AUD" != "compress_offload" ] && sed -i "/$AUD {/,/}/ s/^\( *\)formats.*/\1formats AUDIO_FORMAT_PCM_8_24_BIT/g" $FILE
[ "$AUD" == "direct_pcm" -o "$AUD" == "direct" -o "$AUD" == "raw" ] && sed -i "/$AUD {/,/}/ s/^\( *\)flags.*/\1flags AUDIO_OUTPUT_FLAG_DIRECT\|AUDIO_OUTPUT_FLAG_DIRECT_PCM/g" $FILE
sed -i "/$AUD {/,/}/ s/^\( *\)sampling_rates.*/\1sampling_rates 8000\|11025\|16000\|22050\|32000\|44100\|48000\|64000\|88200\|96000\|176400\|192000\|352800\|384000/g" $FILE
done
fi;;
*audio_output_policy.conf) if $OAP; then
for AUD in "default" "direct" "proaudio" "direct_pcm" "direct_pcm_24" "raw" "compress_offload_16" "compress_offload_24" "compress_offload_HD"; do
[[ "$AUD" != "compress_offload"* ]] && sed -i "/$AUD {/,/}/ s/^\( *\)formats.*/\1formats AUDIO_FORMAT_PCM_16_BIT\|AUDIO_FORMAT_PCM_24_BIT_PACKED\|AUDIO_FORMAT_PCM_8_24_BIT\|AUDIO_FORMAT_PCM_32_BIT/g" $FILE
if [ "$AUD" == "direct" ]; then
if [ "$(grep "compress_offload" $FILE)" ]; then
sed -i "/$AUD {/,/}/ s/^\( *\)flags.*/\1flags AUDIO_OUTPUT_FLAG_DIRECT\|AUDIO_OUTPUT_FLAG_DIRECT_PCM\|AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD\|AUDIO_OUTPUT_FLAG_NON_BLOCKING/g" $FILE
else
sed -i "/$AUD {/,/}/ s/^\( *\)flags.*/\1flags AUDIO_OUTPUT_FLAG_DIRECT\|AUDIO_OUTPUT_FLAG_DIRECT_PCM/g" $FILE
fi
fi
sed -i "/$AUD {/,/}/ s/^\( *\)sampling_rates.*/\1sampling_rates 44100\|48000\|96000\|176400\|192000\|352800\|384000/g" $FILE
[ -z "$BIT" ] || sed -i "/$AUD {/,/}/ s/^\( *\)bit_width.*/\1bit_width $BIT/g" $FILE
done
fi;;
*audio_policy_configuration.xml) if $AP; then
sed -i "/<module name=\"primary\"/,/<\/module>/ {/<mixPort name=\"primary output\"/,/<\/mixPort>/ {s/format=\"[^\"]*\(.*\)/format=\"AUDIO_FORMAT_PCM_8_24_BIT\|AUDIO_FORMAT_PCM_16_BIT\1/; s/samplingRates=\"[^\"]*\(.*\)/samplingRates=\"48000,96000,192000\1/}}" $FILE
sed -i "/<module name=\"primary\"/,/<\/module>/ {/<mixPort name=\"raw\"/,/<\/mixPort>/ {s/format=\"[^\"]*\(.*\)/format=\"AUDIO_FORMAT_PCM_8_24_BIT\1/}}" $FILE
sed -i "/<module name=\"primary\"/,/<\/module>/ {/<mixPort name=\"deep_buffer\"/,/<\/mixPort>/ {s/format=\"[^\"]*\(.*\)/format=\"AUDIO_FORMAT_PCM_8_24_BIT\1/; s/samplingRates=\"[^\"]*\(.*\)/samplingRates=\"192000\1/}}" $FILE
sed -i "/<module name=\"primary\"/,/<\/module>/ {/<mixPort name=\"multichannel\"/,/<\/mixPort>/ {s/format=\"[^\"]*\(.*\)/format=\"AUDIO_FORMAT_PCM_8_24_BIT\1/; s/samplingRates=\"[^\"]*\(.*\)/samplingRates=\"44100,48000,64000,88200,96000,128000,176400,192000\1/}}" $FILE
sed -i "/<module name=\"primary\"/,/<\/module>/ {/<mixPort name=\"direct_pcm\"/,/<\/mixPort>/ {s/format=\"[^\"]*\(.*\)/format=\"AUDIO_FORMAT_PCM_8_24_BIT\1/; s/samplingRates=\"[^\"]*\(.*\)/samplingRates=\"44100,48000,64000,88200,96000,128000,176400,192000\1/; s/channelMasks=\"[^\"]*\(.*\)/channelMasks=\"AUDIO_CHANNEL_OUT_PENTA\|AUDIO_CHANNEL_OUT_5POINT1\|AUDIO_CHANNEL_OUT_6POINT1\|AUDIO_CHANNEL_OUT_7POINT1\1/}}" $FILE
sed -i "/<module name=\"primary\"/,/<\/module>/ {/<mixPort name=\"compress_offload\"/,/<\/mixPort>/ {s/channelMasks=\"[^\"]*\(.*\)/channelMasks=\"AUDIO_CHANNEL_OUT_PENTA\|AUDIO_CHANNEL_OUT_5POINT1\|AUDIO_CHANNEL_OUT_6POINT1\|AUDIO_CHANNEL_OUT_7POINT1\1/}}" $FILE
fi;;
*audio_effects*) process_effects $FILE;;
esac
done