I'm a relative latecomer to the world of MP3s -- until I recently purchased a laptop with a large hard drive, lots of processor and audio, I had no real reason to worry about them -- my Heathkit/Harmon Kardon stereo system works quite well for playing music, thank you very much. However, the laptop changes things a bit -- sometimes it is nice to have a bit of music playing while hacking. No laptop has an audio system comparable to my Heathkit/Harmon Kardon, so a small loss of sound quality is quite acceptable in my mind.
This Techguide will help you create and playback MP3 files on an OpenBSD system. Most of these tools are generic or available on other Unix-Like Operating Systems, so you should have no problem using this information on other systems. This is by no means an exhaustive list of MP3 related applications for OpenBSD, but rather a starter -- once you start with this information, you can explore other tools.
MP3 technology is available on most popular platforms, however, the Unix-Like OS world has a huge advantage: open source tools. Many of the Windows and Macintosh tools are either commercial, or paid for by less than legitimate means, such as "ad-ware" or "spy-ware" -- or just begging you to buy the commercial version, or begging you to upgrade to the latest version which is seemingly rarely better (or as good!) as the old one..
The OpenBSD ports tree has quite a few tools one should look into for MP3 playback, I would suggest using the following command to search:
$ cd /usr/ports $ make search "key=mp3" | more
The man page installed with both programs is quite good, please read it.
Here is a sample script (from Margarida Sequeira, minor mods from Henning Brauer and me) which will take a CDROM and reduce it to a small collection of MP3 files:
$ more cd2mp3.sh #!/bin/sh FILE=cddbinfo.txt cdparanoia -B -v rm track00.cdda.wav for i in `echo *.wav` do lame -cbr -b 128 -q 2 -k -t -p $i $i.mp3; # rm $i; done mp3cddb *.mp3 if [ -f $FILE ]; then mp3cddbtag $FILE fi
The rm track00.cdda.wav line deletes a bogus track00 (a very few seconds of silence) that is sometimes created. It *seems* to be related to the CD drive used to read the audio CD. Some CDs on some drives create this file, others do not. This file's existence messes up the last step, so it is deleted here. Yes, you will get an error message if that file does not exist.
At this point, the contents of the CD are a set of .wav files in the current directory. The next step (the for - do - done loop) encodes the .wav files into MP3 files, giving them the same name as the incoming .wav file, but with the .mp3 tail. You will note that the line after the lame line deletes the .wav file that was just encoded, but I have it commented out here. I rather prefer to delete the .wav files AFTER a successful conversion of the entire CD, but I'm strange. You may well want to remove the '#' that leads off that line (my machine I use for this is rather slow -- if I can skip redoing the cdparanoia step, it saves a good chunk of time).
Now, we have a collection of annoyingly named MP3 files: track03.cdda.wav.mp3 and similar. The next few lines (mp3cddb, mp3cddbtag) look at the tracks and try to identify the CD from the freedb.org database. The mp3cddbtag command then renames and tags the .mp3 files with the appropriate track names and recording information.
If you wish to have better sound quality, you can tweak some of the lame parameters -- notably the '-r 128' and '-q 2' above script. However, be realistic. If you are playing back on your computer, keep in mind computer sound hardware and speakers generally suck. On the other hand, if you pick a good sound card and play it back though your serious stereo system, bumping up the bit-rate to 192k ("-r 192") or fiddling with the the "-q 2" may be worthwhile.
Note that the above script leaves a lot to be desired in terms of error checking, however I think it is of value as it is, as it is very easy to see what is going on and how it works. Feel free to add whatever you wish to it.
In my case, I store MP3 files on a Pentium 133 NFS server, which makes them available to any Unix-like system in the house. When I get around to it, I'll add Samba to this machine, giving me some added flexibility of clients.
Back to Technical Guides
Holland Consulting home
page
Contact Holland Consulting
since February 5, 2003
Copyright 2003, Nick Holland, Holland Consulting