# a blog about things that I've been thinking hard about

# How to Create an Audio CD Using Sox and InfraRecorder

23 January, 2008
How to create an audio CD using the open-source applications SoX and InfraRecorder.
by Philip Dorrell

## Motivation

I had recorded a large number (112 to be exact) of small WAV files on my Philips MP3 player, and I wanted to write them to an Audio CD. I found that this process was either impossible or not straightforward with any of the commercial software installed on my computer, including Windows Media Player (although I later found this advice on how to deal with the problem that Windows Media Player v11 doesn't just let you point to a directory full of files and say "burn these!").

So I decided that I should be able to use open source software to do the job.

I read that InfraRecorder can write Audio CDs. However, when I attempted to write a CD from my recorded WAV files, I got the following message:

i.e. Inappropriate audio encoding in file: '/cygdrive/D/Recorded/Voice/VOICE001.WAV'.

At this point I learned that there is more than one kind of WAV file, and the kind of WAV file I had recorded on my MP3 player was not the kind of WAV file that InfraRecorder was willing to write to a CD.

No doubt future versions of InfraRecorder will include automatic conversion, but for the moment I had to find a way to convert my files.

## SoX

The most popular and/or recommended open-source sound conversion utility is SoX, so I downloaded the Windows version of that program.

Unfortunately when InfraRecorder tells you that your WAV files have the wrong encoding, it doesn't tell you what the correct encoding is. So I had to look up information about Audio CD tracks, and relate the details to the Sox options, as described, for example, here.

There turn out to be four relevant characteristics of CD audio files:

- Signed integer
- 16 bit
- 44100 Hz sample rate
- Stereo

Translated into Sox options, this requires a command line such as the following:

    sox VOICE001.WAV -s -w -c 2 -r 44100 soxed/VOICE001.WAV

where `VOICE001.WAV` is the original file and `soxed/VOICE001.WAV` is the output file.

## A Ruby Script to Loop Over the Input Files

Because I had 112 files and because I didn't want to execute a command 112 times, I needed a way to loop over my WAV files. I know you can do it using a Windows batch file, but I prefer to write even simple scripts in a proper programming language, so I used the following Ruby script:

    soxExecutable = "c:/Users/MisterPD/bin/sox.exe"

    Dir.glob("*.WAV").each do |file|
      command = [soxExecutable, file, "-s", "-w", "-c", "2",
                 "-r", "44100", "soxed/#{file}"]
      puts " #{command.inspect} ..."
      system(*command)
    end

(For some reason I got messages like:

    c:/Users/MisterPD/bin/sox.exe: Premature EOF on .wav input file

on each file, but the output files seemed to be complete, so I don't know if that message is something that matters at all.)

## Burning the CD in InfraRecorder

Having prepared my files, it was then straightforward to burn a CD from InfraRecorder. The main steps to do this are:

- Start InfraRecorder.
- Choose "File/New Project/Audio CD" from the menu.
- Click "No" on the dialog asking if you want to save changes to the existing project.
- In the Explorer View, navigate to the directory containing the converted WAV files.
- Select files and add them to the project (if you have too many files, you might have to determine how many you can choose without exceeding the available space on the CD)
- Sort on "Title" column to get the tracks ordered alphabetically by file name.
- Click the "Burn current compilation to a physical compact disc." button.
- Click "OK" on the dialog
- Wait ...
- Click "OK" when it's finished

## Software Versions Used

- Operating System: Microsoft Windows Vista Home Premium
- Sox 12.18.1 for Windows
- InfraRecorder 0.44.1.0 for Windows
- Ruby 1.8.6 for Windows

Vote for or comment on this article on Reddit or Hacker News ...