#!/bin/sh
### mp32cdr - decode a MP3 to cdr format (bigendian signed 16bit words)
### Copyright (C) 1999  Arne Zellentin <arne@unix-ag.org>

### 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

### see http://www.home.unix-ag.org/arne/scripToys/ for details.

# usage: mp32cdr [-s] <file1,> <...,> <filen>

if [ "$1" = "-s" ] ; then
  swab=1
  shift
else
  swab=0
fi
for i in "$@" ; do
  name=`basename "$i" .mp3`.cdr
  if [ $swab = 1 ] ; then
    # 2 x swap doen't much but waste CPU-time, but data is padded as well
    mpg123 -s "$i" | swapbyteorder | swapbyteorder | dd ibs=2352 obs=8192 > "$name"
  else
    mpg123 -s "$i" | swapbyteorder | dd ibs=2352 obs=8192 > "$name"
  fi
done


#mpg123 -s "$i" | sox -t .raw -c 2 -r 44100 -sw  - -x "`basename $i .mp3`".cdr
