Getting MP3 songs to play at the same volume in iTunes and beyond

My music library consists of songs that I’ve acquired from a variety of sources such as web downloads, Amazon, iTunes, eMusic and rips from my own CDs.

One of my biggest pet peeves for the longest time is that songs and albums across my library vary in playback volume.  Since I almost always listen to music in shuffle/random across the entire library (or within a specific genre), track-to-track volume differences are very noticeable.  It’s particularly bad if I’m listening to through headphones.

By default, iTunes will analyze volume information on songs as you add them to your library.  It stores volume normalization in an extended ID3 tag called “COMMENT ITUNNORM” which it will read and adjust playback volume before each song starts.

While iTunes handles this really well, it sucks if you also use other media player software or want to move to another music player in the future.

Since I wanted to future proof myself, I started investigating how I could have a more portable solution that would be player independent.

Solution: Replay Gain

After doing some searches, I stumbled upon various ways of analyzing audio files in order to normalize overall loudness of song playback.  The most popular method seemed to be “Replay Gain” and it was getting a ton of support in 3rd party applications.

According to Wikipedia:

Replay Gain is a proposed standard published by David Robinson in 2001 to normalize the perceived loudness of computer audio formats such as MP3 and Ogg Vorbis. It works on a track/album basis, and is now supported in a growing number of media players. Although the standard is formally known as "Replay Gain", it is also commonly known as "ReplayGain" or "replaygain." It is sometimes abbreviated "RG".

The Theory of ReplayGain, with the relevant parts in red:

Replay Gain works by first performing a psychoacoustic analysis of an entire audio track to measure peak levels and perceived loudness. The difference between the measured perceived loudness and the desired target loudness is calculated; this is considered the ideal replay gain value (the target loudness of most Replay Gain utilities is 89 dB SPL — 6 dB higher than the Replay Gain specification and SMPTE recommendation). Usually, the gain value and the peak value are then stored as metadata in the audio file, allowing Replay Gain-capable audio players to automatically attenuate or amplify the signal so that tracks will play at a similar loudness level. This avoids the common problem of having to manually adjust volume levels when playing audio files from albums that have been mastered at different levels. Should the audio at its original levels be desired (e.g., for burning back to hard copy), the metadata can simply be ignored.

With lossy files, another benefit of Replay Gain is that the peak information can also be used to prevent loud songs from clipping.

Replay Gain utilities usually add metadata to the audio files without altering the original audio data. Otherwise, a tool can amplify the data itself and save the result to another, gain-adjusted audio file; this is not perfectly reversible in most cases. The Replay Gain standard specifies an 8-byte field in the header of any file, though many popular audio formats use tags for Replay Gain information.

Track vs. Album Gain

There are 2 ways to calculate Replay Gain – Track-gain or Album-gain.  Track-gain does analysis so all tracks are the same volume on playback.  Album-gain will gather additional peak and gain values for every song within an album, and try to maintain the intended loudness differences between tracks.

Album gain makes sense if you typically listen to a whole album at once.  Since I rarely do that, using track-gain made the most sense.

You can calculate both track and album-gain for each songs, but for me, it was a waste of time to do it in addition to track-gain.

How to calculate Replay Gain?

The easiest way I found to calculate Replay Gain (RG) for all the songs on my library was to use the well-known free music player Foobar2000.  After calculating RG for every single track, it’s one button click to add the RG values to the ID3 tags of all the songs in extended tag values called “REPLAYGAIN_TRACK_GAIN” and "REPLAYGAIN_TRACK_PEAK”.

Unfortunately, iTunes doesn’t read these 2 extended ID3 tags and uses it’s own ID3 tag called “COMMENT ITUNNORM” to store it’s volume normalization information. Yes, once again, Apple sucks for interoperability 🙁

The easiest way to get the value of both the RG standard ID3 tags, as well as having iTunes support is to convert the RG tags to the iTunes recognized ones.  Luckily there free tools to help us to that.

Disclaimer

While this only changes your ID3 tags, it is actually writing changes to each file.  Since we’re making changes broadly across your entire music library, make sure you’re extra careful before committing any of the steps below.

I recommend you take a complete backup of your music library before starting this in case you have to revert anything.

Software needed

You’ll need 2 free applications before we begin:

We’ll use Foobar2000 first to calculate the track-gain for each song and write out the ID3 tags, then use MP3Tag to copy the ReplayGain tag into the iTunes supported tag.

Step-by-step (click each screenshot for larger version):

  1. In Foobar2000, add all your target songs either by using File | Add Folder, or drag-and-drop.  Best to try 1 album first, before doing your whole library.
  2. Select all the songs that you added, right-click and choose Replay Gain then Scan Per-File Track Gain.
    image
  3. You’ll see a progress bar as it analyzes the peak and gain for each song you’ve selected.  This should be fairly quick assuming you haven’t chosen thousands of songs:
    image
  4. After that completes, you’ll see a summary window showing the results.  You won’t see any values calculated for Album gain or Album peak since we are only calculating track again.  Press Update File Tags to write the new extended ID3 tags to each song.
    image
  5. After all the tags are written out, you’ll be returned to the main Foobar2000 window. I couldn’t find any way in Foobar2000 to verify the ID3 tags were written out, but don’t worry, you can verify that in our next step.
  6. Now, start up MP3Tag and add the same folder/albums/songs you just worked on in Foobar2000:image
  7. Optional: To verify the Replay Gain tags were written out by Foobar2000, right-click one one of the songs and choose Extended Tags.  You can then scroll down and see REPLAYGAIN_TRACK_GAIN and REPLAYGAIN_TRACK_PEAK tags and values:image
  8. There is no built in functionality in MP3Tag to convert the ReplayGain tag to the necessary iTunes tag.  Luckily, MP3Tag supports custom scripts that we can do almost anything we want with meta data.  Select all the songs in MP3Tag, and choose Convert then Actions.image
  9. On resulting Actions dialog, click on the little icon on the right side represent New Action:image
  10. Give a name to the action, I called mine “ReplayGain to ITUNNORM” and hit OK:image
  11. Another dialog will appear looking similar to the first. Click on the same “New” icon to actually define what this action will do:image
  12. For the Action Type, select “Format Value” and click OK:image
  13. You now have to define the format value.  Specify COMMENT ITUNNORM for the field name, and $rg2sc(%REPLAYGAIN_TRACK_GAIN%) for the format string.  Pay attention to the spelling of both, it needs to be exact. Press OK.
    image
  14. You’ll be returned to the Action groups dialog, where you’ll see your newly created action. Make sure you check the box next to it, and press OK to invoke the action.image
  15. MP3Tag will make quick work of the tag conversion, and you’ll see a summary dialog tell you how many tags it formatted.  It should be exactly equal the number of songs you selected originally.  If it’s not, then your work in Foobar2000 didn’t work and you should restart.image
  16. Optional: You can verify that the new iTunes tag was added by doing the same thing we did in Step 7, except this time we look for a new extended tag called COMMENT ITUNNORMimage image 
  17. The last step is to now get iTunes to read your new track gain information.  If you don’t already have the song added to your iTunes library, you can just add it and it will be read automatically.  However, if the song is already part of your library, there’s an easy work around.  Just select all the songs, click Get Info.  On teh information dialog in iTunes about the selected songs, do not make any changes.  Instead, just click OK and iTunes will re-read all the song information, including the new COMMENT ITUNNORM tag you added.image image

Presto! Your music is now all set with Replay Gain information, and will be supported in iTunes, your iPod and even your iPhone.

If I ever get around to it, I’ll look into creating a simple app that can automated this. But don’t hold your breath 🙂

Update (1/3/2010): I create a simple batch file to help alleviate some of the manual steps.