Citadel Forums

Company Information

Information Request

Linux How-to Guides

ADSP 21xx
Digital Signal Processing

SW Utilities

On-line Order Form

Linux Support

Windows Support


Have you found this site useful? Did we save you time? Did we cure your head-ache? Is your hair growing back now?

Please make a donation to help with maintenance.

MP3 to Ogg Howto

Mandrake 10.1, 2005

Herman Oosthuysen


A few years ago, I encoded my whole CD collection into the compressed .ogg format using Grip. I hoped that the free format would eventually take over from MP3, since it will save the manufacturers of music players some money. Well, it didn't.

While it is good for playing music at home, my son has a problem loading his Sony MP3 player with songs, so I needed a simple way to convert my bazillions of Ogg files to MP3 format, without destroying the original Ogg files. It turned out that the veritable Sox program can do this, but the required libraries for MP3 encoding are not part of the Mandrake 10.1 distribution and some fixes were required to make it work.

As the original Ogg files were very good quality, the conversion worked fine and my son is ever grateful to the Sox and Lame teams.

Note that this same method can be used to convert the other way from MP3 to Ogg, with a minor tweak to the conversion script, but since these formats are very lossy, some quality is lost in the conversion and more so, going from the inferior MP3 to Ogg. However, if you swear that you can hear an irritating difference in quality, go to a few heavy metal concerts, stand close to the speakers all night long and after that you won't hear a quality difference anymore...

Required Libraries

The required library libmad is part of Mandrake and is probably already installed. Do a whereis libmad and if you can't find it, use rpmdrake to install it, or get it on the web and install it from source, same as the example below.

You need to compile the libmp3lame library. It is hidden on the Lame Sourceforge site. Get it from here:

$ tar -zxvf lame-3.96.1.tar.gz
$ cd lame[tab]
$ ./configure
$ make
$ su
# make install

La voila!

SOX - Sound Exchange

Sox is the swiss army knife of audio. It can do pretty much anything pretty well.

Get sox here:

$ tar -zxvf sox-12.17.7.tar.gz
$ cd sox[tab]
$ ./configure
$ make
$ su
# make install

Look at the end of the make output and confirm that MP3 encoding is OK.


Now you probably have two copies of sox on your machine, the old one in /usr/bin and the new one in /usr/local/bin. Let's fix that using a symbolic link:

# cd /usr/bin
# rm sox
# ln -s /usr/local/bin/sox sox

Test sox and if necessary fix the library path with a link:

$ sox -h

Sox complained to me that it could not find the lame library, so I fixed it with a couple of links:

# cd /lib
# ln -s /usr/local/lib/
# ln -s /usr/local/lib/

Test sox again, with sox -h. This time it was OK for me. I do not understand why these library links are required - since sox was compiled from source, the library path should be resolved. Anyhoo, adding the links make it work.


All my ogg files are in a tree under /data/ogg. I went there and made a little script called ogg2mp3:

#! /bin/bash
# convert large ogg library to mp3
# requires sox, libmad and libmp3lame libraries
# .ogg files will remain and sox will create .ogg.mp3 files
# Can't remember where I got this neat find command execute trick from:
find . -name \*.ogg -print -exec sox {} {}.mp3 \;

Make the script executable and run it.

$ chmod 755 ogg2mp3
$ ./ogg2mp3

That took a long, long, long time to run - about 3 days, but the results are good and I share the library with the other machines in the house via Samba, although streaming it via Apache Mod-mp3 would be uber cool - maybe I'll try that one day.

Separating the Chaff

The above script will create *.ogg.mp3 files in the same directories as the original *.ogg files. You may want to separate these into two trees, but how?

One way is to use the cp or mv command with the -a switch, but if cp can't find a match in the current directory, then it will exit, without searching the tree for a match. You could get around that by making a dummy .ogg file in the top level directory to get the thing started, but that feels a bit clunky.

Another way is to use the tar command to backup the files you want and then untar the archive to create the new tree, but that requires a lot of disk space and feels a bit clunky too.

A third way is to use the rsync command. Rsync is a program that was designed to make backups of directory trees between different machines, over a network, but it can also be used as a better copy command. For full details, read the man page, since it is very powerful and easy to use. To separate the ogg and mp3 files, go to the top directory and try this:

$ cd ~/music
$ mv ogg vorbis
$ rsync -r --exclude '*ogg' vorbis mp3

First we copy all the mp3 files from the vorbis directory into a new mp3 tree. Once you verified that all files transferred properly, you can delete the original mp3 files from the vorbis tree, but be careful when deleting files recursively with the -f option. I suggest that you first delete a few without the f and manual confirmation, then press Ctrl-C to terminate the remove process and add the f:

$ cd ~/music
$ cd vorbis
$ rm -Rf *mp3

Now things should be separated into two trees.

Streaming Audio with Edna

Well, no sooner had I written the above, I went and looked for simple streaming solutions. I know I can set up Apache to do it, but it sounded like work. After a bit of searching on Sourceforge, I found Edna:

This proved to be the simplest streaming service ever! Download the tar ball, untar it, edit the file edna.conf to point it to your music collection and run it - honest, that is all there is to it.

$ tar -zxvf edna-0.5.tar.gz
$ cd edna-0.5
$ gedit edna.conf

Change the line:

# Unix example:
dir1 = /data/mp3 = MP3

and run it like this:

$ python &

Open Firefox and enter localhost:8080 to get a nice page for your music collection, browse till you find something and click it to bring up totem or xmms.

Accessing it from any other PC on your LAN is just as easy, just input the IP address as 111.222.333.444:8080 into your browser.

Some weird thing to note: When I ran Edna, it complained that streaming of Ogg files are disabled, since it needs the pyogg and pyvorbis libraries, but when I tried to play Oggs, it worked anyway.

Piping Audio Around the House

Playing audio over a pair of dinky little speakers is not all that satisfying. So how can you get it playing over a proper sound system? The kind that can rattle the walls and break crystal glasses?

Say, all your music resides on a large disk drive on a noisy server machine in the basement, while another silent PC is relatively close to your HiFi system, then you can run a cable from the sound adaptor line out to the auxiliary input of the amplifier, but you then still need a convenient way to send audio from the server over a LAN. This can be done using a combination of Sound Exchange (sox) and Netcat (nc).

On the HiFi connected PC, sox can play a file like this:

sox file.mp3 -t ossdsp /dev/dsp

However, you want sox to play music coming from the LAN, so it needs to be hooked to a server, that will listen for incoming data. Netcat can do that very conveniently.

To make sox and netcat work together, you need to tell sox the incoming file type (-t mp3, or -t vorbis) and you need to tell sox to grab the data from standard input (the empty '-'):

| sox -t mp3 - -t ossdsp /dev/dsp

Then you need to add a netcat listener before the pipe, to listen on a specific IP address and port:

nc -l -w 10 -p 12345

To be really good, you need to put an infinite loop around it, so that if netcat or sox exits, that they will start again:

while [ 1 ]
nc -l -w 10 -p 12345 | sox -t mp3 - -t ossdsp /dev/dsp

Put the above at the end of file /etc/rc.d/rc.local and it will always run when the PC is restarted and the PC will play whatever comes over the LAN - so make sure the volume is turned down a bit...

Now, on the server with the music repository, you can use netcat to send the music to the HiFi like this:

cat *.mp3 | nc 12345

That will cause netcat to pipe the music from the basement to the HiFi. Some more scripting can make the system run a playlist, or simply play everything at random.

Quitening a PC

So, how can one make a PC quiet? Most noise comes from the cooling fans, so you can reduce the noise by slowing the fans down. However, to do that safely, you need to reduce the power consumption.

The easiest way to reduce the power consumption is to stop the hard disk when it isn't needed and you can remove the video adaptor and run the machine headless. You can also run the BIOS setup and turn off the USB, serial, parallel and built-in video chips. You could also reduce the processor speed.

To stop the disk drive, add the following to /etc/rc.d/rc.local, to stop the drive after 25 seconds of inactivity:

hdparm -S 5 /dev/hda

To ensure that the drive will become inactive, you have to run MCC System and stop the syslog daemon, since it is always writing junk to the disk and will keep it from spinning down.

To quiet the CPU cooling fan down, you can solder a 50 to 75 Ohm, 1/2 Watt resistor in series with the fan. You'll need to experiment a little, to ensure that the fan will still start reliably.

Happy listening!


Copyright © 2005-2008, Aerospace Software Ltd., GPL.