Ripping Analog Music to Digital Audio Tracks

By Van Emery



Introduction

If you are like me, you have thousands of dollars worth of LP records, 45's, cassettes, and reel-to-reel tapes in your collection. I am perfectly satisfied with my stereo equipment, but I would like a convenient way to archive and listen to all of this music. I am not about to repurchase all of the same music (and in some cases, it is not available) in CD, DVD-A, or SACD format. No freaking way. I want it in a portable format, so that I can listen to it on hardware players, new car stereos, and on my computers. I also want to be able to make my own collections of music, so that many of them fit on the same CD, disk, or flash card.

This is clearly a "fair-use" scenario, no different from putting songs from an LP or CD that you purchased onto a Sony mini-disc or cassette tape. It will also allow you to listen to your own legally purchased music CDs that have been crippled by the recording industry to prevent playing in computer CD-ROM drives. I make no apologies for the fact that I frequently have my laptop with me, but not a separate CD player.

This tutorial/manual will show you step-by-step how to convert analog audio input into compressed digital formats so that you can:

Not only that, but it shows you how to perform these functions on a GNU/Linux system, where the cost is minimal...just a little bit of your time.

This is NOT a document advocating music piracy or illegal file-sharing. There are plenty of sites devoted to that topic, and the professional pirates don't need any instructions, anyway. This is all about how YOU can control your music collection. That being said, the RIAA must be smoking something if they think that their DRM schemes are going to work long term.

As long as music can be tapped off of headphone jacks or speaker wires, it can be copied at minimal cost with reasonable quality.


Music Encoding Overview

The diagram below shows how analog audio or CDDA input is converted into compressed digital files. As you can see, there are multiple ways to accomplish this:

flowchart


Super Expensive Tools of the Trade

In the pictures below, you can clearly see how complex and expensive encoding music will be. You should be shaking with fear...

boombox cord soundcard


Recording Music from External Sources

The first step is to record music from external players, which could be cassette decks, turntables, CD/DVD players, reel-to-reel, etc. This process consists of converting the analog audio input into an uncompressed format, such as AIFF, WAV, or raw encoded files. AIFF was developed and used by Apple, and WAV was developed and used by Microsoft. Raw encoding is just what it sounds like, a file full of digitized sound bytes. It has no header, so if you use raw encoding, you will have to manually specify things like sample rate, number of bits per sample, whether or not the data is big-endian or little-endian, etc. AIFF and WAV have headers that include this information, which simplifies things. There is no difference in quality between AIFF, WAV, and raw encoding. The file sizes are approximately the same size as well. Here is the formula for the audio data size within the file:


File size in bytes = bits (8/16/24) x channels (1,2,...) x sample rate (Hz) x seconds / 8


For standard CD audio (16 bit, 2-channel, 44.1kHz), your files will be roughly 10MB per minute of music.

Two programs which can record audio input from the sound card to disk are rawrec and sox. Sox is more versatile, since it will save in all of the aforementioned formats, while rawrec will only save in the raw encoding. They both work as advertized, but I recommend sox for several reasons:

Your sound card also plays a role in what quality your recording can achieve. Sound cards will have minimum and maximum sample rates, a limit on how many bits per sample the encoding can have, and a specific number of channels. Make sure to look up the specifications for your sound card. 24-bit sound cards are now commonly available, and 16-bit sound cards are both ubiquitous and inexpensive.

Note:   If you only want to rip a non-protected audio CD from your computer's CD-ROM to an uncompressed digital format, then you just need to use cdparanoia or cdda2wav. These are very stable, high-quality CDDA to WAV/AIFF/raw programs that can be used from the command line or through a GUI front-end like Grip. These tools are included with many GNU/Linux distributions, including Red Hat.

For the purposes of this HOWTO, we will use sox to record audio input into AIFF or WAV files. Here are the specs on my test system:

Step 1: Connect external music player

Using a 3.5 mm mini audio cable, I connected the line-out/headphone jack on the Sanyo unit to the line-in jack on the sound card. I used a cassette tape and a CD for sample music sources for the test. You could just as easily use your turntable or reel-to-reel unit, or even a digital music player like an i-Pod.

If your audio unit only has a headphone jack for output, make sure you keep the volume control at a low setting. We will have to adjust the input gain/levels on the sound card, and cranking the volume control on your music player could potentially cause damage to your sound card.

Step 2: Make sure that you have the required software

We want to make sure that sox and aumix are installed. Aumix is a console-based mixer control for your sound card. Both packages are usually installed by default with Red Hat 9, but we will check:

$ rpm -q aumix
aumix-2.7-16
$ rpm -q sox
sox-12.17.3-11

If you are missing these packages, you will need to download and install them and install before proceeding!

Step 3: Configure your mixer settings

From the command line, enter this command:   aumix

You will be shown an interface where you can adjust the various mixer controls. Here is the setup I used in order to record from my player. You will have to adjust your mixer controls for your specific environment: aumix-image

Step 4: Record Tracks

We will record one track from cassette tape in WAV format, and one track from a CD in AIFF format. We will do this from the command line. The rec command is actually a front-end for sox. Its input is the sound card, its output is a file. We will then play the files to make sure that they were recorded properly, with the right mixer settings. The play command is also a front-end for sox, with its output being directed to the sound card.

First, let's record the song "Numb" (track #7) from a Portishead CD:

$ rec -c 2 -r 44100 -s w portishead.aiff
Send break (control-c) to end recording
$

Now, we will record "Bull in the Heather" by Sonic Youth from cassette tape:

$ rec -c 2 -r 44100 -s w sonicyouth.wav
Send break (control-c) to end recording
$

Check out the size of the files:

$ ls -l sonic*wav
-rw-rw-r--    1 tamen  tamen  31973420 Nov  5 23:29 sonicyouth.wav
$ ls -l port*aiff
-rw-rw-r--    1 tamen  tamen  41364560 Nov  5 23:02 portishead.aiff

Now play the files and make sure that your mixer settings were reasonable:

$ play portishead.aiff

$ play -V sonicyouth.wav
sox: Detected file format type: wav
 
sox: Chunk fmt
sox: Chunk data
sox: Reading Wave file: Microsoft PCM format, 2 channels, 44100 samp/sec
sox:         176404 byte/sec, 4 block align, 16 bits/samp, 31973376 data bytes
sox: Input file sonicyouth.wav: using sample rate 44100
        size shorts, encoding signed (2's complement), 2 channels
sox: Input file sonicyouth.wav: comment "sonicyouth.wav"
 
sox: Output file /dev/dsp: using sample rate 44100
        size shorts, encoding signed (2's complement), 2 channels
sox: Output file: comment "sonicyouth.wav"

(Optional): Record Tracks with a GUI

One thing you may have noticed is that you may inadvertently leave too much space before or after the track when recording manually. There are command-line tools to deal with this, but they are a pain to work with. I found a nice Tcl/Tk GUI front-end for sox called Sound Studio. It is a sound editor that lets you see the record levels and cut out unwanted audio samples. Here is a screen shot:

VU Meter Sound Studio

Installing Sound Studio is very straightforward; as long as you already have sox and Tcl/Tk, it should be a snap. Just follow the instructions in the README file after unpacking the tarball. After you have installed it, you can invoke it simply by entering studio at the command line. After a few minutes of play, you will have no problems using this excellent tool. Once you have recorded a song, you can edit the beginning and end to cut out unwanted silence. You can then click the "Save" or "Save As" menu items and save to various audio file formats, such as WAV, AIFF, and raw.

I have also heard that Audacity is an excellent sound recorder/editing tool, but I have not used it. It may be worth a try.


Compressing the Music

Now that the music has been saved on disk in a digital format, it needs to be compressed for practical use. There are two types of compression we can perform on the music:  lossy compression and lossless compression. Lossy compression includes formats such as mp3, Ogg Vorbis, AAC, and WMA. Lossless compression includes formats like FLAC and Monkey's Audio (.ape) format. For the purposes of this HOWTO, we will use lossy compression formats that are well-documented and easily available to the Open Source community:  .mp3 and .ogg.

Note:   The FLAC encoder is easy to use as well, and you should definitely try it if you are interested in lossless compression.

mp3 is the most well-known compressed audio format. It is also outdated, patent-encumbered, and freqently maligned by the RIAA. The facts:  mp3 support is ubiquitous, there are no DRM controls, and software for Linux and FreeBSD is readily available. All of this makes the mp3 format worthwhile for our purposes.

Ogg Vorbis is an up-and-coming compressed audio format. It has better sound quality than mp3 at the same bitrates, and for music files of comparable quality, the file size is noticeably smaller. Furthermore, Ogg Vorbis tools and players are free for multiple operating systems, the software is Open Source and patent free, and many software and hardware players now support it. It is my preferred compressed audio format. Oh, did I mention that Ogg Vorbis is not encumbered with any DRM nonsense? Red Hat 9 includes Ogg Vorbis tools and players.

Using LAME to encode our music files to .mp3 format

In order to convert our .wav and .aiff files into much smaller .mp3 files, we will use the excellent open source encoder, LAME. This is not included in Red Hat 9, you will have to compile it from source code or download an RPM. I found a good LAME RPM at FreshRPMs.Net.

For portishead.aiff, which came from a CD, we will use medium-quality encoding. For sonicyouth.wav, which came from an old cassette tape, we will use a lower quality encoding. First, the Portishead track:

$ lame -q 2 --tt Numb --ta Portishead --tl Dummy --ty 1994 --tn 7 portishead.aiff portishead.mp3
LAME version 3.93 MMX  (http://www.mp3dev.org/)
CPU features: i387, MMX (ASM used), SIMD
Resampling:  input 44.101 kHz  output 44.1 kHz
Using polyphase lowpass  filter, transition band: 15115 Hz - 15648 Hz
Encoding portishead.aiff to portishead.mp3
Encoding as 44.1 kHz 128 kbps j-stereo MPEG-1 Layer III (11x) qval=2
    Frame          |  CPU time/estim | REAL time/estim | play/CPU |    ETA
  8976/8978  (100%)|    0:48/    0:48|    0:49/    0:49|   4.8315x|    0:00
average: 128.0 kbps   LR: 1 (0.01114%)   MS: 8978 (99.99%)
 
Writing LAME Tag...done

$ ls -al portishead*
-rw-rw-r--    1 tamen  tamen  41364560 Nov  5 23:02 portishead.aiff
-rw-rw-r--    1 tamen  tamen   3753400 Nov  7 16:18 portishead.mp3

As you can see, the mp3 file compression is at an 11:1 ratio. We can test our mp3 file by playing it with mpg123 or XMMS.

Just for grins, let's encode the same file as a VBR (variable bit rate) file instead of a CBR (constant bit rate) file, which is the default. Here we go:

$ lame --vbr-new --tt Numb --ta Portishead --tl Dummy --ty 1994 --tn 7 portishead.aiff portisvbr.mp3
LAME version 3.93 MMX  (http://www.mp3dev.org/)
CPU features: i387, MMX (ASM used), SIMD
Resampling:  input 44.101 kHz  output 44.1 kHz
Using polyphase lowpass  filter, transition band: 17960 Hz - 18494 Hz
Encoding portishead.aiff to portisvbr.mp3
Encoding as 44.1 kHz VBR(q=4) j-stereo MPEG-1 Layer III (ca. 9.1x) qval=2
    Frame          |  CPU time/estim | REAL time/estim | play/CPU |    ETA
  8976/8978  (100%)|    0:52/    0:52|    0:59/    0:59|   4.4391x|    0:00
 32 [   1] *
 40 [   0]
 48 [   0]
 56 [   1] *
 64 [   8] *
 80 [ 689] *********************
 96 [3817] ***************************************************************************************************************
112 [2476] *************************************************************************
128 [ 869] %*************************
160 [ 676] %*******************
192 [ 240] %******
224 [ 139] %****
256 [  55] **
320 [   8] *
average: 112.8 kbps   LR: 36 (0.4009%)   MS: 8943 (99.60%)
 
Writing LAME Tag...done

$ ls -al portis*
-rw-rw-r--    1 tamen  tamen  41364560 Nov  5 23:02 portishead.aiff
-rw-rw-r--    1 tamen  tamen   3753400 Nov  7 16:18 portishead.mp3
-rw-rw-r--    1 tamen  tamen   3302156 Nov  7 15:39 portisvbr.mp3

This results in a VBR file with a 12.5:1 compression ratio, which is not bad. Unfortunately, not all players can decode VBR mp3 files.

Now, let's encode sonicyouth.wav to mp3. Since it is being pulled off of a tape, I will use a lower quality setting than I did with the track that was recorded from CD analog output. Here we go:

$ lame -q 5 --tt "Bull in the Heather" --ta "Sonic Youth" --tl "Exp.Jet Set" --tn 2 sonicyouth.wav sonicyouth.mp3
LAME version 3.93 MMX  (http://www.mp3dev.org/)
CPU features: i387, MMX (ASM used), SIMD
Resampling:  input 44.101 kHz  output 44.1 kHz
Using polyphase lowpass  filter, transition band: 15115 Hz - 15648 Hz
Encoding sonicyouth.wav to sonicyouth.mp3
Encoding as 44.1 kHz 128 kbps j-stereo MPEG-1 Layer III (11x) qval=5
    Frame          |  CPU time/estim | REAL time/estim | play/CPU |    ETA
  6938/6940  (100%)|    0:31/    0:31|    0:33/    0:33|   5.7426x|    0:00
average: 128.0 kbps   LR: 1546 (22.27%)   MS: 5395 (77.73%)
 
Writing LAME Tag...done

$ ls -l sonicyouth*
-rw-rw-r--    1 tamen  tamen   2901599 Nov  7 22:03 sonicyouth.mp3
-rw-rw-r--    1 tamen  tamen  31973420 Nov  5 23:29 sonicyouth.wav

We can now play all of the mp3 files we have just created with mpg123, XMMS, or any other media player that you have that supports mp3 format. Of course, your XMMS player must have the mp3 input plug-in installed. By default, mp3 support is not included with Red Hat 9 due to patent and licensing restrictions.

Encoding Ogg Vorbis files with oggenc

Let's now run through encoding the same songs with oggenc, which comes with Red Hat 9. Oggenc creates VBR files by default. We will use a decent quality setting for the Portishead track from CD, and a lower quality setting for the Sonic Youth track from cassette tape.

First, let's take care of encoding the Portishead track:

$ oggenc -q 4 -a Portishead -t Numb -l Dummy -o portishead.ogg portishead.aiff
Opening with aiff module: AIFF/AIFC file reader
Encoding "portishead.aiff" to
         "portishead.ogg"
at quality 4.00
        [100.0%] [ 0m00s remaining] \
 
Done encoding file "portishead.ogg"
 
        File length:  3m 54.0s
        Elapsed time: 1m 10.2s
        Rate:         3.3380
        Average bitrate: 118.8 kb/s
 
$ ls -l portis*
-rw-rw-r--    1 tamen  tamen  41364560 Nov  5 23:02 portishead.aiff
-rw-rw-r--    1 tamen  tamen   3753400 Nov  7 16:18 portishead.mp3
-rw-rw-r--    1 tamen  tamen   3486020 Nov 12 15:12 portishead.ogg

Now, let's encode some Sonic Youth at a relatively low quality setting, which is just fine for recording tapes:

$ oggenc -q 2 -a "Sonic Youth" -t "Bull in the Heather" -l "Exp.Jet Set" -o sonicyouth.ogg sonicyouth.wav
Opening with wav module: WAV file reader
Encoding "sonicyouth.wav" to
         "sonicyouth.ogg"
at quality 2.00
        [ 99.9%] [ 0m00s remaining] -
 
Done encoding file "sonicyouth.ogg"
 
        File length:  3m 01.0s
        Elapsed time: 0m 56.6s
        Rate:         3.2035
        Average bitrate: 91.1 kb/s
 
$ ls -l sonicyouth*
-rw-rw-r--    1 tamen  tamen   2901739 Nov  7 17:18 sonicyouth.mp3
-rw-rw-r--    1 tamen  tamen   2067981 Nov 12 15:18 sonicyouth.ogg
-rw-rw-r--    1 tamen  tamen  31973420 Nov  5 23:29 sonicyouth.wav

You can now play the new Ogg Vorbis files with XMMS or with ogg123, the command-line player.   ogginfo will give you info on the music file. One very neat feature of Ogg Vorbis is that it actually sounds pretty good at low bitrates. If you use the -q 0 or -q 1 settings when encoding (approx 54 kbps + 68 kbps), you will get a small file that sounds good, at ~ 20:1 - 25:1 compression ratios. This is ideal for e-mailing or posting sound clips on web sites. Of course, -q -1 with mono (instead of stereo) will give you a really small file.


Conclusion

As you can see, there are plenty of open-source audio tools available for Linux. These tools will allow you to record audio from any source to convenient digital formats. This gives you complete control over your music, including the ability to archive and to create customized collections of music for mobile playback.

Have fun!


Resources

Relevant Manpages






Back to Linux Gouge...

Valid HTML 4.01!