Music collection/playing notes

From Helpful
(Redirected from Replaygain)
Jump to: navigation, search

On file tags


This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, or tell me)

ID3, ID3v2

MP3s originally had ID3, later retroactively versioned as ID3v1

Used on: MP3
a fixed-length 128-byte
mostly spent on artist, album, title, and comment, each 30 bytes some obvious problems for long names
genre only as an integer
stored at end of file
identified by: starts with
(at filesize-128)

There is an extended/enhanced version of ID3v1 but I'm not sure it's used much in the wild(verify)

ID3v2 was designed to overcome ID3's limitations

Used on: MP3
There are two major revisions of it.
2.4 has a few more features
2.3 is more widely supported
Some players are happy with both. Others (e.g. windows media player, windows phone) doesn't understand some tags, that's probably because for the longest time they didn't support or didn't handle it correctly (e.g old iTunes versions).
In general these issues are with 2.4 [1] and you'll have less trouble after converting everything to 2.3
Stored at front of file (meaning sometimes slower to alter. Adding some padding up front tends to )
identified by: starts with ID3 (at file offset 0)

Arbitrary tags will typically go to TXXX (basically a 'use defined' miscellaneous text field)

Vorbis comments

Used on: Ogg, FLAC, Theora, Speex, Opus
Arbitrary key-value.
Value is always a list, just usually a length-1 list.

APE tags

Used on: APE, Musepack, wavpack, MP3
APEv1 is mainly used on APE files and rarely elsewhere
APEv2 is an update that you also see on others, e.g. MP3, Musepack, wavpack, OptimFROG

arbitrary key-value
Not everything understands APEv2.
Things that understand it may still be confused if you add both ID3v2 and APEv2
Supported by:
Players include: foobar, winamp, a few others
libraries include: mutagen (v2 only)(verify)
Stored at end of file
Identified by: header and footer that mention APETAGEX [2]
Note that an ID3v1 tag could come after it, so

APEv2 tags get associated with replaygain, but note that it can go to ID3v2 as well (things like mp3gain just default to APEv2 for some reason - maybe just because writing a separate tag was easier than handling ID3v2 fully correctly at the time mp3gain was written?)

On unified tag access

mutagen notes




A lot of media don't have a standardized output level. Targets, yes. Conventions, yes, but volume can vary between any song by a handful of dB.

Even for entirely digital media, mastering only somewhat sticks to that.

A lot of the time this isn't hugely noticeable, but sometimes it is, and with music on shuffle, it is sometimes audible. DJs may care a bit more.

Different tracks on an album also have different volumes, though usually fairly subtly, and possibly intentionally.

Different albums have different volumes - not so intentionally, and also fairly subtly.

Even if there were a single standard that everyone kept to (there isn't really), there are other reasons for variation.

Natural reasons like
that different movements in classical music may well have long subtle bits and occasional loudness, as may wall-of-sound prog rock, bands, and others
that most acoustic playing tends to have a lot more loudness variation.
Less natural reasons like more dynamic compression (see loudness wars),
different music types from different eras will sounding a little louder even on the same medium
albums may intentionally have quieter parts/songs
this is particularly true for some classical music

For most music it won't be a huge amount of dB, but playing an above-average and below-average volume next to each other is pretty clear.

Analysing loudness

You can analyse your music to estimate its average perceived loudness, and later use that information to play things on approximately the same level

'approximately', for a few reasons, including that

  • It's based on energy, not peaks
which itself is better
...but that means that some peaks might go above the maximum value (clipping)
partly that's solved by not trying to normalize the perceived loudness to something well under the peak value
so that it's less likely that the occasional peak will clip (clipping is distortion, so most programs won't go for this unless you really insist)
which means that a few quiet songs with one big peak won't be amplified as much as you'd like
(this can also happen if there's corrupted data)
this mostly shouldn't happen as replaygain's target level is well under the maximum
  • "What do you want to happen in this edge case" reasons. Say,
what do you want to happen when a song builds up and starts quiet? It'll still sound too quiet at first, and finish louder than the next song starts at, even if the average is right.
That mostly just makes sense, though.
what if you play one classical song (that in its album should be quieter) inbetween completely different music? It's going to be quieter.
not realy the largest of problems, but still.
  • mentioned dynamic range compression during mastering messes with the perception of loudness.
that replaygain can't fully estimate(verify)
(It's one reason that classic rock sound quieter and cleaner than rock since the nineties)

The adjustment that software will suggest is towards a given intended level, and (depending on the file type in question) may either

  • tag the file, so that replaygain-aware players will play them louder, but you don't need to touch the music data itself
your player will have to support this too
  • or alter the file to play at that level
(mostly just in MP3, because you can do this without re-encoding: there's a gain in each MP3 frame we can adjust throughout).

Dealing with albums

As various albums have songs flow into each other, it's better to analyse albums as a whole.

It still analyses each file, but comes up with the amount to gain the album as a whole as well as a track gain.

The idea being that

  • When you play tracks as individual tracks (e.g. playing on shuffle), it uses the track gain, and the levels fit the average well.
  • When you play it as an album, it uses the album gain, and while this may be a few dB from the thing that plays after the album
the album's levels are internally consistent.

(what players actually do varies)

This is also an argument for why you would tag the files rather than adjust their contents: it lets you decide

This just means estimating the correction you want per track, considering all, and making one uniform correction to all things on the album.

You can skip that step, and gain the tracks individually. This should only really be perceptible on classical albums.

More technically

For a longer list, see [3]



On linux

The following does track gain (and forgets album consistency).

I have

  • mp3
    • install mp3gain
    • run
      nice -n 19 ionice -c3 find /data/Music -iname '*.mp3' -exec mp3gain -r -k \{\} \;
      (probably via cron)
-r means track gain,
-k means lowering the target volume if the default means it will clip somewhere. (no distortion is more important to me than exactly the same volume)
  • ogg
    • install vorbisgain.
    • run
      nice -n 19 ionice -c3 find /data/Music -iname '*.ogg' -exec vorbisgain -f -s \{\} \;
-f means it will only calculate for files when a tag isn't present. (should be default behaviour, really)
-s makes it more robust when you accidentally hand a bad file to vorbis

The basic niceness is for non-aggressive CPU use, the ionice for non-aggressive disk use (if you don't have ionice, omit the ionice -c3). Both are optional.

Foobar2000 notes


I'm currently fond of Columns UI with the Genre/Artist/Album lists on top (fairly iTunes-style).


Grouping applies after sorting, and combines things with the same value into a section - by default, each artist+album combination becomes a section, which means you'll see albums as chunks (when sorting by album or artist)


  • When sorted as intended, this is visually understandable (and relatively minimal)
Note that depending on UI you also get the artwork column


  • Odd results when sorting by anything else.
  • When you sort via clicking on column headers, you basically need to do tracknumber, then album, then artist to get decent sorting (because stable sort)
I work around this by having one column displaying
%artist% - %album%
and sorting and grouping by something a little more complicated, to deal with Various Artists-style albums, see below
  • can lead to a lot of one-item pseudo-albums (in the case of selective live songs, cover, etc)
you may prefer grouping per artist. And/or the sorting mentioned in the previous point
(note that if you've auto-tagged things and have a lot of single-per-'nineties hits' or such, consider removing that album

Dealing with Various Artists albums

Albums by two or more artists make sorting by any one column do the not-so-intuitive thing.

My current solution is an "Artist - Album" column that

  • sorts by something like
$ifgreater($len(%album artist%),0,%album artist%,%artist%) %album% $ifgreater($len(%disc number%),0,%disc number%-%tracknumber%,1-%tracknumber%)
  • groups by:
$ifgreater($len(%album artist%),0,%album artist% - %album%,%artist% - %album%)
  • and displays:
%artist%  - %album% 

You still have to tag albums to have a value in "Album Artist" tag when it varies (often Various Artists on collection albums, sometimes something more specific).

Side note: foobar seems to treat "Album Artist" as a fallback of a few fields - when displaying only, not when testing??(verify))

Disc number

I wanted to show disc number cleanly, specifically

omitting it unless it's present and >1
zero-padding track numbers
...while not showing albums missing track numbers as ? or 00

I ended up with

$ifgreater(%totaldiscs%,1,%disc number% - $ifgreater(%track number%,0,$num(%track number%,2),),$ifgreater(%track number%,0,$num(%track number%,2),))


Autoplaylists are queries, that show their results live.

Previously mostly created configured via its own manager (or album list).

Since 0.9.5 they are instead created via the Library search window:
button → Create Autoplaylist. Once they exist you can still edit their search query further.

See the query syntax.


  • All music (exclude known non-music), according to your own genre/path organization, e.g.
NOT %genre% HAS spoken AND NOT %path% HAS MusicVideo

  • recently modified
%last_modified% DURING LAST 2 WEEKS

  • Stored locally (not on network), e.g.
%path% HAS "C:\" OR %path% HAS "D:\" 

  • useful stuff missing (note: no %, this is about the field, not the value from it)
title MISSING OR artist MISSING OR genre MISSING AND NOT %path% HAS MusicVideo

  • title, album, or artist missing (also the difficult way)
("$if($meta_test(title,album,artist),1,0)" IS 0)

  • artist name is all-uppercase
("$if($strstr(%artist%,$upper(%artist%)),1,0)" IS 1) 
you may want to add
AND (NOT %artist% MISSING )

See also

Multiple values, e.g. for genre split

You can use multiple values for a field, because foobar can be told to split values on specific strings.

For example, you can add multiple genres, which by default it seems to split genres on
, and newlines. (You possibly want to add
) to that)

Note that this does not (necessarily) mean it adds these characters to the tag literally, it means "foobar, figure out how to split it for the underlying tag".

For example

on ogg tags, multiple values are natively a thing, most fields just happen to have one for practical reasons
On ID3v2.4 a TCON tag can have multiple text entries (NUL separated)
On ID3v2.3 a TCON tag can have multiple only one text value (though multiple numeric entries in it)
so it seems it stores the semicolon literally, but still splits its in its own own database(verify)

For the same reason, adding
with another tagging program may appear as a literal
in a single text value - unless it has similar "hey this means you should actually split it" logic.

In this case, you can tell foobar to split them again:

  • use tag editor for these files ('Properties')
  • right-click on the Genre field, select 'Split values...', and OK the window that opens
  • OKing the tag editor will now save the split values to tags

Playlist format


Useful extensions


masstagger (foo_masstag)

Often you can fill fields based on the filename, e.g.

  • choose "take parts from filename"
And write a pattern based on the actual filenames, e.g.
%tracknumber% - %artist% - %title%

You can also format existing values. For example, taking out underscores from the title:

  • choose "Format value from other fields" (note: not guess...)
Destination: TITLE
$replace(%title%,_, )