Click to See Complete Forum and Search --> : Little tutorial about audio in Linux for newbie


Davno
05-11-2008, 10:56 AM
Part -1-

This is a little help file about audio ripping, converting, encoding. ect.... I refer to it often and i tought that it would be useful to others. These are the type files i use and more documentation can be found in there respective man pages.
Most programs and scripts are available on the net (google) or see this post for some of the scripts.
I did not write these scripts except that i modified some. Before using some of these programs you should already know how to install scripts and programs from source.
Some of this stuff is pretty basic but i have seen a lot of questions about audio with linux on many forum to see that there is a need for a newbie HowTo:

AUDIO RIPPING, CONVERTING, ENCODING, ect...

PART -1- (part 2 will be in the next post due to forum limitations)


.cda to .mp3
.cda to .wav
.wav to .mp3 with lame or gogo (petit)
.wav to .flac
.wav to .ogg
.wav to .ape
.ape to .mp3
.ape to .mp3 if .cue present
.ape to .wav
.flac to .mp3
.flac to .mp3 if .cue present
.flac to .ogg
.flac to .wav
.m4a to .wav
.m4a to .mp3
Joining .mp3
Joining .flac


Utilies used in this tutorial:

mpgtx
flac
lame
mplayer
k3b
grip
cdparanoia
petit (gogo)
oggenc
Monkey Audio Library
shntool
mp3splt
mp3wrap
mpg123
k3bmonkeyaudioplugin

________________________________

.cda to .mp3

Use Grip. (lame must be installed)

or if you prefer the command line with cdparanoia (see .cda to .wav) followed with mlame see (.wav to .mp3).

To convert an entire album into one big .mp3 file you can use K3b (lame must be installed).

.cda to .wav

Grip again will do well with the rip only button.

or if you prefer the command line with cdparanoia:
First change directory to where the .wav files will be created.
exemple:
cd /home/userxxx/temp
Options:
cdparanoia -B (for the whole cd)
cdparanoia 4 (for the track # 4 only)
see man paranoia for all options.

Or with a script:
Since i like to automate every thing, i made a simple script for this.
Scripts are really neet for these task, this one will create a link (NeWRiP) to the desktop for the files that will be created in your /home/userxxx/NeWRiP/ and will run cdparanoia. (Just put in a cd and type cdrip).

You will need to modified this script with your username in it.

cdrip script:
#!/bin/bash
# cdrip
# cdparanoia script (.cda to .wav)
# Will create a directory if it does not exist.
# Will create a link to the desktop if it does not exist.
# Will cd to proper directory to execute cdparanoia.

[ -d /home/UserName/NeWRiP ] || mkdir /home/UserName/NeWRiP

[ -L /home/UserName/Desktop/NeWRiP ] || ln -s /home/UserName/NeWRiP /home/UserName/Desktop

cd /home/YourUserName/NeWRiP

cdparanoia -B
.wav to .mp3 (One track a the time)

Using Lame (lossy)
Lame will encode at 192kps with this option.
lame -b 192 /home/PathToTheMusicFiles/song01.wav /home/PathToTheMusicFiles/song01.mp3
see:
lame --help
lame --longhelp

.wav to .mp3 using Gogo (renamed Petit is a encoder based on lame 3.9x, Google for petit313.tgz)
(it encode at least twice as fast as lame)

Usage:

gogo -b 192 /home/PathToTheMusicFiles/song01.wav /home/PathToTheMusicFiles/song01.mp3 .wav to .mp3 (script for multiple tracks at once)
(lame must be installed for wav2mp3 to work)

Usage:
cd /path/to/directory/with/wav files
Then use the wav2mp3 script:
#!/bin/bash
#
# wav2mp3
# This will convert all the files in the directory
# cd /path/to/directory/with/wav files
# Then run this script

for i in *.wav; do
#out=$(ls $i | sed -e 's/.wav//g')
#out=$(echo $i | sed -e 's/.wav$//')
#lame -h -b 192 "$i" "$out.mp3"
lame -h -b 192 "$i" "${i%.wav}.mp3"
done
.wav to .mp3 (another script for multiple tracks at once)
(lame must be installed for mlame to work)
I modified mlame script to encode at 192kps by default.

Usage:
mlame /home/PathToTheMusicFile/*.wav* /home/PathToTheMusicFile/.mp3
mlame script:
#!/bin/bash
#!/usr/local/bin/bash
################################################## ##########################
#
# Run the LAME encoder on multiple files, with option to delete .wav files
# after encoding. "mlame -h" will give instructions.
#
# Robert Hegemann <Robert.Hegemann@gmx.de>
#
# 1 - Make it executable:
# chmod -775 mlame
#
# 2 - Put to use from command line:
# ./mlame -o "-v -V 0 -b 128" *.wav *.mp3
# WARNING: if option -r the original .wav becomes .mp3
################################################## ##########################
mp3coder="lame"
options="-h -d -m j -b 192"
rmsrc=false

helptext="\
\nThis script runs the LAME mp3 encoder on multiple files: \n\n\
$0 [options] <file 1> ... <file n>\n\
\n\
options:\n\
-h this help text\n\
-r remove files after encoding\n\
-o \"<lame options>\" overrides script default options \"${options}\"\n\
\n\
example:\n\
$0 -r -o \"-v -V 0 -b 112\" a*.wav z*.aif\n\
\n\
"

# process command-line options
# this could be extended to fake the
# commandline interface of the mp3encoder

while getopts ":r" optn; do
case $optn in
o ) options=$OPTARG # replace default options
;;
r ) rmsrc=true
;;
\? ) printf "$helptext"
exit 1
;;
esac
done
shift $(($OPTIND - 1))

# process input-files

for filename in "$@"; do
case $filename in
*[*?]* ) # means shell couldnīt extend *.wav, etc.
echo "warning: no $filename file(s) found"
;;
*[.][wW][aA][vV] )
name=${filename%[.][wW][aA][vV]}
if $mp3coder $options "$filename" "${name}.mp3"
then
if [ $rmsrc = true ]; then
rm -f "$filename"
fi
fi
;;
*[.][aA][iI][fF] )
name=${filename%[.][aA][iI][fF]}
if $mp3coder $options "$filename" "${name}.mp3"
then
if [ $rmsrc = true ]; then
rm -f "$filename"
fi
fi
;;
* )
if $mp3coder $options "$filename" "${filename}.mp3"
then
if [ $rmsrc = true ]; then
rm -f "$filename"
fi
fi
;;
esac
done mlame options:
-h: help text
-r: remove files after encoding


.wav to .flac (require the installation of Flac)
http://flac.sourceforge.net/

Flac is a lossless compression format, meaning no lost of quality in the compression.
It compress to about 60% of the original size.
Great for storing cd quality album onto a harddrive, ect... It can also be played as .flac on a computer and some portable player also play Flac.
See man flac for options.
Usage:
flac /home/PathToTheMusicFiles/song01.wav
.wav to .ogg

Encode using oggenc (lossy)
http://www.vorbis.com/

Quality from 0 to 10
4 = 110kps-128kps
5 = 136kps-160kps
6 = 160kps-192kps
oggenc --help

Usage:
oggenc -q 6 /home/PathToTheMusicFiles/song01.wav
.wav to .ape
(Google for the Monkey Audio Library for Linux) (mac-3.99-u4-b5.tar.gz)
Also its nice to have this (k3bmonkeyaudioplugin-3.1.tar.bz2)
Encode .wav to .ape (lossless to lossless)
Modes:
Compress (better quality) (fast): '-c1000'
Compress (normal): '-c2000'
Compress (high): '-c3000'
Compress (extra high): '-c4000'
Compress (insane): '-c5000'
Decompress: '-d'
Verify: '-v'
Convert: '-nXXXX'
Usage:
mac /home/PathToTheMusicFiles/song01.wav /home/PathToTheMusicFiles/song01.ape -c1000
PS: I would not normally compress to that format, i would rather use Flac instead but sometimes you need this librairy to decompress a .ape to .wav or a .ape to .mp3.
see next .ape to .mp3

.ape to .mp3
(require the Monkey Audio Library for Linux and also mp3splt)

Use the script cueape
I slightly modified that script to my taste.
It's a very useful script that read a .cue file to break down a album_xyz.ape into multiple tracks.
Usage:
cueape [input ape file] [input cue file] [parameters] Parameters: -m for mp3 or -o for ogg encode.
Exemple:
cueape /home/PathToTheMusicFile/albumXYZ.ape /home/PathToTheMusicFile/albumXYZ.cue -m
It will decompress to a .wav then it will encode to .mp3 or .ogg
It keep one big album_xyz.wav and one big album_xyz.mp3.
.mp3 is encode in VBR of 192 kps. (my default)
Then it call for mp3splt to split that big album_xyz.mp3 into multiple tracks.
mp3splt also write the tags {some tags error i find, not a big deal}

cueape script:
#!/bin/bash

################################################## ##############################################
#usage cueape [input ape file] [input cue file] [parameters]
#Parameters can be: -m for mp3 encoding or -o for ogg encoding.
# Decompress to .wav then encode to .mp3 or to .ogg see options [parameters]
# Keeps a copy of .wav and the original .ape, also it will keep a big .mp3
# It then split the resulting .mp3 file into multiple .mp3 tracks.
# .mp3 are encoded to VBR average 192 kps.
# mp3splt will then write tags.
################################################## ##############################################
#cueape 0.1
#This script is intended to convert ape or flac + cue files to
#ogg vorbis or mp3 files, setting the tags to the correct value,
#obtained from the cue file.
#REQUIREMENTS:
# -Oggenc installed (it comes with vorbis-tools) if you want to encode into Ogg Vorbis.
# -lame installed if you want to encode into mp3
# -mac to decode ape files (Monkey's Audio)
# -flac to decode flac files.
# -mp3split

#IF YOU FIND A BUG OR HAVE A SUGGESTION COMMENTO OR SIMPLY WANT TO CONTACT ME PLEASE MAIL ME TO
#rafadev_*@gmail.com REMOVING THE "_*"
#This is done to prevent spamming

#Copyright (C) 2006 Rafael Ponieman - Buenos Aires, Argentina

#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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


#scripted by deX


case "$1" in
*.[aA][pP][eE] | *[fF][lL][aA][cC] )
if [ ! -f "$1" ] ; then
echo "Input file $1 doesn't exist"
exit 1
fi
if [ ! -f "$2" ]; then
echo "Cue input file $2 doesn't exist"
exit 1
fi ;;
* )
echo "Error: invalid input parameters"
exit ;;
esac

#Testing parameters
if [ "$3" != "-m" ] && [ "$3" != "-o" ] ; then
echo -en "\033[1;31mInvalid parameters\n"
echo -en "\033[1;37m"
echo -en "Usage: cueape [input ape file] [input cue file] [parameters]\nParameters can be: -m for mp3 encoding or -o for ogg encoding.\n"
exit 1
fi

#Need help with this one, coudn't solve it. I need to know how to check if a
#program actually exists and is accesible
#Checking for mac
#[ -f $(which 'maca' >> /dev/null) ] || {
# echo -en "\033[1;31mYou must have mac in your PATH.\033[1;37m\nPlease install Monkey's Audio Codec\nYou can get it from http://sourceforge.net/projects/mac-port/\n"
#}


#Saving the position so as to return afterwards
olddir="$(pwd)"

#Going to target directory
cd "$(dirname "$1")"

#Checking for the output folder. If it's not there I create it
[ ! -d "Output" ] && mkdir -p "Output"
cp "$2" "Output/"

#Decompress
echo -en "\nCueape 0.1\n\n"
echo -en "\033[1;32mStarting conversion\n"

#Checking filetype by extension and decompressing
tmp="$(basename "$1")"
tmp="${tmp##*.}"

case "$tmp" in
[fF][lL][aA][cC] )
echo -en "\033[1;32mDecompressing FLAC file\n\n"
echo -en "\033[1;37m"
tm="$(basename "$1")"
tm="${tm%.[fF][lL][aA][cC]}"
out="$(flac "-d" "$1" -o "Output/${tm}.wav" )"
;;
[aA][pP][eE] )
echo -en "\033[1;32mDecompressing APE file\n\n"
echo -en "\033[1;37m"
tm="$(basename "$1")"
tm="${tm%.[aA][pP][eE]}"
out="$(mac "$1" "Output/${tm}.wav" "-d")"
;;
* )
echo "Error: line 99"
esac

cd "Output"
echo -en "\033[1;32m\nDecompression finished\n"
echo -en "\033[1;32mStarting reencoding\n\n"
echo -en "\033[1;37m"
if [ "$3" = "-o" ] ; then
#Calling oggenc. Saving output for future checking
out="$(oggenc -q 6 -o "$tm.ogg" "$tm.wav")"
echo -en "\033[1;32m\nReencoding finished\n"
echo -en "\033[1;32mSplitting\n\n"
echo -en "\033[1;37m"
out="$(mp3splt -c "$(basename "$2")" -o "@n+-+@t" "$tm.ogg")"
else
#Calling lame. Saving output for future checking
out="$(lame --preset standard "$tm.wav" "$tm.mp3")"
echo -en "\033[1;32m\nReencoding finished\n"
echo -en "\033[1;32mSplitting\n\n"
echo -en "\033[1;37m"
#Using framemode becaus this settings are for VBR
out="$(mp3splt -f -c "$(basename "$2")" -o "@n+-+@t" "$tm.mp3")"
fi
cd "$oldir"
echo -en "\033[1;32m\nProcessing finished successfully\n"
echo -en "\033[1;37m"
exit 0
.ape to .wav
(require the Monkey Audio Library)
If no .cue file present you can go without the cueape script and decompress those .ape files one at the time.
There will be no tags writen and no split of tracks if this is a album.
usage:
mac /home/PathToTheMusicFile/song01.ape /home/PathToTheMusicFile/song01.wav -d
END OF PART -1- (see next post for part -2-)

Davno
05-11-2008, 11:15 AM
This is part 2 of the tutorial about audio in Linux for newbie.
AUDIO RIPPING, CONVERTING, ENCODING, ect...

PART -2-

.flac to .wav (require the installation of Flac)
http://flac.sourceforge.net/

Usage:
flac -d /path/to/the flac file
.flac to .mp3 (if a .cue file is present)

Use this modified script cueflac
Based on the cueape script.
It's a very useful script that read a .cue file to break down a album_xyz.flac into multiple tracks.

Usage:
cueflac [input flac file] [input cue file] [parameters]
Parametres: -m for mp3 encoding or -o for ogg encoding.

It will decompress to a .wav then it will encode to .mp3 or .ogg
It keep one big album_xyz.wav and one big album_xyz.mp3.
.mp3 is encode in VBR of 192 kps. (my default)
Then it call for mp3splt to split that big album_xyz.mp3 into multiple tracks.
mp3splt also write the tags {some tags error i find, not a big deal}

cueflac script:
#!/bin/bash

################################################## ##############################################
#This script is the same than cueape but adapted for flac files.
#usage cueflac [input flac file] [input cue file] [parameters]
#Parameters can be: -m for mp3 encoding or -o for ogg encoding.
#
# Decompress to .wav then encode to .mp3 or to .ogg see options [parameters]
# Keeps a copy of .wav and the original .flac, also it will keep a big .mp3
# It then split the resulting .mp3 file into multiple .mp3 tracks.
# .mp3 are encoded to VBR average 192 kps.
# mp3splt will then write tags.
################################################## ##############################################
#cueape 0.1
#This script is intended to convert ape or flac + cue files to
#ogg vorbis or mp3 files, setting the tags to the correct value,
#obtained from the cue file.
#REQUIREMENTS:
# -Oggenc installed (it comes with vorbis-tools) if you want to encode into Ogg Vorbis.
# -lame installed if you want to encode into mp3
# -mac to decode ape files (Monkey's Audio)
# -flac to decode flac files.
# -mp3split

#IF YOU FIND A BUG OR HAVE A SUGGESTION COMMENTO OR SIMPLY WANT TO CONTACT ME PLEASE MAIL ME TO
#rafadev_*@gmail.com REMOVING THE "_*"
#This is done to prevent spamming

#Copyright (C) 2006 Rafael Ponieman - Buenos Aires, Argentina

#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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


#scripted by deX


case "$1" in
*.[aA][pP][eE] | *[fF][lL][aA][cC] )
if [ ! -f "$1" ] ; then
echo "Input file $1 doesn't exist"
exit 1
fi
if [ ! -f "$2" ]; then
echo "Cue input file $2 doesn't exist"
exit 1
fi ;;
* )
echo "Error: invalid input parameters"
exit ;;
esac

#Testing parameters
if [ "$3" != "-m" ] && [ "$3" != "-o" ] ; then
echo -en "\033[1;31mInvalid parameters\n"
echo -en "\033[1;37m"
echo -en "Usage: cueape [input ape file] [input cue file] [parameters]\nParameters can be: -m for mp3 encoding or -o for ogg encoding.\n"
exit 1
fi

#Need help with this one, coudn't solve it. I need to know how to check if a
#program actually exists and is accesible
#Checking for mac
#[ -f $(which 'maca' >> /dev/null) ] || {
# echo -en "\033[1;31mYou must have mac in your PATH.\033[1;37m\nPlease install Monkey's Audio Codec\nYou can get it from http://sourceforge.net/projects/mac-port/\n"
#}


#Saving the position so as to return afterwards
olddir="$(pwd)"

#Going to target directory
cd "$(dirname "$1")"

#Checking for the output folder. If it's not there I create it
[ ! -d "Output" ] && mkdir -p "Output"
cp "$2" "Output/"

#Decompress
echo -en "\nCueape 0.1\n\n"
echo -en "\033[1;32mStarting conversion\n"

#Checking filetype by extension and decompressing
tmp="$(basename "$1")"
tmp="${tmp##*.}"

case "$tmp" in
[fF][lL][aA][cC] )
echo -en "\033[1;32mDecompressing FLAC file\n\n"
echo -en "\033[1;37m"
tm="$(basename "$1")"
tm="${tm%.[fF][lL][aA][cC]}"
out="$(flac "-d" "$1" -o "Output/${tm}.wav" )"
;;
[aA][pP][eE] )
echo -en "\033[1;32mDecompressing APE file\n\n"
echo -en "\033[1;37m"
tm="$(basename "$1")"
tm="${tm%.[aA][pP][eE]}"
out="$(mac "$1" "Output/${tm}.wav" "-d")"
;;
* )
echo "Error: line 99"
esac

cd "Output"
echo -en "\033[1;32m\nDecompression finished\n"
echo -en "\033[1;32mStarting reencoding\n\n"
echo -en "\033[1;37m"
if [ "$3" = "-o" ] ; then
#Calling oggenc. Saving output for future checking
out="$(oggenc -q 6 -o "$tm.ogg" "$tm.wav")"
echo -en "\033[1;32m\nReencoding finished\n"
echo -en "\033[1;32mSplitting\n\n"
echo -en "\033[1;37m"
out="$(mp3splt -c "$(basename "$2")" -o "@n+-+@t" "$tm.ogg")"
else
#Calling lame. Saving output for future checking
out="$(lame --preset standard "$tm.wav" "$tm.mp3")"
echo -en "\033[1;32m\nReencoding finished\n"
echo -en "\033[1;32mSplitting\n\n"
echo -en "\033[1;37m"
#Using framemode becaus this settings are for VBR
out="$(mp3splt -f -c "$(basename "$2")" -o "@n+-+@t" "$tm.mp3")"
fi
cd "$oldir"
echo -en "\033[1;32m\nProcessing finished successfully\n"
echo -en "\033[1;37m"
exit 0
.flac to .mp3 (Perl script that also require perl-MP3-Info)

Usage:
cd /path/to/directory/with/flac files
then:
flac2mp3.pl flacfilename
or for multiple tracks:
flac2mp3.pl *flac
flac2mp3.pl script:
#!/usr/bin/perl
#
# Converts FLAC to MP3 preserving tags
# License: GPLv2
# Home: http://www.GuruLabs.com/downloads.html
#
# Note: Only use on flac files that you trust. A
# malicious ID3v1 tag could hose you.
#
# Usage:
# cd /path/to/directory/with/flacfiles
# flac2mp3.pl flacfilename
# For multiple tracks:
# flac2mp3.pl *flac
#
################################################## #############

use MP3::Info;

foreach $file (@ARGV) {
if (!($file =~ /\.flac$/)) {
print "Skipping $file\n";
next;
}
undef $year; undef $artist; undef $comment; undef $album; undef $title; undef $genre; undef $tracknum;
if ($tag = get_mp3tag($file)) {
$year = $tag->{YEAR};
$artist = $tag->{ARTIST};
$comment = $tag->{COMMENT};
$album = $tag->{ALBUM};
$title = $tag->{TITLE};
$genre = $tag->{GENRE};
$tracknum = $tag->{TRACKNUM};
chomp($year, $artist, $comment, $album, $title, $genre, $tracknum);
$tracknum = sprintf("%2.2d", $tracknum);
} else {
print "Couldn't get id3v1 tag for $file.\n";
}
if (($artist) && ($title) && ($tracknum)) {
$outfile = "$tracknum" . "_-_" . "$title.mp3";
`flac -c -d "$file" | lame --alt-preset standard --ty $year --ta "$artist" --tc "$comment" --tl "$album" --tt "$title" --tg "$genre" --tn $tracknum - "$outfile"`;
} else {
$outfile = $file;
$outfile =~ s/\.flac$/.mp3/;
`flac -c -d "$file" | lame -b 192 - "$outfile"`;
}
}

.flac to .ogg
Encode using oggenc (lossy)
http://www.vorbis.com/

Usage:
oggenc -q 6 /path/to/your/song01.flac
.flac to .wav (require the installation of Flac)
http://flac.sourceforge.net/

Usage:
flac -d /path/to/your/song01.flac
.m4a to .wav (require mplayer and faad2)

Usage:
cd /path/to/directory/with/song.m4a
Then use like this:
mplayer -ao pcm YourSong.m4a -ao pcm:file="YourSong.wav"
.m4a to .mp3 (require mplayer, faad2 and lame)
Usage:
cd /path/to/directory/with/.m4a files
Then use the m4a2mp3 script:
#!/bin/bash
#
# $Id: aac2mp3,v 1.2 2005/08/22 15:32:34 rali Exp $
# My modification called m4a2mp3
#
# Convert one or more AAC/M4A files to MP3. Based on a script example
# I found at: http://gimpel.gi.funpic.de/Howtos/convert_aac/index.html
# Usage:
# cd /PathTo/your/m4a files
# Then run this script

ME=`basename ${0}`

AAC2WAV="/usr/bin/mplayer"
WAV2MP3="/usr/bin/lame"

EXT="m4a"
BITRATE="192"

do_usage() { # explanatory text
echo "usage: ${ME} [-b nnn] [-e ext] [-f] [-c] [-r] [-v] [-h] [file list]"
echo " Convert music from AAC format to MP3"
echo " -l /path/app Specify the location of lame(1)"
echo " -m /path/app Specify the location of mplayer(1)"
echo " -b nnn bitrate for mp3 encoder to use"
echo " -e ext Use .ext rather than .m4a extension"
echo " -f Force overwrite of existing file"
echo " -c Delete original AAC|M4A file(s)"
echo " -s Keep intermediate .wav file(s)"
echo " -v Verbose output"
echo " -h This information"
exit 0
}

do_error() {
echo "$*"
exit 1
}

file_overwrite_check() {
if [ "$FORCE" != "yes" ]
then
test -f "${1}" && do_error "${1} already exists."
else
test -f "${1}" && echo " ${1} is being overwritten."
fi
}

create_wav() { # use mplayer(1) to convert from AAC to WAV
file_overwrite_check "${2}"

test $VERBOSE && echo -n "Creating intermediate WAV file"

${AAC2WAV} -really-quiet -ao pcm "${1}" -ao pcm:file="${2}"
if [ $? -ne 0 ]
then
echo ""
echo "Conversion to WAV (${AAC2WAV}) failed."
do_cleanup
do_error "Exiting"
fi

test $VERBOSE && echo ". OK"
}

create_mp3() { # use lame(1) to convert from WAV to MP3
file_overwrite_check "${2}"

test $VERBOSE && echo -n "Creating output MP3 file"

${WAV2MP3} -h -b ${BITRATE} -S "${1}" "${2}"
if [ $? -ne 0 ]
then
echo ""
echo "Conversion to MP3 (${WAV2MP3}) failed."
do_cleanup
do_error "Exiting"
fi

test $VERBOSE && echo ". OK"
}

do_cleanup() { # Delete intermediate and (optionally) original file(s)
test $VERBOSE && echo -n "Deleting intermediate file"
test ${SAVEWAV} || rm -f "${2}"
test ${RMM4A} && rm -f "${1}"
test $VERBOSE && echo ". OK"
}

do_set_bitrate() {
test $VERBOSE && echo -n "Setting output bitrate to: $1 kbps"
BITRATE=$1
test $VERBOSE && echo ". OK"
}

GETOPT=`getopt -o l:m:b:e:cfhrv -n ${ME} -- "$@"`
if [ $? -ne 0 ]
then
do_usage
fi

eval set -- "$GETOPT"

while true
do
case "$1" in
-l) LAME=$2 ; shift ; shift ;;
-m) MPLAYER=$2 ; shift ; shift ;;
-b) do_set_bitrate $2 ; shift ; shift ;;
-e) EXT=$2 ; shift ; shift ;;
-f) FORCE="yes" ; shift ;;
-c) RMM4A="yes" ; shift ;;
-s) SAVEWAV="yes" ; shift ;;
-v) VERBOSE="yes" ; shift ;;
-h) do_usage ;;
--) shift ; break ;;
*) do_usage ;;
esac
done

test -f $LAME || do_error "$LAME not found. Use \"-l\" switch."
test -f $MPLAYER || do_error "$MPLAYER not found. Use \"-m\" switch."

if [ $# -eq 0 ]
then # Convert all files in current directory
for IFILE in *.${EXT}
do
if [ "${IFILE}" == "*.${EXT}" ]
then
do_error "No files with extension ${EXT} in this directory."
fi

OUT=`echo "${IFILE}" | sed -e "s/\.${EXT}//g"`

create_wav "${IFILE}" "${OUT}.wav"
create_mp3 "${OUT}.wav" "${OUT}.mp3"
do_cleanup "${IFILE}" "${OUT}.wav"

done
else # Convert listed files
for IFILE in "$*"
do
test -f "${IFILE}" || do_error "${IFILE} not found."

OUT=`echo "${IFILE}" | sed -e "s/\.${EXT}//g"`

create_wav "${IFILE}" "${OUT}.wav"
create_mp3 "${OUT}.wav" "${OUT}.mp3"
do_cleanup "${IFILE}" "${OUT}.wav"
done
fi
exit 0
Joining mp3 files: (require the installation of mpgtx)
http://mpgtx.sourceforge.net/

Usage:
mpgjoin /path/to/your/files/*.mp3 -out /path/to/your/files/NameOfTheAlbum.mp3
or with mp3wrap (require the installation of mp3wrap)
http://mp3wrap.sourceforge.net/

Will keep tags informations of individual files as long as the resulting tag is not modified.
Can be played like a big album or split later to the original multiple tracks (using mp3splt).

Usage:
cd /path/to/directory/with/audio files
exemple:
mp3wrap AlbumTitle.mp3 *.mp3
That album could later be split to the original multiple files with mp3splt:
http://mp3splt.sourceforge.net/mp3splt_page/home.php
Usage:
mp3splt -w -f AlbumTitle_MP3WRAP.mp3
Joining flac files: (require the installation of shntool)
http://etree.org/shnutils/shntool/

You need to have all your codecs installed before you compile shntool.
Ex: lame, flac, ogg, ape, ect...
shntool will put your files in order if you rename them with numbers like: 01_song, 02_whatever, 03_abc, ect...
Usage:
cd to /path/ToThe/FlacFiles
then:
shntool join -o flac *.flac
Or join those flac files into one big.wav file:
shntool join *.flac
Hopefully there is not to many mistakes in this tutorial.
I hope this help somebody. :)

saikee
05-13-2008, 05:36 PM
Davno,

This is a good collection of nice and useful information.

Thanks for sharing with us.