Dausha CommunicationsA Resource for the Renaissance Man

Technical »

Join Wavs

Why Did I Do This?

I converted many of the CDs in my personal library into MP3s so I could listen to them at work. Among those CDs was the entire Beatles' collection. Those of you who know their music are familiar with the B side of the Abbey Road album. Pretty much the entire side is meant to be listened to in succession. So, when I randomize my music these songs got mixed like the rest.

To fix this, I decided to combine them into one big file. Being a little naiive, I figured I could just cat them together then lame them into an MP3. However, the conversion to MP3 ended with the only first track. It seems that the .wav format has headers, and lame tripped up on them. Rather, it functioned as it should, but I didn't know what I was doing. Par for the course.

CDs, the De Facto License

You know, there's another reason why it's good to rip your CDs. Owning the CD is a de facto license, your right to play the music in private. How many times has one of your CDs become scratched? I think the music industry relies upon the scratchability of CDs for repeat sales. More importantly, that's why we make backups. Now, if you use the MP3 version of the CD, you still have a fairly scratch-free original.

A Solution

I put this litte page together because I spent a good deal of time scouring the Internet for a suitable How-To. No single source was found, but several pages that in combination work. So I am obliged to write one. Here goes:

  • First, let's ensure we're all on the same sheet of music. I used

lame version 3.93 on Linux, and sox version 12.17.3. I'm sure these techniques will be forward compatible over time.

  • You need to first rip the .wav from the CD using your favorite CD

ripping app (I used cdparanoia, but don't encode. Just rip. Then, convert each of the .wav files into .raw with sox like this:

sox -t wav -r 44100 -s -w -c 1 infile1.wav outfile1.raw

sox -t wav -r 44100 -s -w -c 1 infile2.wav outfile2.raw

I did this because the .raw format is headless. I suppose the file extension is self-explanitory.

  • Next, you need to join the .raw files together. Pretty simple:

cat outfile1.raw outfile2.raw > combined.raw

  • Then, you'll need to convert the combined.raw file back into a

.wav file. I made a short little Bourne script gleaned from the Linux CD Writing website (called ext):

#!/bin/sh
exec dd if=$1 bw=17640 skip=$2 count=$3

This lets me do the same command repeatedly if I chose. Here's how to use it to make a .wav file:

ext combined.raw 0 (size_of_file) | sox -t raw -r 44100 -s -w -c 2 - combined.wav

Now, just use lame to convert the file to an MP3.

lame -h -b 128 combined.wav combined.mp3

  • Now you can listen to your new MP3 in a commie free world

(appologies to Burke Breathed).

Better Solution

Is the "Six-Step Program" too much typing? The essence of any good programmer contains a dash of hubris, a smiggin of ??, and a pinch of laziness. So, once I got the recipe down, I wrote this little Perl "program":/local/downloads/joinWav.txt. It takes the files passed as arguments, and joins them together in the order they were passed, and crates a file called 'combined.wav'. So, you call it thus:

perl joinWav.pl infile1.wav infile2.wav infile3.wav

It even cleans up after itself. :-)

Process Improvement

Let me know if this is useful to you, or what I could do to make this more useful. Email me at ameen (at) dausha (dot) net. (:commentable:)