Adding ReplayGain tags to your Music Collection

If you find yourself having to change the volume of your music player all the time, because the music in your collection is mastered at different volumes, replaygain is the solution. See Wikipedia eplanation of replaygain . In order to use replaygain for your mp3 files you will need the program mp3gain. See installation of mp3gain .

Goals

By default the program mp3gain will analyze the loudness of an mp3, and then alter the audio to change the perceived volume. The Dj Tagger tasks described in this example will instead use mp3gain for the analysis, but leave the audio of the mp3 alone. This has several advantages:

  • You have a choice between using replaygain of not using replaygain when you play your music files. When the audio would be changed, that choice is gone.
  • Replaygain analysis is done per track and per album (to get a perceived volume of an entire album or disc). Typically when listening to an album you want to hear softer songs on the album play back softer. When storing tags both album gain and track gain values are written. When playing your music, you can choose which one (album, track, or no replaygain) should be applied.
  • If the perceived volume should be higher than the original volume, there is allways a chance of clipping. Clipping prevention makes sure that the track is not played so loud that clipping will occur. When replaygain analysis is stored in the tags, the clipping prevention can take the actual playback volume into account. Making it less likely that clipping prevention is indeed necessary.

Of course the disadvantage is that your player has to support replaygain tags.

The replayGain task

To add replaygain tags to your music files, all you have to do is save the following file, for example as replaygain.djt :

<tasks>
  <scanRoot>C:\Users\username\Music</scanRoot>
  <task class="printInfo" />
  <task class="replayGain" />
</tasks>

This task file instructs DjTagger to analyze all your music files under C:\Users\username\Music and add replaygain tags to them. To execute this task in Windows, open a command prompt and type something like:

"C:\Program Files\DjTagger\djtagger.exe" replaygain.djt

Undoing audio changes

If you or somebody else have previously used mp3gain on files in your collection, then either (as explained in goals ):

  1. Replaygain is applied by altering the audio in the files, instead of by adding tags.
  2. Replaygain information is stored in tags, but in Ape tags instead of id3 tags. Some players can not read Ape tags, or have difficulty playing songs with Ape tags. DjTagger will allways write to id3 tags for mp3 files.

Such changes can be undone by the undoMp3Gain task of DjTagger. Note that this will not undo changes added by the replayGain task. It is intended to reverse changes made to songs by a manual execution of mp3gain. If there are no such changes, undoMp3Gain will do nothing.

A task file that first undoes changes by a manual execution of mp3gain.exe , and then analyses your songs and writes correct replaygain tasks will look like:

<tasks>
  <scanRoot>C:\Users\username\Music</scanRoot>
  <task class="printInfo" />
  <task class="undoMp3Gain" />
  <task class="replayGain" />
</tasks>

Applying album gain

If you open your scanned files in a tag editor, you will see that DjTagger added the following tags: replaygain_track_gain , replaygain_track_peak , replaygain_album_gain , and replaygain_album_peak . However the album and track values are the same! This is because DjTagger does not now how to discriminate between albums yet, so each track is considered belonging to an album with just that track.

The albumInfo task can be used to correctly discriminate between albums. It uses the concept of an albumId to achieve that: tracks with the same id belong to the same album. Use expression language to define an albumId . An example:

<tasks>
  <scanRoot>C:\Users\username\Music</scanRoot>
  <task class="printInfo" />
  <task class="albumInfo">
    <albumId>${albumArtists}:${album}</albumId>
  </task>
  <task class="undoMp3Gain" />
  <task class="replayGain" />
</tasks>

Now DjTagger will consider all songs for which the album artists tag and the album title tags are identical to be on the same album. Album gain tags for songs in an album are computed by determining the perceived volume of the entire album.

The above album definition still has two problems:

  • If you have tracks without album tags and/or without albumArtists tags they may be incorrectly grouped together. I.e. all tracks without albumArtists and album tags will get the same albumId. This can be solved by setting the isAlbum property.
  • You may have tracks that do not use the albumArtists tags.

Possible alternatives for the above configuration would be:

<tasks>
  <scanRoot>C:\Users\username\Music</scanRoot>
  <task class="printInfo" />
  <task class="albumInfo">
    <isNotAnAlbum>${(empty albumArtists && empty artists) || empty album}</isNotAnAlbum>
    <albumId>${empty albumArtists ? artists : albumArtists}:${album}</albumId>
  </task>
  <task class="undoMp3Gain" />
  <task class="replayGain" />
</tasks>

Another example (assuming you organize albums per directory on your filesystem):

<tasks>
  <scanRoot>C:\Users\username\Music</scanRoot>
  <task class="printInfo" />
  <task class="albumInfo">
    <isAlbum>${!(empty album)}</isAlbum>
    <albumId>${path}</albumId>
  </task>
  <task class="undoMp3Gain" />
  <task class="replayGain" />
</tasks>

Installing the mp3gain executable.

Information about mp3gain: mp3gain.sourceforge.net . You only need the command line version of mp3gain. DjTagger is tested with version 1.4.6. For Windows it can be downloaded here: http://prdownloads.sourceforge.net/mp3gain/mp3gain-dos-1_4_6.zip?download . For linux users: most distributions include an mp3gain package.

After installation, DjTagger needs to know where it can find the mp3gain executable. There are two ways in which you can achieve this:

  1. Add the path in which you installed the mp3gain executable to your PATH environment variable.
  2. Add (or change) the djtagger.properties file. This file can be found in the subdirectory .djtagger of your home directory. (DjTagger has to be run at least once for this directory to exist). On Windows Vista the directory would be: C:\Users\your-user-name\.djtagger\djtagger.properties . Add the following line to this file (of course using the path to which you installed mp3gain):
    djtagger.mp3gain.path=C:\\Program Files\\MP3gain\\mp3gain.exe