...making Linux just a little more fun!

<-- prev | next -->

Ogg, WAV, and MP3

By Edgar Howell

Disclaimer

What is described in the following may be illegal where you live. Where I live, the law permits making a small number of copies of the contents of legally acquired media for personal use as long as this does not involve circumventing copy protection. Strangely enough, "personal use" includes giving a copy to close relatives. And "small number" certainly is well under double-digits, but to my knowledge the courts have not yet made it explicit. You didn't expect the legislators -- politicians! -- to do that in the course of creating the legislation, did you?

For obvious reasons I would have much preferred to use the Ogg Vorbis format. Unfortunately the music player on the Zaurus couldn't handle Ogg, so MP3 it was. IANAL (I Am Not A Lawyer), I may be wrong, but as best I can determine, conversion to MP3 is permitted.

(It is interesting to consider the obligation of those subject to the law to observe it. Reasonable enough, right? When they can't even understand it without professional help?!)

From these considerations, I conclude that it would be prudent to remove all files created as described below before taking any storage medium across any international border. As usual, your call.

CD to Hard Disk

The first step in getting some music onto the Zaurus was to copy it to the hard disk on a PC - but never having done anything of the sort in the past, it was time to consult the oracle:

web@lohgoDELL:/tmp/CD> apropos CD
rsyncd.conf (5)      - configuration file for rsync in daemon mode
reader.conf (5)      - configuration file for pcscd readers' drivers
pcscd (8)            - PC/SC Smart Card Daemon
cdparanoia 9.8 (Paranoia release III libcdio) (1) [cd-paranoia] - an audio CD reading utility which includes extra data verification features
Encode::EBCDIC (3pm) - EBCDIC Encodings
...

This went on for a while but fortunately the reference to cd-paranoia was early in the list.

The man-page even included an example for an entire CD, "cd-paranoia -B", which is basically what I used. This simply puts the entire contents of the CD into the current directory with names like "track01.cdda.wav".

WAV to Ogg

WAV files are, well, sizeable. That made it worthwhile looking into conversion into another format.

So here is a script to convert from WAV to Ogg:

#!/bin/bash

/usr/bin/oggenc track$1\.cdda\.wav -o $1_$2\.ogg
/bin/rm track$1\.cdda\.wav

It is executed as follows:

./wav2ogg 01 Melanie=The_Nickel_Song

to convert 'track01.cdda.wav' into '01_Melanie=The_Nickel_Song.ogg'.

In fact, if you start cd-paranoia in one window and wait until the first track is available, in another window you can almost keep up with it converting formats and assigning reasonable names. It takes about 15 to 20 minutes to do a CD.

[ Conversely, you could automate the process with this timely 2-cent tip. :) -- Ben ]

There are "better" approaches. You can create playlists and go out to the Internet to get track information. But my goal was to have a convenient may of occasionally copying a CD to the Zaurus to be listened to for a while before erasing it to recover space.

Ogg to WAV

Unfortunately the Zaurus doesn't handle Ogg - at least I haven't been able to figure it out. Even more unfortunately, because of the size of the WAV files, the script erases them after conversion - but I didn't want to have to read the CD again and then go through the process of assigning titles.

Well, careful reading of the documentation pointed me at 'ogg123' and resulted in the following script:

#!/bin/bash

/usr/bin/ogg123 -d wav -f $1\.wav $1\.ogg

It is executed as follows:

./ogg2wav 01_Melanie=The_Nickel_Song

to convert '01_Melanie=The_Nickel_Song.ogg' into '01_Melanie=The_Nickel_Song.wav'

Interestingly enough, this is extremely fast.

WAV to MP3

This is where things got a bit complicated. MP3 is subject to certain restrictions and SuSE no longer includes anything dealing with it. But there was a reference to LAME, which I obtained from Sourceforge.

The directions provided by SuSE seemed a bit complicated to me -- construct an RPM out of a tar-ball and then install it? As root I just did the following:

cd /usr/src/packages/SOURCES/lame-3.93.1
./configure
make
make install

Having done this, the following script

#!/bin/bash

/usr/local/bin/lame track$1\.cdda\.wav -o $1_$2\.mp3
/bin/rm track$1\.cdda\.wav

can be executed as follows:

./wav2mp3 01 Melanie=The_Nickel_Song

to convert 'track01.cdda.wav' into '01_Melanie=The_Nickel_Song.mp3'

For the sake of completeness I should mention that there is an inconsistency in the names used in all that fumbling about, sometimes 'cdda.wav' and sometimes just 'wav'. This merely reflects the status as work in progress. Ultimately I used the following two scripts ('ogg2wav2mp3' and 'wav2mp3_2') to convert an entire CD in its own directory from OGG to MP3 all at once:

#!/bin/bash

for i in *.ogg;do /tmp/CD/ogg2wav $(basename $i .ogg);echo $? $i;done
for i in *.wav;do /tmp/CD/wav2mp3_2 $(basename $i .wav);echo $? $i;done
rm *.wav

and

#!/bin/bash

/usr/local/bin/lame $1\.wav -o $1\.mp3

File Sizes

It is interesting to note the differences in file sizes.

web@lohgoDELL:/tmp/CD> ll *01*
-rw-r--r-- 1 web users  3682219 2006-07-29 15:47 01_Melanie=The_Nickel_Song.wav.2.mp3
-rw-r--r-- 1 web users  3087829 2006-07-29 15:45 01_Melanie=The_Nickel_Song.wav.2.ogg
-rw-r--r-- 1 web users 40581452 2006-07-29 15:51 01_Melanie=The_Nickel_Song.wav.2.ogg.2.wav
-rw-r--r-- 1 web users 40581452 2006-07-29 14:34 track01.cdda.wav

And interestingly enough, converting back to WAV produces a file of the same size but it isn't identical.

web@lohgoDELL:/tmp/CD> diff 01_Melanie\=The_Nickel_Song.wav.2.ogg.2.wav track01.cdda.wav
Files 01_Melanie=The_Nickel_Song.wav.2.ogg.2.wav and track01.cdda.wav differ

Presumably such manipulations will have an impact on the quality of the recording, but a mobile music player certainly can't claim to be high-fidelity - and I am extremely happy with the sound on the headphones.

Talkback: Discuss this article with The Answer Gang


Bio picture Edgar is a consultant in the Cologne/Bonn area in Germany. His day job involves helping a customer with payroll, maintaining ancient IBM Assembler programs, some occasional COBOL, and otherwise using QMF, PL/1 and DB/2 under MVS.

(Note: mail that does not contain "linuxgazette" in the subject will be rejected.)

Copyright © 2006, Edgar Howell. Released under the Open Publication license unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 131 of Linux Gazette, October 2006

<-- prev | next -->
Tux