#!/bin/bash

LAME=`which lame`
BS2B=`which bs2bconvert`

LAMEDECODEOPT="--decode"
LAMEENCODEOPT="--preset medium --tc bs2b"
BS2BOPT="-6"

TW=tmpfile.wav
TWB=tmpfile-bs2b.wav

DC="$LAME $LAMEDECODEOPT"
EC="$LAME $LAMEENCODEOPT"
BC="$BS2B $BS2BOPT"

if [ -e $TW ]; then
	rm $TW
fi
if [ -e $TWB ]; then
	rm $TWB
fi
if [ -e *-!bs2b.mp3 ]; then
	rm *-!bs2b.mp3
fi

for i in `ls -1 *.mp3`; do
	$DC $i $TW && \
	$BC $TW $TWB && \
	$EC $TW "$i~nf-!bs2b.mp3" && \
	rm $TW $TWB
done
