Add create_sid_mp3.sh
authorColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Mon, 28 Jan 2013 23:16:56 +0000 (15:16 -0800)
committerColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Mon, 28 Jan 2013 23:16:56 +0000 (15:16 -0800)
Signed-off-by: Colin McCabe <cmccabe@alumni.cmu.edu>

create_sid_mp3.sh [new file with mode: 0755]

diff --git a/create_sid_mp3.sh b/create_sid_mp3.sh
new file mode 100755 (executable)
index 0000000..93cf8cc
--- /dev/null
@@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+
+die() {
+    echo $@
+    exit 1
+}
+
+usage() {
+    cat <<EOF
+create_sid_mp3: creates mp3 out of sid files
+
+-h               This help message
+-i [infile]      Set input SID
+-o [outdir]      Set output directory
+EOF
+}
+
+input=""
+outdir=""
+while getopts  "hi:o:" flag; do
+    case $flag in
+    i)  input=$OPTARG;;
+    o)  outdir=$OPTARG;;
+    h)  usage; exit 0;;
+    *)  usage; exit 1;;
+    esac
+done
+shift $((OPTIND-1))
+[ "${input}" == "" ] && die "you must supply a sid file to convert with -i"
+[ -f "${input}" ] || die "can't find ${input} (or is not file)"
+[ "${outdir}" == "" ] && die "you must supply an outdir direcctory with -o"
+[ -d "${outdir}" ] || die "can't find directory ${outdir} (or is not dir)"
+base="`basename "$input"`"
+wav="${outdir}/$base.wav"
+sidplayer "${input}" --outfile "${wav}" --time 300
+mp3="${outdir}/$base.mp3"
+lame -q 2 -b 123 "$wav" "$mp3" || die "lame failed"
+rm -f "${wav}"