-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw2sw
executable file
·103 lines (64 loc) · 1.73 KB
/
sw2sw
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
#!/bin/bash
reoder(){ echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}"; }
numtooff(){
echo -n "00000000$(printf '%x' "$1")" | tail -c 8
}
num2(){
echo -n "00000000$(printf '%x' "$1")" | tail -c 2 | tr '[:lower:]' '[:upper:]'
}
4bb(){
echo $((0x$(reoder "$(head -c $1 "$file" | tail -c 4 | xxd -p)")))
}
swar2swav(){
file="$1"
out="$2"
samplecount=$(4bb 60)
echo $samplecount
for i in $(seq 1 $samplecount)
do
if [ $i != $samplecount ]
then
tmp=$(4bb $((60+((i+1)*4))))
else
tmp=$(wc -c <"$file")
fi
tmp2=$(4bb $((60+(i*4))))
echo $tmp $((tmp-tmp2))
echo "53574156 fffe0001 $(reoder $(numtooff $(((tmp-tmp2)+24)))) 10000100 44415441 $(reoder $(numtooff $(((tmp-tmp2)+8))))" | xxd -r -p >"$out/$(num2 $((i-1))).swav"
cat "$file" | head -c $tmp | tail -c $((tmp-tmp2)) >> "$out/$(num2 $((i-1))).swav"
done
}
# swar2swav "$1" "$2"
swav2swar(){
dir="$(realpath "$1")"
out="$2"
samplecount="$(ls -1 "$dir" | wc -l)"
headersize="$((60+(samplecount*4)))"
echo "$1" "$2"
echo $samplecount $headersize
add=
buf=$headersize
buff=
for i in $(seq 0 $(($samplecount-1)))
do
size=$(($(wc -c <"$dir/$(num2 $i).swav")-24))
buff="$buff"" $(reoder $(numtooff $buf))"
buf="$((buf+size))"
add=$((add+$size))
done
filesize=$(((add+$headersize)))
bottonsize=$(((add+($headersize-16))))
echo "53574152 fffe0001 $(reoder $(numtooff $filesize)) 10000100 44415441 $(reoder $(numtooff $bottonsize)) 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 $(reoder $(numtooff $samplecount))$buff" | xxd -r -p >"$out"
for i in $(seq 0 $(($samplecount-1)))
do
# echo $(num2 $i)
size=$(($(wc -c <"$dir/$(num2 $i).swav")-24))
tail -c $size "$dir/$(num2 $i).swav" >>"$out"
done
}
# if [ "$1" = "-u" ]
# then
# swar2swav "$2" "$3"
# else
# swav2swar "$1" "$2"
# fi