This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature

Adjusting MP3s with mp3gain

By Joe 'Zonker' Brockmeier on February 27, 2007 (8:00:00 AM)

Share    Print    Comments   

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.

Share    Print    Comments   

Comments

on Adjusting MP3s with mp3gain

Note: Comments are owned by the poster. We are not responsible for their content.

for vorbis

Posted by: Anonymous Coward on February 27, 2007 11:31 PM
<a href="http://www.sjeng.org/vorbisgain.html" title="sjeng.org">http://www.sjeng.org/vorbisgain.html</a sjeng.org>

#

For amarok

Posted by: Anonymous Coward on February 27, 2007 11:46 PM
<a href="http://www.kde-apps.org/content/show.php?content=26073" title="kde-apps.org">amarok replaygain script</a kde-apps.org>

You'll still need mp3gain for mp3, vorbisgain for ogg, <a href="http://altosdesign.com/aacgain/" title="altosdesign.com">aacgain</a altosdesign.com> for aac/mp4, <a href="http://www.musepack.net/index.php?pg=lin" title="musepack.net">musepack's replaygain</a musepack.net> for musepack

#

Re:can't find my mp3s

Posted by: Anonymous Coward on February 28, 2007 01:23 AM
Try this :

find<nobr> <wbr></nobr>/mnt/Music/ -name *mp3 -exec mp3gain -r -k {} \;

#

Re:can't find my mp3s

Posted by: Anonymous Coward on February 28, 2007 02:00 AM
If you don't escape *mp3, it gets expanded into the list of files ending with mp3 in the current directory by the shell before it gets passed to find. If you have one there, it might be the cause of your problems, and if not it's always good to escape just in case. Try -name '*.mp3' or \*.mp3

#

Re:can't find my mp3s

Posted by: Administrator on February 28, 2007 04:16 AM
\*.mp3 worked, thanks

#

On Linux, sox and a shell script do this

Posted by: Anonymous Coward on February 28, 2007 04:51 AM
I did this long ago with sox.
Sox can be embedded in a shell script to rip, adjust the volume and encode.
.
In the script, to adjust the volume:
1. call "sox<nobr> <wbr></nobr>... stat -v" and save the result to a shell variable.
2. parse the shell variable for the actual volume
3. call 'sox infile outfile vol "volume"'
.
This makes sox adjust the volume to the maximum available, without distortion.
However, this won't solve everything. If a song has a low average level, but occasional strong peaks relative to another song then there will still be an audible difference.

#

Peak normalization sucks (don't use sox!)

Posted by: Administrator on February 28, 2007 08:00 AM
The procedure you describe is "peak normalization." <a href="http://replaygain.hydrogenaudio.org/faq_norm.html" title="hydrogenaudio.org">Read why that sucks.</a hydrogenaudio.org>

#

mp3 gain is very messy

Posted by: Anonymous Coward on February 28, 2007 11:07 PM
In your article you state:

[...]Then, after analyzing the file, it can save information to the MP3's metadata in the APEv2 format[...]

But this is patently false, because mp3 metadata is not in the APEv2 format. To many mp3 compliant programs, the APEv2 data is garbage noise in the mp3 stream, and adding a foreign tag to mp3 files is ungainly and awful.

To split hairs of course id3 and id3v2 tags are also not compliant mpeg audio layer 3 data, but nearly every mp3 decoding program has been improved to handle them. When you start adding random other "tags" (ie. blobs of data) to the end of the file, however, all bets are off.

id3v2 is extensible, so mp3gain should use custom fields in id3v2.

Since it does not, I simply have mp3gain adjust the mp3 headers to tweak the replay decode levels. I lose the undo, but it will work with every decoder everywhere, and it's still a lossless transformation.

#

can't find my mp3s

Posted by: Administrator on February 28, 2007 12:20 AM
Ok, so I like the settings I used in one temp directory.

All my music are in subfolders in<nobr> <wbr></nobr>/mnt/Music/
So I use
find . -name *mp3 -exec mp3gain -r -k {} \;
like suggested, and it says, "find: No match."
What am I missing?

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya