#!/bin/bash
#
# BpmDj: Free Dj Tools
# Copyright (C) 2001 Werner Van Belle
# See 'BeatMixing.ps' for more information
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

songname="$2"
songlocation=$songname
rawname=$1"`basename "$2"`.raw"
extension=${songname##*.}

#echo LOCATION = $songlocation
#echo RAWNAME = $rawname
#echo EXTENSION = $extension

# if the raw filename already exists, don't write it
(test -f "$rawname") && exit 1;

# the song must exist
(! (test -f "$songlocation") ) && songlocation=music/"$songlocation" \
&& (! (test -f "$songlocation") ) && exit 2;

# now check the filename extension
case $extension in 
  (MP3) mpg123 -s "$songlocation" >"$rawname" 2>/dev/null;;
  (mp3) mpg123 -s "$songlocation" >"$rawname" 2>/dev/null;;
  (ogg) ogg123 -q -d raw -f "$rawname" "$songlocation";;
esac;

