Skip to content

Support R128 ReplayGain tags (Opus)

Currently, VLC seems to support VorbisComment-based ReplayGain by using the REPLAYGAIN_{TRACK,ALBUM}_{PEAK,GAIN} tags.

However, ReplayGain in Opus is implemented using the two tags R128_TRACK_GAIN and R128_ALBUM_GAIN, see the RFC.

@jbk posted a collection of test files for ReplayGain under some other ReplayGain bug a while ago; the two Opus files Owner128-11a67-ReplayGain.opus and Owner128-11a67-WithoutRG.opus are good reproducers for this behavior, because they seem to differ only in one tag: One has a R128_TRACK_GAIN tag (although it's set to 0, but that's perfectly alright to demonstrate the issue), the other has none.

Steps to reproduce:

  • Enable ReplayGain in VLC (Android or desktop probably doesn't matter, though I used Android)
  • Set replay gain mode to track (might be the default)
  • Set the default replay gain to some absurdly low value like -64.0
  • Play both files

Expected behavior:

  • The ReplayGain value from the R128_TRACK_GAIN tag (or R128_ALBUM_GAIN) is used when present

Actual behavior:

  • ReplayGain is not used for either of the files

Unfortunately, I don't know enough about ReplayGain (or R128) to implement the code that converts these values.

Although it's a bit dirty, I think it's not strictly necessary to check if this is actually Opus or some other codec - assuming a straightforward conversion of the R128 track/album gain to the old peak/gain values is possible, I guess it can just be implemented in modules/demux/xiph_metadata.c (encoders are only supposed to use one of the two variants anyway).

Further references: beets Cantata

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information