From Vinyl to Digital

Tom Younker

Issue #113, September 2003

Nothing beats the sound quality of a good LP record, but if you need travel convenience, you can make a CD or Ogg Vorbis copy.

Dory Previn inspired me to pursue this project. She recorded a string of intelligent, literate albums in the 1970s, but by the early 1990s they still were not available on CD. With a little searching, I found a package named gramofile by Anne Bezemer and Ton Le designed to capture the sound of vinyl and prepare it for burning to CD. Then, along came xmcd2make by C. R. Johnson, which extends gramofile's functionality. Look at the possibilities:

  • Preserve the music on inexpensive, durable media.

  • Have each track individually accessible with timing details.

  • Encode to Ogg or MP3.

  • Apply click reduction filters to all or selected tracks.

  • Leave out unwanted songs and rearrange the order.

  • Fit two albums onto one disk.

Preparing the Hardware

Sound quality depends on many factors, as explained in the “Linux Audio Quality HOWTO”, but with a quality sound card and well-supported drivers. Try to keep the card away from other cards to minimize induced noise. Because I'm using a spare PC solely for this project, I have only two cards installed: video in the first PCI slot and a SoundBlaster Live! 5.1 in the last PCI slot. If you plan to use the PC for other tasks while capturing the LP to disk, use a kernel from the 2.4 series, apply the preempt-kernel and lock-break patches (see Resources), select the new choices under Processor type, then build and install it. I was pleasantly surprised by the quality of sound on the CD from the first LP I processed.

Minimal Software

If you simply want to burn a CD, gramofile alone does the job. Install it from an RPM or deb file. Figure 1 shows the main menu. I discuss each step further later in this article. gramofile expects a mixer called xmixer, which I found in a Debian package called mctools-lite, but in the RPM world, it is in a package called multimedia. However, there's no problem using whatever mixer you have in another window or console.

Figure 1. gramofile's Main Menu

Deluxe Software

For the encoding of songs in Ogg or MP3 format, consider taking the extra steps to install xmcd2make and its dependencies also. A bit of tedium up front will simplify the processing of every album. The xmcd2make scripts are simply that—Perl scripts whose installation amounts to make install. However, they won't work until swig, oggenc (for Ogg encoding) or lame (for MP3), mpgtx and Perl module Getopt::Long are installed. In addition, xmcd2make expects the special version of gramofile that has perl-swig extensions, with a P in the version name. So let's get to work. Because this machine is dedicated to one task, I'll do all installs as root and untar each package from /usr/local.

swig has progressed, but gramofile hasn't. Using the latest version 1.3.17, the gramofile make perl-swig failed. Using Debian's older version 1.1.p883-4 (apt-get install swig), the make completed. Here's the manual equivalent:

tar xvzf swig1.1-883.tar.gz
cd  SWIG1.1-883
./configure
make
make install

oggenc should be available as RPM or deb packages, though the name may be elusive. For Debian, I used apt-get install vorbis-tools libvorbis0. Lame may be harder to find due to patent issues, and Ogg is the politically correct choice.

mpgtx, a command-line MPEG toolbox, is a simple apt-get install mpgtx in Debian, but I installed version 1.3 from source with the classic tar, configure, make, make install as in swig above. Though pages of warnings scrolled by, it installed without complaint.

The Perl module Getopt::Long is part of Debian's 5.6.1 package, and I hope it's in yours too. On my system it's installed in /usr/share/perl/5.6.1/Getopt/Long.pm.

A manual install of gramofile with perl-swig extensions is not for the timid. It requires ncurses5-dev and doesn't install itself. You'll need to know where your Perl CORE resides, so try:

cd /usr/lib
find -name CORE
./perl/5.6.1/CORE

This reveals that my Perl CORE is at /usr/lib/perl/5.6.1/CORE. After untarring gramofile, edit the Makefile in the perl-swig subdirectory, changing the line PERLCORE = -I/usr/... to match your installation:

tar xvzf gramofile-1.6P
cd gramofile-1.6P
cd perl-swig

(edit the Makefile here)

cd ..
make
make perl-swig

Now, let's copy the executables into a directory that's in your $PATH:

cp gramofile bplay_gramo brec_gramo /usr/bin

Finally, cd into the perl-swig subdirectory, and copy two files from there into a directory in the Perl path. But first, check your Perl path for a suitable directory:

perl -e 'print join("\n",@INC), "\n"'

So, in my Debian setup:

cd perl-swig
mkdir /usr/local/lib/site_perl
cp Gramofile.pm Gramofile.so /usr/local/lib/site_perl

Finally, we're ready for xmcd2make:

tar xvzf xmcd2make-0.4.tar.gz
cd xmcd2make-0.4
make install

xmcd2make installs with a default bitrate of 128, but I prefer a higher bitrate (at the expense of larger files and longer encoding time), so I edited the file /usr/local/bin/xmcd2make and changed the bitrate to 224:

# $bitrate = 128;
$bitrate = 224;

If you can stand one more item, I recommend a mixer called umix, because it has a console version, offers numeric levels to set levels accurately and repeatably, and the ability to save or restore all settings with a single keystroke. This means the whole LP to CD process can be done on a low-end PC without even installing X. The default mixer path is /dev/sound/mixer, which you may want to adjust as follows: ./configure --with-mixer-dev=/dev/mixer. To load and save levels as an ordinary user, start umix with a config filename, like umix -f $HOME/umixrc. Press S to save the current settings and L to reload the last saved settings.

Basic Recording Procedure

Here are the steps to capture Dory's On My Way To Where album to the hard drive, then process it to arrive at a set of wav files suitable for burning an audio CD, plus a set of Ogg files for use by computers and portable players. Eventually, we'll tell xmcd2make the basename is “where”, so we name the files appropriately.

  • Position the computer near your stereo, and connect stereo line out to your sound card line in with a quality, shielded cable. You probably will need a dual RCA-to-stereo mini-plug cable to make this connection.

  • Load your mixer in one console or xterm. Load gramofile in another after changing to an empty directory on a partition with a lot of free space.

  • Use the mixer to set “line in” to record mode and to mute all other channels. You may need to bring up input gain (igain) too. This reduces background noise.

  • Use gramofile's Record audio to a sound file to capture a sample, and use the mixer to adjust levels to bring the peaks on the gramofile level meter near the top.

  • Stop sampling, and verify that a reasonable percent of samples were above 50% of max volume, a few above 90%, but that few or none were above 99% (Figure 2).

  • Set gramofile to capture side one of the LP by giving it a descriptive name, in our example, where1.wav; start playing the LP, then start capturing.

  • When side one is completed, stop gramofile and verify that the sample levels are reasonable. If not, use your mixer to adjust the levels. Some of the volume spikes are caused by clicks, so a few clipped samples are acceptable.

  • Capture side two to a file called where2.wav.

Figure 2. gramofile's Recording Information

Now we have two wav files of about 200MB each, digital representations of the sound in the vinyl grooves. This is a good time to decide whether this LP has significant surface noise—those clicks for which vinyl is famous. If the whole album is noisy, run both sides through the filter(s) gramofile offers. If only selected songs are noisy, typically the first track on each side, wait until the tracks are split.

The gramofile documentation includes a fascinating discussion (Signproc.txt) of each filter and the theory behind it. You'll notice when choosing Process the audio signal that Conditional Median Filter II already is selected. It's the most sophisticated, and I had good results with it. Clicking noises aren't obliterated, but they're greatly reduced. Multiple filters can be used, or you can use the same filter twice. I stick with one pass because when I used Conditional Median Filter II twice, there was a noticeable degradation in the music. However, the process takes only a few minutes, so feel free to experiment. The original file is preserved, and you have the opportunity to give the filtered file a meaningful name. Listen to this new wav file. If you like the result, delete the original and rename the filtered file to be the same as the original.

Before encoding any tracks, you'll want a listing of the artist name, album name and the title of every track. You can save some typing by searching freedb.org. If your album is found, click on the IDs link above the first track title, then save the page that comes up as a text file. If you prefer, simply copy the listing from this xmcd page and paste it into a text editor, ignoring any lines starting with #. Be sure to save the file as plain text into the directory where your wav files are, and name it to match. For our example, that would be where.xmcd. In either case, all we'll be using are DTITLE and TTITLE lines. For obscure LPs, I keep a copy of an xmcd file with only DTITLE= and TTITLE0= thru TTITLE10= in my home directory. It only takes a minute to copy it with a name to match the current LP, then type in the titles from the album jacket. Notice that the track listings start with zero. Here's a partial sample:

DTITLE=Dory Previn / On My Way To Where
TTITLE0=Scared To Be Alone
TTITLE1=I Ain't His Child

Our task now is to split each side into individual songs. Straight gramofile users can choose Locate tracks from the menu, then choose side one (where1.wav), click Next, click Start computation and wait for the song count to come up. If the count is not correct, try again but adjust one or more of the options before Start computation. Try reducing intertrack silence to 12 or less. Repeat for side two. When you're happy with the track counts, choose Process the audio signal; choose the side one wav file again; click Next; then, tab through to the “Next” screen if you want to use the default click filter. To use no filter, stop at the Available filters box, highlight Copy only and press the Enter key. Now tab to the Selected filters box, highlight Conditional Median Filter II and press the R key to remove it. Use the same procedure to choose a different (or additional) filter, but you must select either a filter or Copy only to process the files. Incidentally, pressing the Enter key while a filter is highlighted in the Selected filters box allows you to change specific filter settings. Finally, tab to Start and press Enter. When it completes, you should have a wav file for each track, ready for test listening and then burning.

xmcd2make users should exit gramofile, as xmcd2make's findtracks script is a wrapper around gramofile's findtracks function. Run findtracks where1.wav from the prompt to scan album side one, then compare its output with the official track listing. Type less *.tracks, and you'll see a plain-text file with start and stop timings for each track. If you see two tracks lumped together, go back to the prompt and try again with one or more of the parameters adjusted, for example:

findtracks where1.wav --min-silence-blocks 12

It's possible, though tedious, to split the songs manually. A crude alternative is to burn the whole side as a single track. In this case, use gramofile's filter, but choose Copy only (as explained above but unchecking the Split tracks option), which would do no filtering but would add timing information to the wav file, so the CD burner would know the true running time. If you find a song split in two, it's easy to edit the tracks file to merge the two, then renumber the rest of the tracks on that side and edit the Number_of_tracks= line to match. Finally, repeat the whole process for side 2.

Now, we're ready to create a Makefile, which automates the rest of the process:

xmcd2make --basename where --counts 5,5 > Makefile

This creates a Makefile that includes the timing for splitting the tracks and the album, artist and trackname information for Ogg or MP3 creation. The counts must match those in the track's files. To adjust the bitrate, add --rate 192, for example. Now simply typing make copies each track's content to a separate wav file and encodes it to an Ogg file with a descriptive name. Here's an abbreviated directory listing from our example:

Makefile                    9.5k
where1.wav                  196M
where1.wav.tracks           1.2k
where2.wav                  191M
where2.wav.tracks           1.2k
where_processed_101.wav      52M
101_Scared_To_Be_Alone.ogg  8.2M

Use make mp3 to split tracks and create MP3 files instead of Ogg files. Typing make proc simply splits the tracks, allowing you to apply a filter to selected tracks. By deleting the original unfiltered file and renaming the filtered file to the original name, make creates an Ogg file from the filtered wav file. For more options, try xmcd2make --help.

There you have it—wav files to burn to an audio CD-R and Ogg files to play back on any capable device or burn to a data CD-R. If you're new to CD burning, there are many fine HOWTOs available. Once you've set up the system, you can repeat it for stacks of albums and enjoy the results. By the way, in 2002 the last of Dory's albums finally were re-issued on CD, but I already have my Linux-made disks.

Tom Younker (tom@darecomputer.com) lives in smoggy Atlanta, Georgia with his Mac-loving wife and a basement full of Linux boxen. He also runs a consulting business.