Creating Audio CDs With Linux

Recently a friend asked me for a CD of music I wrote and recorded many years ago. Unfortunately, the material existed only as a 4-track cassette tape master, but the tape had been recorded on a Yamaha MT120 home studio 4-track, with a speed of 9.5 centimeters per second and with dbx (a noise reduction method) enabled. Though the tape was hardly a sonic or musical masterpiece, it did sound good enough to warrant recording to hard disk for processing before eventually burning the songs to CD.

This article follows the process of recording the material to the hard disk, editing and filtering it with signal processing software, and finally creating an audio CD from the results, complete with custom covers for the jewel case. I'll present and describe the tools used in each stage of the process, and I'll explain how you too can turn your computer into a powerful audio CD mastering machine, using only free and open-source Linux software.

Stage 1: recording to hard disk: ecasound

Kai Vehmanen's ecasound (Figure 1) is multitrack-ready, capable of recording as many channels as your sound card setup permits. The system used for this project includes two sound cards, a SoundBlaster PCI128 and an SBLive Value. It is possible to record two channels into one card and two into another to create a system with four-channel analog input, but due to clock drift, it is impossible to correctly synchronize the recorded tracks (see Paul Winkler's excellent Linux Audio Quality HOWTO for a summary of dual sound-card clock drift). Synchronized multichannel I/O is normally found only on high-end digital audio boards. Only a few such boards enjoy Linux driver support at this time. (Two notable examples are the boards from MidiMan and RME.) Alas, I don't own one of those boards, so I decided to simply mix the master tape's four tracks with the mixer on the MT120, sending the mixed stereo output to the input of the SBLive (its audio specifications are somewhat better than those for the PCI128).

Figure 1. Kai Vehmanen's ecasound.

Recording with ecasound (or with qtecasound, its GUI sibling (Figure 2) is extremely simple. I issued the following command from an xterm:

ecasound -c -b:4096 -r -i:alsa,0,0,0 -o my_song_01.wav

The command options are as follows:

-c starts ecasound in interactive mode

-b sets the audio buffer size

-r sets the realtime scheduler (SCHED_FIFO) flag

-i sets the input device and its parameters

-o names the output file

I have a lot of RAM (256 MB) in a decently fast machine (a PIII 550), so I set the buffer size to a relatively large number. You may need to adjust it for best results on your own system. Ecasound will work with any Linux sound driver, but in this example I've set the input device to the ALSA driver for my SBLive. The numbers indicate the first sound card in my system (the count starts at 0), the first audio input device (0, or /dev/snd/pcmC0D0), and the subdevice (also 0). The output file will be recorded at the default CD-quality specifications, i.e., a stereo recording with a sampling rate of 44.1 kHz and 16-bit sample resolution.

Setting the realtime scheduler helps prevent underruns (gaps and dropouts in the recording), but to guarantee dropout-free recording, I suggest installing a kernel patched for low latency. (See my O'Reilly Network article on low-latency audio for the details.) The results are definitely worth the minimal effort, and if you intend to do much recording in Linux, I strongly urge you to patch your kernel for low-latency response.

The actual recording starts when you type t at ecasound's command prompt. Press s to finish. If all goes well, ecasound will report no errors. If underruns are reported, you probably need to upgrade to a low-latency patched kernel and tune your IDE drive with hdparm (as described in my low-latency article).

Stage 2: editing and processing sound: tools for X and the console

After recording the songs to the hard disk, I wanted to edit them before burning the files to the audio CD. I used Doug Scott's MiXViews (Figure 3) to perform the following operations:

Cut extraneous length from the files

Adjust the overall amplitude (the gain factor, oddly called "Phrase" in MiXViews)

Filter extraneous high frequencies

Figure 3. Doug Scott's MiXViews.

Readers who are familiar with other, more modern Linux soundfile editors may wonder why I chose MiXViews. My best reason is that I know it very well, having assisted in an early port to Linux. Other reasons include its ease of use (it can be controlled from the keyboard as well as the mouse), its accuracy and definition (the file view can be zoomed to single-sample resolution), its well-designed filters, and its speed.

Soundfiles are most easily edited in graphic displays, and Linux can claim a number of fine soundfile editors with graphic interfaces, including Snd, Broadcast2000, and DAP. All of those editors absolutely require the X-Window graphics system, but console users are not entirely shut out from the world of graphic editing: Bernhard Oemer's WaveTools is a suite of WAV-format soundfile editing utilities that includes wView, an interactive console SVGA soundfile viewer. Although wView isn't actually an editor, the information it provides can be utilized by the other tools in the suite (which includes mixing, cutting, and filtering modules). Traditional Unix pipes can be used to link operations together for a deceptively simple yet powerful soundfile editing environment at the Linux console.

Console and X users alike may also be interested in J.A. Bezemer's GramoFile. This utility was originally designed for cleaning up soundfiles created from phonograph recordings. Such recordings are often marred by clicks and pops caused by imperfections of the original medium, and GramoFile's greatest strength lies in its selection of audio filters (Figure 4).

The final step in my editing process dealt with the problem of uneven amplitudes between soundfiles, i.e., some files were louder than others, so I employed Chris Vaill's normalize. This handy little tool can batch process a group of WAV files to bring their relative volumes into balance with each other, ensuring that my listeners would not need to adjust their player's volume level for each song. In order to normalize all the files I intended to burn, I ran this simple command:

normalize -m /home/dlphilp/soundfiles/cd-audio/my_songs/*.wav

The -m flag adjusts the level of each track to the average level of all the tracks. Once the levels had been normalized, it was time to move on to the next stage and actually burn the soundfiles to an audio disc.

Stage 3: burning the CD: cdrecord and gcombust

Burning compact discs under Linux is a straightforward matter. Many writable CD drives are supported by current Linux kernels: SCSI drives are directly supported in the SCSI subsystem set up during kernel compilation, and IDE/ATA drives are indirectly supported via the SCSI emulation module (see the Linux CD-Writing HOWTO for a list of supported CD-Rs and CD-RWs). Many mainstream distributions include the SCSI emulation module (ide_scsi.o), but if your distribution doesn't include it, you will need to configure and recompile your kernel for the emulation support.

My CD burner is a Creative Labs RW4224E CD-RW, correctly identified in the kernel boot messages as an IDE/ATAPI drive (/dev/hdc). Figure 5 illustrates how I configured my kernel for SCSI support and Figure 6 shows the SCSI emulation configuration. (The emulation mode depends on some of the SCSI configuration options.) Rather than detail the emulation setup here, I direct the interested reader to Chris Stoddard's CD-Writing with an ATAPI CDR Mini-HOWTO for a step-by-step description of the process. Once the emulation module is installed, the system will recognize the IDE CD-RW as a SCSI device (/dev/scd0).

Jörg Schilling's cdrecord is the indispensable component for burning CDs under Linux. Happily, it is included with every mainstream Linux distribution, and it is very easy to use. Cdrecord can create CD-ROM data discs in standard ISO 9660 format or a hybrid format readable by Macintosh machines, CD-DA (digital audio) discs, and mixed-mode discs that combine ISO 9660 and audio tracks. Typing 'man cdrecord' at a console or xterm command prompt will bring up the very informative manual page, complete with examples and full explanations for every option.

Burning my audio CD from the command line required only this command sequence:

-audio tells cdrecord that the recorded tracks are in CD-DA format (stereo 16-bit 44.1 kHz soundfiles)

It's really that simple, but for those of you who can't bear the thought of working at the Linux console, help is at hand with gcombust (Figure 7), a GTK-based graphic front end for cdrecord. Gcombust organizes cdrecord's many options into a sensible GUI, and if you're using the GNOME desktop, you can drag and drop your files into gcombust's data holding areas.

Note: CD audio is specifically defined as stereo sound sampled at 44.1 kHz with 16-bit resolution. My files were recorded with those specifications, but they were not yet "CD ready." CD audio has its own file format, and WAV files must be converted to that format before burning to disc. Fortunately this process is carried out transparently by cdrecord. Ecasound is also capable of direct conversion, and a number of other format conversion utilities are also available for Linux.

Creating an audio CD may involve some options not used when burning a data disc. For example, by default, audio tracks will be separated by a 2-second gap. This mode is called TAO (tracks at once); if you want your tracks to run together without a gap, or if you want to reset the gap value, you will want to use the DAO (disc at once) mode. Both modes are available from cdrecord; however, for finer control of the DAO mode, you may want to consider using cdrdao, a CD-burning utility specifically designed for disc-at-once recording.

Some words about discs and recording speeds

Blank recordable compact discs are available in a range of formats, capacities, and prices. My experiences with a variety of discs has so far led me to these conclusions:

Don't use cheap discs for important recordings. Spend a little more money for a lot more reliability.

Either 74-minute and 80-minute discs will work fine in standard CD players.

Rewritable audio discs are useful only in your CD-RW drive. They will not work in a regular CD player.

When selecting the speed for burning an audio disc, keep in mind that you increase the likelihood of "coasterizing" it (i.e., making it useful only as a beverage coaster) at the higher rates. My writer is capable of 1x, 2x, and 4x recording speeds, but the 4x is unreliable, creating a condition known as a buffer underrun (the data buffer empties while the laser is still burning the disc). Cdrecord employs BURN-Proof, a technology that enables the safe use of higher burning rates (it suspends and restarts the writing process when the CD recorder's buffer is about to empty); however, not all drives are compatible with the technology (mine is not). It must also be noted that BURN-Proof will only correct buffer underruns; it will not compensate for faulty or inadequate hardware.

For my project I found 1x and 2x to be the safest speeds. Your mileage may vary, but if you are consistently receiving underruns at high burn speeds, try recording at a slower rate (or see if BURN-Proof will work for your drive).

No CD project can be called complete until the disc's case has a decorative and descriptive cover. I used B.W. Fitzpatrick's cdlabelgen to prepare the tray and cover labels for my disc. Cdlabelgen must be the simplest label generator available for Linux: It's a small Perl script with only a few options, but it creates perfectly usable covers for data and audio discs. Console-phobic users will be happy to learn that gcombust provides a nice GUI for cdlabelgen's options (Figure 8). Working in X also lets you use the ghostview PostScript file viewer to preview the output before printing.

Here's the command sequence I used to generate the simple cover seen in Figure 9:

cdlabelgen -c "Songs" -s "Dave Phillips" -o my_songs.ps

The command options used above indicate the following:

-c category (title)

-s subcategory (subtitle)

-o name for saved PostScript output file

Cdlabelgen works perfectly for quick and easy cover cards, but for a fancier, picturesque cover, I used Pascal Panneels' Kcdlabel (Figure 9). This program is wonderful for the creation of covers with my own images and favorite fonts. When used with the GIMP, Kcdlabel is a powerful tool for making and printing beautiful CD covers (Figure 10).

My friend was quite pleased by both the audio and visual results of my project. I was equally pleased, not only with the appearance and sound of the results, but with the excellent Linux software available for each stage of the project. Ecasound provided dropout-free recording to the hard disk, cdrecord managed the CD burn with no buffer underruns, and cdlabelgen provided a simple way to create tray and cover cards for the completed disc. It's worth pointing out that each stage of my project could be realized either at the Linux console (with ecasound, Gramofile, cdrecord, and cdlabelgen) or in X (with qtecasound, MiXViews, gcombust, and Kcdlabel). It's also worth mentioning that every piece of software used in my project was free and open-source software, and almost all of it is licensed under the GPL. As usual, Linux provides me with an assortment of powerful tools and lets me choose how and where I want to use them. It definitely works for me.