-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalyze-file
executable file
·74 lines (58 loc) · 1.68 KB
/
analyze-file
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
# this shell script is sourced
#
# returns the format, bitrate and samplerate of a file
# returns error 1 when the file is does not exist
#
analyze_file() {
FILE="$1"
# set soxi filter labels
SOXISE="Sample Encoding: "
SOXISR="Sample Rate : "
SOXIBD="Precision : "
if [ -f "${FILE}" ]; then
FILENAME=$(basename "${FILE}")
# call soxi one time per file
FILEINFO=$(LANG=C soxi "${FILE}")
FILESR=$(echo -e "${FILEINFO}" | grep "${SOXISR}" | sed "s#${SOXISR}##")
FILEBD=$(echo -e "${FILEINFO}" | grep "${SOXIBD}" | sed "s#${SOXIBD}\(.*\)-bit#\1#")
FILETYPE=$(echo -e "$FILEINFO" | grep "${SOXISE}" | sed "s#${SOXISE}${FILEBD}-bit \(.*\)#\1#")
case "$FILETYPE" in
"FLAC")
;;
*)
die "Error: $FILE has an unknown filetype";;
esac
get_samplerate "$FILESR"
get_bitdepth "$FILEBD"
echo " \`$FILENAME': $FILETYPE, $FILESR Hz, $FILEBD bit"
return 0
else
die "Error: no such file $FILE"
fi
}
get_samplerate(){
# returns 0 when valid source has valid sample rate:
# '44100', 88200' or '176400'
# '48000', '96000' or '192000'
# dies when source has unknown sample rate
VALIDRATES="'44100', '88200', '176400', '48000', '96000' or '192000'"
case "$1" in
44100|88200|176400|48000|96000|192000)
return 0 ;;
*)
die "Error: Invalid samplerate ($1) specified, use any of:\n" \
" $VALIDRATES"
esac
}
get_bitdepth(){
# returns 0 when bitdepth is valid
# dies when source file has unknown bit depth
VALIDDEPTHS="'16', '18', '22' or '24'"
case $1 in
16|18|20|24)
return 0 ;;
*)
die "Error: Invalid target bitdepth ($1 bits) specified, use any of:\n" \
" $VALIDDEPTHS"
esac
}