On to more interesting things. I’ve got fed up recently with changing volumes for different songs. I actually notice it more on my portable MP3 player, but Amarok 2 has long bugged me by not having any Replay Gain support. And I’ve been thinking about implementing it for about the same amount of time. Yesterday, I finally got around to starting it.
The first hurdle I came up against was how to get the information I needed from the files. If you run mp3gain or aacgain on your MP3 or MP4 files, or if you have MusePack files, there’s no problem since the information about changing the volume is stored in such a way that it is interpreted by the decoder, and so Amarok doesn’t need to do anything. But with other file formats, and when you use other tools for calculating the gain for MP3 and MP4 files, the information is stored as tags. Fine, we can read tags. We can store the information we read in the database, and then access it later. But we’re left with the question of what tags we’re looking for.
The official Replay Gain standard is incredibly unhelpful in this regard. It gives you all sorts of details about the mathematics behind calculating how much gain to apply to a track, but almost nothing about how to store or retreive that value. On top of that, it is woefully out of date, not having been updated since 2001.
OK, so over to the Replay Gain page on the slightly more active Hydrogenaudio Knowledgebase wiki. However, which tag format (ID3v2 or APE, say) the relevant tags are stored in by various tools and for various formats is about as detailed as it gets. None of the web pages for the various tools are any more helpful.
The vorbisgain man page is more forthcoming: the relevant tags are REPLAYGAIN_TRACK_GAIN, REPLAYGAIN_TRACK_PEAK, REPLAYGAIN_ALBUM_GAIN and REPLAYGAIN_ALBUM_PEAK. The REPLAYGAIN_*_GAIN values are in decibels and have ” dB” appended to the end. The REPLAYGAIN_*_PEAK values are floats (no further information given).
So I turned to the old Amarok 1.4 Replay Gain script. This is what I found:
- Vorbis and FLAC works as described above. To get the peak gain relative to the adjusted gain, you apparently need to take the log of the float, base 10, and multiply the result by 20.
- MP3s can have the data stored in one of several ways (apart from the method detailed above, which we don’t need to concern ourselves with):
- In the APEv2 tags in the same manner as with Vorbis (possibly not all uppercase)
- In the ID3v2 TXXX (user comment) tags in the same manner as Vorbis (possibly not all uppercase) – the TXXX frames have a description field and value field, which are used for the tag name and the tag value. Total of 4 TXXX tags to store all the values. These are written by Foobar2000.
- In the ID3v2.4 RVA2 tags (only Quod Libet does this AFAIK). Each tag has an identification string, into which Quod Libet writes the values “album” and “track”. The format of the rest of the frame is specified in section 4.11 of the ID3v2.4 frames specification.
- MP4s are done in the same way as Vorbis.
- AAC (not in an MP4 container): APEv2, presumeably in the same manner as MP3 APE tags (the ReplayGain script doesn’t support AAC files).
- MusePack: values are stored in the header in fields designated for the purpose. Should be supported natively by the decoder, according to the Hydrogenaudio Knowledgebase, but the 1.4 ReplayGain script stil reads these values. The peak value apparently needs to be multiplied by 2 to get the peak gain relative to the adjusted gain.
- WMA: same as Vorbis, stored in the ASF tags (this may well be only files tagged by the ReplayGain script itself).
- WavPack: stored in APEv2 tags, presumeably in the same manner as MP3 APE tags (the ReplayGain script doesn’t support WavPack files).
- MOD files: Foobar2000 stores these in APEv2 format, presumeably in the same manner as MP3 APE tags (the ReplayGain script doesn’t support MOD files).
Don’t you feel all enlightened now?