Copying an Audio CD

This document is a little how-to for copying audio CDs with FreeBSD.

Suppose a friend of yours is a pretty good banjo player and he made a home-made audio CD of some of his music. Suppose you borrowed it and like it so much that you want a copy. Suppose your friend has given his blessing for you to make a copy.

Alternatively, suppose you have this nice CD and you want to have a copy for your car so you can listen to it even when you are not home. You believe in the fair use doctrine (still not settled legally) that you can copy music for your own use - just as long as you don't go into the publishing business by selling the copies or giving copies to all your friends (blah blah blah....)

Here's how you would go about it on FreeBSD.

Step 1: Pull the files off the existing CD.

There are many ways to do this. It seems a lot of unix gurus like to use the dd command and specify each track by device number. I find this method to be very tedius.

My preference is to use a program that is in the ports collection called dagrab1. For directions on installing this port, see the tutorial in the FreeBSD Handbook. I recommend reading the whole chapter; but if you are in a hurry, you may be able to get away with reading only section (By the way, after installing a couple ports, you should start using the port called portupgrade, explained in section 4.5.5.)

Once you have installed the dagrab port, you can probably figure out real quick how to use it by viewing its man page:

$ man dagrab
The way I would handle it is by inserting the original CD into my CD drive and typing a sequence of commands like the following:
$ cd
$ mkdir cd_work
$ cd cd_work
$ dagrab -d /dev/acd0c -a

Step 2: Convert the newly stripped wave files to raw files.

Wave files have header information (that is, information at the beginning of the file that tells a player software how to play the file. You can burn these wave files to a cd and they will play just fine but there will be a nasty pop at the beginning of each track. A raw audio format doesn't have this header on it. It's just a plain old digital sound file. To be more specific, it has a sample rate of 44100, it is in stereo and it has a 16 bit sample size (16-bit audio.) There is no need to worry here about sample rates and stuff. The files generated by dagrab are already in the proper bit-rates, etc.

I think the best program for converting one audio format to another is the tool called sox. It's in the ports collection under /usr/ports/audio/sox. I recommend installing it.

Here is how I like to convert the wave files to raw files:

$ ls *.wav |
> while read file
> do sox "$file" `basename \"$file\" .wav`.raw"
> done
basename is a tool that permits easy manipulation of a string of characters. I use it here as an in-line command between the left-quotes (`) to strip off the ".wav". Note that there is no space after the second left-quote and before the ".raw" part of the string.

If the convert was successful, remove the wave files. They are just clutter now.

$ rm *.wav

Step 3: Burn the raw tracks to a CD.

The best way to burn anything to a CD on FreeBSD - if your cd is an ATAPI (that is, NOT SCZY, and they hardly ever are these days) - is the tool burncd. The burncd tool comes stock with FreeBSD2 so you don't need to worry about installing it.

Using the tool is quite straightforward. I still recommend you take a look at the man page:

$ man burncd
Here's a decent way to burn these raw files onto an audio CD:
$ burncd -f /dev/acd0c audio *.raw fixate
Now the above command will probably take a long time to burn. Your CD drive will probably support higher burn speeds than 1x. Check the user's guide to the drive. I generally durn at 4x or 8x. My drive supports much higher burn speeds but I can generally keep myself entertained while the job is running:
$ burncd -f /dev/acd0c -s 8 audio *.raw fixate

1. The tools in this tutorial assume that you have permission to read from and write to the device that specifies your CD-RW drive. If you have recently installed FreeBSD or just re-made the devices in the /dev directory or otherwise never fooled with the default permissions of your CD-RW device, you may need to do either do all of these steps as the superuser (root) or make the device available for general users. To give users read and write privilages to your CD-RW drive do the following (or something similar - depending on what device is your CD-RW) as root:

# chmod o+rw /dev/acd0c

2. Commercial: The burncd tool is one of the things that really impresses me about FreeBSD. Linux is stuck into the mode of handling all CD burning to a SCZY drive - which hardly anyone has. All the software is built upon using the Linux SCZY burning tools. What people have to do (or the user-friendly installers have to do) is fake the SCZY tools into seeing your ATAPI CD-RW as a SCZY drive. On FreeBSD, you don't have to try to figure out how to fake the system into seeing your ATAPI as a SCZY because the burncd tool already sees it that way. If, however, you want to use one of the Linux tools, well you may find yourself doing the ol' fake-setup on your machine.

By the way, there is a graphical tool being hacked out by an enthusiast. I am very grateful for his hard work on the project. I may even try it out sometime.