#!/bin/sh # # mp3tocd # ------- # # Pressing an audio CD from multiple mp3-files. # # Script by Paul Kremer (paulkremer (AT) gmx (DOT) net) # License: BSD artistic # # needs the following tools: # - an mp3 player which can convert to wav (mpg123 or madplay) # - sox (Sound eXchange), for correcting wav-files # - normalize, to adjust the volume of different mp3's # - some gnu-utilities: grep, head, cut and bash # - cdrecord # # # The script assumes you have enough disk-space for at least # one complete audio-cd and that the mp3-files come from # different sources so they are being "tuned" for better # quality. The processing with sox and the normalization should # not be necessary with godd-quality mp3's. # # Speed, system load and cdrecord: I have tested this script on # an old Pentium 100 system with 32 MB RAM, and everything went OK. # #Changelog: # # 0.1 initial release (june 2001) # 0.2 minor feature enhancements (july 2001) # added command-line options, and nice output to console # # Configuration # ------------- # this regexp will match all lines in a playlist which do not contain # filenames (like comment lines) EXCLUDE_REGEXP="^#" CONVERTCOMMAND="madplay --quiet --output" #CONVERTCOMMAND="mpg123 -w" CDBURNCOMMAND="cdrecord -v dev=0,6,0 -eject speed=4 -pad -audio *.wav" # The main code # # VERSION="0.2" function help { echo "$0 version $VERSION License: BSD Author: Paul Kremer" echo "" echo "Usage: `basename $0` [OPTION] -f playlist" echo "" echo "Options:" echo " -b --batch batch-mode for volumes" echo " -m --mix mix-mode for volumes" echo " -h --help displays this message" echo " -f specify a playlist file" echo "" exit 0 } # this function prepares the mp3-files from the playlist # == copies them to the current directory # the parameter for the function is the playlist filename function playlist_prepare () { FNAME="bla" echo " copying mp3 files..." let COUNTER=1 while [ "$FNAME" != "" ] do read FNAME F="`echo -n "$FNAME" | grep -v "$EXCLUDE_REGEXP"`" if [ -f "$F" ]; then echo " ... `basename "$F"`" cp "$F" "./$COUNTER-`basename "$F" | tr ' ' '_'`" let COUNTER=$COUNTER+1 fi done < "${1}" } # converts the mp3 files to wav format function convert_to_wav() { echo " converting to wav..." for i in *.mp3 do echo " ... `basename $i .mp3`" nice $CONVERTCOMMAND `basename $i .mp3`.wav $i rm "$i" done } # sox fixes files with bad frequencies function fix_bad_files() { BADFILES=`file *.wav | grep -v 44100 | cut -f 1 -d ":"` if [ "$BADFILES" != "" ]; then echo " fixing frequencies..." fi while [ "$BADFILES" != "" ] do BADFILE=`file *.wav | grep -v 44100 | cut -f 1 -d ":" | head -n 1` echo " ...$BADFILE adjusting to 44100 Hz" nice sox $BADFILE -r 44100 $BADFILE.new.wav resample if [ "$?" == "0" ]; then mv $BADFILE.new.wav $BADFILE # echo " adjusted rate of $BADFILE to 44100 Hz" fi BADFILES=`file *.wav | grep -v 44100 | cut -f 1 -d ":"` done } # adjust volume level function normalize_wav() { echo " normalizing volume levels, using $NORMA_MODE ..." nice normalize -q $NORMA_MODE *.wav } # burn to cd function burn_to_cd() { echo "" echo " starting CDDA burn process..." echo " ... $CDBURNCOMMAND" } ################## function do_stuff() { echo "Using playlist \"${1}\"" playlist_prepare "${1}" convert_to_wav fix_bad_files normalize_wav burn_to_cd exit 0 } ########### MAIN ################# if [ "${1}" == "-f" ]; then if [ -f "${2}" ]; then NORMA_MODE="-m" do_stuff "${2}" fi fi if [ "${1}" == "-m" ]; then NORMA_MODE="-m" fi if [ "${1}" == "--mix" ]; then NORMA_MODE="-m" fi if [ "${1}" == "-b" ]; then NORMA_MODE="-b" fi if [ "${1}" == "--batch" ]; then NORMA_MODE="-b" fi if [ "${2}" == "-f" ]; then if [ -f "${3}" ]; then do_stuff "${3}" fi fi if [ "a" == "a" ]; then help fi