Sunday, April 27, 2008

Making a CD from MP3 files with Linux

Our church posts sermons online in the form of MP3 files (so do many others, including KBF). The task is to create a CD so that the iPod-challenged generation can listen to it.

So first, we download the file, for which file(1) tells me:
080413_sscruggs.mp3: MPEG ADTS, layer III, v2,  32 kBits, 22.05 kHz, Monaural
That gives us a few clues about what must be done:
  1. We need to "transcode" the file from MP3 to a "wav" file.
  2. We need the data rate to be a CDDA-compatible one (i.e., 44.1 kHz).
  3. I'm not sure, but to be safe I want to make it a stereo file rather than mono. (When I listen to these monaural MP3s on my iPod, I only get sound from one ear.)
Some CD-burning programs like "k3b" will do the data-rate conversion for you, but I don't know about mono/stereo.


This is simplicity itself. I use the excellent mpg321 decoder, like so:
$ mpg321 --wav 080413_sscruggs.wav 080413_sscruggs.mp3 
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2, and 3.
Version 0.59q (2002/03/23). Written and copyrights by Joe Drew.
Uses code from various people. See 'README' for more!

Directory: /home/carol/Desktop/
Playing MPEG stream from 080413_sscruggs.mp3 ...
MPEG 1.0 layer III, 32 kbit/s, 22050 Hz mono

[35:11] Decoding of 080413_sscruggs.mp3 finished.
$ file 080413_sscruggs.wav
080413_sscruggs.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 22050 Hz
There we are -- a WAV file. For the rest...

wav (22050Hz mono) → wav (44100Hz stereo)

I believe we can do this all in one step, using the extremely versatile sox(1) program. I invoked it like this:
$ sox 080413_sscruggs.wav -c 2 -r 44100 cd0413-scotty.wav polyphase
  • "080413_sscruggs.wav" is the input file;
  • "cd0413-scotty.wav" is the output file. Parameters appearing before the output file name are the output file's format options:
    • "-c 2" means I want the output file to have two channels.
    • "-r 44100" means, well, that's the sample rate I want the output file to have.
  • "polyphase" gives a higher-quality rate conversion than the default linear interpolation. (I don't know if "resample" is better or worse for this sort of application.)
This took about two minutes on a 2.6GHz Pentium 4 box. The result is a file like:
$ file cd0413-scotty.wav
cd0413-scotty.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 44100 Hz
Once you have the requisite 44.1kHz "wav" files, use your favorite CD-burning program to make an audio CD.

I use k3b because it's easy and convenient. I used to use cdrecord, but I have gotten old and lazy. Of course the best thing about k3b is that it plays a bugle victory song after a successful burn.

1 comment:

LNA said...
This comment has been removed by a blog administrator.