This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions2.sh
65 lines (59 loc) · 2.02 KB
/
functions2.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
#!/system/bin/sh
function toHexLE() {
if [ $# -eq 1 -a $1 -gt 0 ]; then
printf "%2.2x%2.2x%2.2x%2.2x" $(( $1 % 256 )) $(( $1 / 256 % 256 )) $(( $1 / 256 / 256 % 256 )) $(( $1 / 256 / 256 / 256 % 256 ))
return 0
else
return 1
fi
}
function toHexLineLE() {
if [ $# -eq 1 ]; then
for i in $1; do
toHexLE $i
done
return 0
else
return 1
fi
}
# Patch libalsautils.so to clear the 96kHz lock of USB audio class drivers
# arg1: original libalsautils.so file; arg2: patched libalsautils.so file;
# optional arg3: "max" (clearing full sample rates), "full" (clearing upto 386kHz) or another (clearing upto 192kHz)
function patchClearLock() {
local orig_rates='96000 88200 192000 176400 48000 44100 32000 24000 22050 16000 12000 11025 8000'
local new_rates='192000 176400 96000 88200 48000 44100 32000 24000 22050 16000 12000 11025 8000'
if [ $# -ge 2 -a -r "$1" ]; then
if [ $# -gt 2 ]; then
case "$3" in
"max" )
new_rates='768000 705600 384000 352800 192000 176400 96000 88200 48000 44100 24000 16000 8000'
;;
"full" )
new_rates='384000 352800 192000 176400 96000 88200 48000 44100 32000 24000 16000 12000 8000'
;;
* )
;;
esac
fi
local pat1=`toHexLineLE "$orig_rates"`
local pat2=`toHexLineLE "$new_rates"`
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
}