February 27, 2007

Adjusting MP3s with mp3gain

Author: Joe 'Zonker' Brockmeier

If you listen to music on CD much, you'll notice that some CDs sound much louder than others, and I'm not talking about Ministry's The Mind is a Terrible Thing to Taste versus Sarah McLachlan's Touch. Two CDs of the same genre, when played on the same CD player, at the same volume, can have drastically different playback volume. This difference carries over when you rip the CD to MP3, and can be really annoying when you're going from song to song on your MP3 playlists on your computer or portable music player. One way to iron out the differences is to use MP3Gain to adjust your MP3s to have the the same volume.

According to the MP3Gain site and documentation, MP3Gain does an analysis of each MP3 and tries to figure out how loud it sounds to the human ear. Then, after analyzing the file, it can save information to the MP3's metadata in the APEv2 format to Analysis and Undo tags about its analysis, and adjust the MP3's gain setting directly so that the track is louder or softer.

MP3Gain does not re-encode the files or make any irreversible changes to your MP3's audio data. The last thing you want to do after you've taken the time to encode several hundred CDs is to have to go back and do it again. All MP3Gain does is tweak the file's metadata to tell your MP3 player "turn this one up," or "crank it down," in an effort to achieve a consistent volume between songs and albums.

Using MP3Gain

Your favorite distro may have a package for MP3Gain; Ubuntu users, for example, can just run sudo apt-get install mp3gain to install MP3Gain. If not, grab the source from the download page. Make an mp3gain directory, copy the zipfile to that directory, and unzip the source there. Then run make and make install to install the mp3gain command-line utility.

Once the software is installed, pick an album or song that's a bit quiet compared to the rest of your collection and copy it to a directory where you can experiment. I started with Concrete Blonde's Bloodletting, which seemed to be a bit faint volume-wise when compared to other alternative rock albums. Make sure to listen to a bit of the songs with your favorite audio player so you can compare before and after.

For the first test, you might want to let MP3Gain try to automagically adjust the gain based on its analysis of the songs' volume. To do this, run mp3gain -a -k *mp3 on the album, or mp3gain -r -k *mp3 for a single song.

Now, pop the songs into your MP3 player again and give 'em a listen. If they sound good, then try a couple more. If you're happy with MP3Gain's adjustments, you could run it against your entire music collection using something like this:

find . -name *mp3 -exec mp3gain -a -k {} \;

Depending on the size of your music collection, this may take some time.

If you're not happy with the changes made by MP3Gain, just run mp3gain -u file.mp3. That should reverse the changes by MP3Gain and return the file to its original state. I strongly recommend working on copies until you have got the settings you want, as I have managed to mess up a few MP3s while experimenting.

So far, I've found MP3Gain to be somewhat conservative about adjusting the volume. It trends toward dropping the overall gain on albums rather than upping the gain on the albums I find too quiet. I've also noticed that the utility will warn of clipping far more frequently than clipping actually occurs, so feel free to take the clipping warnings with a grain of salt and adjust a bit past what MP3Gain considers safe. If you want to ignore the clipping warnings altogether, use the -c option.

To manually tweak the gain, you can use the -d option to modify the dB gain by a floating-point number above or below the default volume. According to MP3Gain author Glen Sawyer, the default volume is 89.0 dB. If you want to tweak the volume by, say, 2 dB, you'd use:

mp3gain -r -d 2.0 myquietsong.mp3

The -r option sets the song to the default volume of 89.0 dB, and the -d option adjusts the dB level above or below that. You can use a negative value as well:

mp3gain -r -d -3 myloudsong.mp3

Also, if you want to preserve the original file's timestamp, use the -p option -- otherwise MP3Gain will update the timestamp each time you modify the file.

Another option is to apply a gain level directly to the current volume level of a file using the -g option:

mp3gain -g 3 myquietsong.mp3

This will add 3 dB to the song as it is, rather than calculating from the default volume as you would with the -r -d options.

Getting graphic

The Windows version of MP3Gain comes with a nice GUI, but MP3Gain doesn't offer a corresponding Linux version. However, you can download JavaMP3Gain if you're interested in having a GUI to work with and have Java installed. Note that you will need Sun Java installed, as JavaMP3Gain doesn't work with the GNU Java Interpreter.

Download the zip file from the JavaMP3Gain site and unzip it in the directory where you'd like the software to live. Once that's finished, you'll need to tell Java to run it as a JAR file:

java -jar JavaMP3Gain.jar

JavaMP3Gain isn't as full-featured as the MP3Gain GUI for Windows, but you may find it easier to use for basic operations than the command line. In the upper left corner, you'll see a Select Directory button. Click that and navigate to the directory you want to work on. Click the Process Recursively button if you want to run operations on subdirectories containing MP3s as well. Select the options you want to use and click Start.

Since the GUI offers only the option of applying the track or album gain options, you may want to override those and put your own options in the Other Options field. One thing that's missing from the GUI is an undo option, but you can undo MP3Gain changes by putting -u in the Other Options field and clicking Start.

Since tastes in volume are as subjective as tastes in music, it will probably take some playing with MP3Gain before you hit on exactly the right formula for you. I'd recommend copying a few albums to a temporary directory and mucking about with MP3Gain to get just the settings you like, and then applying them to your entire music collection.

Click Here!