Repository navigation
Expand file tree
/
Copy pathmugeco.sh
More file actions
137 lines (116 loc) · 3.74 KB
/
Copy pathmugeco.sh
File metadata and controls
137 lines (116 loc) · 3.74 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/sh
progname=mugeco version=0.1
programr='Alexander Leidinger'
progdate='7 Dec 2000'
progdesc='MUltiGEnerationCOding'
# NEEDS: getopt, lame
# Please have a look at the DEFAULTS section.
# $Id: mugeco.sh,v 1.6 2000/12/08 13:47:56 aleidinger Exp $
usage() {
cat << EOF
** $progname v$version, $progdate **
by $programr
$progdesc
usage: $progname [ <flags> ] -g <num> <file>
-v use builtin VBR options
-g <num> number of generations
-h help
used
- env vars:
* LAME : alternative encoder binary
* LAMEOPT: alternative encoder options
- VBR opts: $enc_vbr_opts
- CBR opts: $enc_cbr_opts
EOF
}
# DEFAULTS
# if you can, use getopt(1) (c)1997 by Frodo Looijaard <frodol@dds.nl>
# it's in most modern unixen, or look at http://huizen.dds.nl/~frodol/
: ${GETOPT=getopt} # helper program
# mktemp (optional) is also in most modern unixen (originally from OpenBSD)
: ${MKTEMP=mktemp} # helper program
: ${TMPDIR:=/tmp} # set default temp directory
: ${LAME:=lame} # path to LAME
enc_cbr_opts="-b192 -h --lowpass 18 --lowpass-width 0"
enc_vbr_opts="--vbr-mtrh --nspsytune -v -h -d -Y -X3"
enc_opts=${LAMEOPT:-$enc_cbr_opts}
num= # default number of generations
# DEFINE FUNCTIONS
e() { echo "$progname: $*"; }
die() { # usage: die [ <exitcode> [ <errormessage> ] ]
trap '' 1 2 3 13 15
exitcode=0
[ $# -gt 0 ] && { exitcode=$1; shift; }
[ $# -gt 0 ] && e "Error: $*" >&2
exit $exitcode
}
# tfile()
# this function creates temporary files. 'tfile temp' will make a tempfile
# and put the path to it in the variable $temp (defaults to variable $tf)
trap 'for f in $ztfiles; do rm -f "$f"; done' 0
trap 'trap "" 1 2 3 13 15; exit 10' 1 2 3 13 15
unset ztfiles
tfile() { # usage: tfile <variable_name>
ztf=`$MKTEMP -q $TMPDIR/$progname.XXXXXX 2>/dev/null` # try mktemp
if [ $? -gt 0 -o -z "$ztf" ]; then # if mktemp fails, do it unsafely
ztf=$TMPDIR/$LOGNAME.$progname.$$
[ -e "$ztf" ] && ztf= || { touch $ztf && chmod 600 $ztf; }
fi
[ "$ztf" -a -f "$ztf" ] || { echo Could not make tempfile; exit 8; }
ztfiles="$ztfiles $ztf"
eval ${1:-tf}='$ztf'
}
# PARSE COMMAND LINE
options="g:vh" # option string for getopt(1)
help=; [ "$1" = -h -o "$1" = -help -o "$1" = --help ] && help=yes
[ "$help" ] && { usage; die; }
$GETOPT -T >/dev/null 2>&1
[ $? -eq 4 ] && GETOPT="$GETOPT -n $progname -s sh" #frodol's getopt?
eval set -- `$GETOPT "$options" "$@"`
[ $# -lt 1 ] && { die 9 getopt failed; }
while [ $# -gt 0 ]; do
case "$1" in
-g) num=$2; shift ;;
-v) enc_opts=$enc_cbr_opts ;;
-h) help=y ;;
--) shift; break ;;
*) usage; die 9 "invalid command line syntax!" ;;
esac
shift
done
[ "$help" ] && { usage; die; }
[ $# -eq 0 ] && { usage; die 9 no arguments; } #change or remove if desired
# sanity checking
[ "$num" ] && echo "$num"|grep -q '^[0-9]*$' && [ $num -ge 1 ] \
|| die 1 please use the -g flag with a valid number
# MAIN PROGRAM
# what version of lame are we using?
lame_vers=`$LAME 2>&1 | awk 'NR==1{print $3}'`
# check filename
[ -f "$1" ] || die 2 "'$1' isn't a file"
echo "$1"|grep -qi '\.wav$' || die 2 "'$1' isn't a .wav"
# make tempfiles
base=`echo "$1"|sed 's/\.[^.]*$//'`
dest=${base}_generation_$num.wav
[ -e "$dest" ] && die 2 "'$dest' already exists"
touch "$dest" || die 2 "couldn't create '$dest'"
TMPDIR=. tfile tmpwav
TMPDIR=. tfile tmpmp3
cp -f "$1" "$tmpwav"
# do the loop
start=`date`
i=1
while [ $i -le $num ]; do
e "Working on file '$1', generation number $i..."
$LAME $enc_opts --tc "lame $lame_vers; Generation: $i" \
"$tmpwav" "$tmpmp3" || die 3 encoding failed
$LAME --decode --mp3input "$tmpmp3" "$tmpwav" || die 3 decoding failed
i=`expr $i + 1`
done
end=`date`
# save the result
ln -f "$tmpwav" "$dest"
echo
e "Start: $start"
e "Stop : $end"
die