Like most people, I have a fairly sizeable collection of audio files stored on my hard disk in .mp3 or .ogg format – music, copies of interviews, podcasts and old radio shows. Which is great for my MP3 player and my laptop computer, but it isn’t any good for my basic standalone CD player which doesn’t have a clue how to play MP3 files. So until I get a better CD player I use a simple technique to create audio CDs that all CD players can handle.
I started using this technique a couple of years ago and despite a recent spate of free software applications for Linux that can pretty much do the same by simply pointing and clicking, I still find myself reverting to the command line.
The technique is simple enough and you’ll need a couple of small applications to complete the task: mpg321, ogg123 (included in the vorbis-tools package), normalize-audio, sox and cdrecord.
On Ubuntu, getting most of these tools is as easy as typing sudo apt-get install appname at the command line. On other distributions you may need to look around for the RPM or source files for each.
First, collect the .mp3 and .ogg files you are going to convert into a directory:
mv file1.mp3 ~/FilesToConvert/ # for each of the files
Depending on where you got your files from they may include blank spaces in their names or some may have a combination of upper and lowercase file extensions. To avoid possible problems in the next few steps it is best to convert these to something less problematic – blank spaces to underscores and uppercase to lowercase
Convert spaces to underscores (replace .mp3 with .ogg for your ogg vorbis files)
for i in *.mp3; do mv “$i” `echo $i | tr ‘ ‘ ‘_’`; done
Bear in mind the ` character is not an apostrophe or single quote mark. It is a tick mark which is angled backwards slightly.
Then convert uppercase extensions into lowercase (again, replace .MP3 with .OGG to achieve the same with ogg files):
for i in *.MP3; do mv “$i” “`basename “$i” .MP3`.mp3″; done
Now we are ready to convert the .mp3s and .ogg files to .wav files. My preferred application for this is mpg321 which is a free application. There was originally an mpg123 application but its restrictions made it a less appealing option for free software users. To convert .ogg files to .wav files I use ogg123.
Convert the mp3 files to .wav:
for i in *.mp3; do mpg321 –rate 44100 –stereo –buffer 3072 –resync -w `basename $i .mp3`.wav $i; done
Again, watch out for that back tickmark.
Then convert .ogg files to .wav:
for i in *.ogg ; do ogg123 -d wav -f `basename $i .ogg`.wav $i; done
Sit back and wait a little as the conversion is completed.
Once your files are converted there is one thing left to do before burning them to CD. Unless you got your files from a single source, you’ll probably find that all of them have different volume levels. To rectify this we need to use normalize-audio which adjusts the volume across a group of files to be the same (some older systems may still use normalize instead of normalize-audio):
normalize-audio -m *.wav
This can take a couple of minutes but once that is done type file *.wav and check the output for any files that are not 16 bit, stereo 44100Hz. To be successful we need to make these to all be the same. If you find you have some files that are not 16bit, stereo 44100Hz use this command to fix the problem:
sox track01.wav -r 44100 track01-new.wav resample
Now you’re ready to burn the files to a CD and get ready for listening pleasure. There are many tools for burning CDs on Linux but again I often fall back to the command line to do this simple task using cdrecord.
Still in the same directory type:
cdrecord dev=ATAPI:/dev/hdc -eject -pad -audio *.wav
Newer Linux kernels prefer the “ATAPI:/dev/hdc” command. If you have problems with this you can try the older version:
cdrecord dev=1,1,0 -eject speed=2 -pad -audio *.wav
You should now have a CD that you can insert into any CD player and enjoy without having to turn on your PC.
One thing to bear in mind is that because you have started with .mp3 and .ogg files which may be of varying quality and are already compressed, converting them to .wav files is not going to gain you any quality. The quality of the CDs produced using this method is not flawless but more than adequate for most uses.