FLAC to Audio CD burning on Linux and Mac OS X

I went through all the work described in the rest of this post, typed it up, then while putting in links found this blog post that explains the same thing and includes a short script for the whole thing. Oh, well.

Some years ago I backed up our music CD collection to disk, settling on what seemed at the time to be the smallest lossless format, one that would keep for a long while and allow restoring the original CDs. I used cdparanoia to make one flac file per cd, with a cue file of track information embedded as metadata. A program called flacenstein made that easy, and with some tweaking made it easy to produce separate ogg, aac, or mp3 files. Fast-forward to now, our CD collection is in storage with most of our furniture as we prepare to build the rest of our house in the bush, the music collection is all on a 60GB ipod and in the flac files on our server, and I finally have a reason to turn one of those carefully saved flac files back into its original audio CD.

It was surprisingly difficult to find out how to use free software to burn the original audio CD from the flac file that is supposed to contain all of the necessary information to do just that. Google searches turned up many proprietary cd burning programs for Windows, information on ripping to flac, and information on converting flac to individual ogg and mp3 files. I even found people talking about the many threads of people asking about how to restore an audio CD fthat had been archived as flac, but most of the answers I found were to use a closed source Windows program named EAC (Exact Audio Copy). Well, looking at EAC, which is free (as in beer), perhaps I should just have fired up a virtual Windows machine in Parallels and used that, but I was stubborn about getting something that I could use on my MacBook, or at least on a linux machine.

Now that I have found out how, I want to document it here where I will find it easily when in a year or three I have to do this again. This is how I burned a single flac file with cue track metadata to an audio CD, on my MacBook, using free tools that are available on typical Linux systems too.

The tools required are FLAC and Cdrdao. Both are available on fink and macports. I use fink and the version of flac there seemed old, so I downloaded the latest sources and built it myself. The first attempt failed, but searching revealed that the flac build has to be configured with the –disable-asm-optimizations on an Intel Mac OS. I chose build it to install in fink’s directories. I downloaded and unpacked the tar file, changed into the directory and:

./configure --prefix=/sw --disable-asm-optimizations
make check
sudo make install

FLAC has an extremely extensive test suite run by make check which seems to run for hours. If you want to be absolutely sure that the build properly implements the lossless compression algorithms with no errors, start it up before you go to bed. I don’t really know how long the test takes as I forgot to say ‘time make check’. Maybe it was about to finish before I got tired of waiting.

Installing flac also installs metaflac, which handles the metainformation stored in the flac files.

Cdrdao had a recent version in fink so I just installed it using ‘fink install cdrdao’.

The next steps are to extract the metainformation into a cue file and the audio information into one big wav file. You have to have enough disk space to hold the uncompressed audio cd wav file, which on a full cd is around 700MB.

metaflac --export-cuesheet-to=foo.cue path_to_flac_file.flac
flac -d -o foo.wav path_to_flac_file.flac

Where I wrote foo.cue and foo.wav you can use any name you want. These files will be discarded when you are done. The path_to_flac_file.flac is the flac file which can be in any directory you want as long as you specify it here.

Next edit the cue file to make it refer to the wav file you have just created. The first line will begin withthe keyword FILE followed by the flac file name in quotes and the keyword FLAC. Change that to refer to the wav file in the current directory, like so it says something like

FILE "foo.wav" WAVE

Now you can optionally use cdrdao to look up the CD information in the cddb (freedb) database on their servers, which should make sure that foo.cue contains complete and accurate information.

cdrdao read-cddb foo.cue

Finally, put the blank CD in the drive and use this command to burn the wav file that is listed in the cue file to the CD:

sudo cdrdao write --device IODVDServices --driver generic-mmc foo.cue

You don’t have to use sudo, but burning as root allows cdrdao to use some real time scheduling trick that makes it less likely to get an underrun.

Older Macs that have a drive that doesn’t handle DVDs might use the device IOCDServices.