Skip to main content
Topic: Opus 'output gain' seems to be set incorrectly (Read 347 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Opus 'output gain' seems to be set incorrectly

According to the xiph.org wiki, the album gain should be stored in the OpusHead 'output gain' field, instead of a comment field such as REPLAYGAIN_ALBUM_GAIN or ALBUM_GAIN.

While foobar2000 does seem to do this (although it also creates an R128_ALBUM_GAIN comment field and sets it to 0? 🤔), the scale used for it seems to be off. For example, I have an Opus file for which foobar2000 claims the album gain is -9.39 dB, while opusinfo reports that the file has output gain set to -14.3867 dB, and I can confirm that the file indeed sounds too quiet compared to other ReplayGain-normalised music.

Re: Opus 'output gain' seems to be set incorrectly

Reply #1
After some more digging, RFC 7845 actually disagrees with the xiph.org wiki - it also allows "an optional gain for album normalization", R128_ALBUM_GAIN. I'm not sure what this means, although I do prefer this variant of album gain tagging because its use - unlike that of the 'output gain' field - is optional, and I prefer having the option of not utilising either track or album gain instead of being forced to use one or the other.

But all this is neither here nor there, as the main point is that foobar2000 currently seems to set the 'output gain' field incorrectly when using it as album gain, as indicated by the disagreement between the album gain reported by foobar2000 and the output gain value reported by opusinfo.

Re: Opus 'output gain' seems to be set incorrectly

Reply #2
They are not set incorrectly. foobar2000 just shifts the values internally to match ReplayGain target. Otherwise the format would be useless for anyone who uses ReplayGain - and everyone should use it.

Re: Opus 'output gain' seems to be set incorrectly

Reply #3
They are not set incorrectly. foobar2000 just shifts the values internally to match ReplayGain target. Otherwise the format would be useless for anyone who uses ReplayGain - and everyone should use it.
You know, now that you mention it, I completely forgot that I did my listening test in VLC and not foobar2000 itself. Listening in foobar2000, those Opus files actually do sound equally loud as my ReplayGain-adjusted FLAC files. So it seems as if foobar2000 adjusts the gain by the way it interprets the 'output gain', while VLC adjusts the gain the way opusinfo interprets it.

So the question is - who's right? I would say opusinfo (and, by extension, VLC) is right, on account of opusinfo being opusinfo. At the end of the day, the way foobar2000 (or any other application) interprets (and writes) Opus 'output gain' should match the way opusinfo interprets it, and if opusinfo says that foobar2000 set the output gain to -14.3867 dB, then that's what foobar2000 set it to.

Although - I would actually prefer it if the album gain was specified in the R128_ALBUM_GAIN comment field instead of the 'output gain', but that's a separate matter.

Re: Opus 'output gain' seems to be set incorrectly

Reply #4
On top of that, I just did another test - I decoded the Opus file in question (although all Opus files which have had album gain adjusted via foobar2000 suffer the same issue) with opusdec, and the resulting wav file matched the loudness as reproduced by VLC, not foobar2000, i.e. it is too quiet. Foobar2000 is wrong.

Re: Opus 'output gain' seems to be set incorrectly

Reply #5
For ease of parsing I'll summarise, since I can now write an honest-to-goodness bug report -

Steps to reproduce:
  • Adjust the ReplayGain of several Opus files in foobar2000 by scanning them as a single album.
  • Decode one of the Opus files with opusdec. During decoding, opusdec will apply the 'output gain' which foobar2000 has set (and which it uses for storing the album gain).
  • Making sure the ReplayGain mode is set to "Album" and that RG preamps are set to 0 dB, play both the Opus file itself and its decoded wav file (produced in the previous step) in foobar2000.
  • The gain which foobar2000 applies when playing the Opus file should equal the gain opusdec applied when producing the wav file, i.e. the two files should be equally loud when played. But the wav file will be quieter.

Re: Opus 'output gain' seems to be set incorrectly

Reply #6
This just keeps getting more and more confusing.

The "Selection Properties" tab shows this when the Opus file I mentioned in the OP is selected:


And the relevant output of opusinfo looks like this:
Code: [Select]
(...)
        R128_TRACK_GAIN=-545
        R128_ALBUM_GAIN=0
Opus stream 1:
        Pre-skip: 312
        Playback gain: -14.3867 dB
(...)

So, uh... what?! 😕
foobar2000 apparently recognises that the "Opus header gain" (i.e. 'output gain') is set to -14.39 dB, but then goes on and decides that the "Album gain" is -9.39 dB? I'm confused.

Re: Opus 'output gain' seems to be set incorrectly

Reply #7
I already told you. foobar2000 adjusts the values internally to ReplayGain levels because ReplayGain levels are different from R128 levels. If you ask ReplayGain to be used you get proper RG levels. There is no bug.

Re: Opus 'output gain' seems to be set incorrectly

Reply #8
I already told you. foobar2000 adjusts the values internally to ReplayGain levels because ReplayGain levels are different from R128 levels. If you ask ReplayGain to be used you get proper RG levels. There is no bug.
I know that you already told me that, but the problem is that you're wrong. Or rather, you're at least wrong in the claim that that behaviour is not a bug.

The long and short of it is that the decoding behaviour differs from the decoding behaviour of opusdec - ergo, it is a bug.

But furthermore, the output gain must be applied regardless of which gain mode is used, or even if none is used. Straight from RFC 7845, page 15:
Quote
   6.  Output Gain (16 bits, signed, little endian):
(...)
       Players and media frameworks SHOULD apply it by default.  If a
       player chooses to apply any volume adjustment or gain
       modification, such as the R128_TRACK_GAIN (see Section 5.2), the
       adjustment MUST be applied in addition to this output gain in
       order to achieve playback at the normalized volume.
Note that while the document does only initially say "SHOULD", it does say that it "MUST" be used if a player "chooses to apply any volume adjustment" - which foobar2000 does, as it has a volume control.
However, not only does foobar2000 not apply the output gain at all if the gain mode is set to "None", if the gain mode is set to either "Album" or "Track", it does not apply that gain in addition to the output gain, which is also something it "MUST" do. So all of that mess is a bug, as it does not follow the RFC.

Re: Opus 'output gain' seems to be set incorrectly

Reply #9
All gain values are taken into account, just not used as-is when you request ReplayGain use. Slide the RG preamp slider to -5 dB and observe how output levels are now in line with R128 and all file formats play at the same average loudness.

Edit: Are you seriously asking for foobar2000 to butcher Opus so it can't be used with other formats as it would play several decibels quieter?

Re: Opus 'output gain' seems to be set incorrectly

Reply #10
All gain values are taken into account
I mean, that's very clearly false, as evidenced by the fact that the output gain does not get applied when ReplayGain mode is set to "None". I literally just said that:
(...) not only does foobar2000 not apply the output gain at all if the gain mode is set to "None", (...)

Are you seriously asking for foobar2000 to butcher Opus so it can't be used with other formats as it would play several decibels quieter?
What I'm "seriously asking" is for foobar2000 to comply to the Opus standard, and to the decoding behaviour of opusdec. What you seem to be suggesting is that the manner in which opusdec applies the output gain when decoding an Opus file is "butchering" it.

This is how any Opus-standard-compliant decoder/player - such as opusdec and, apparently, VLC, and presumably others (I'm also going to see how Rockbox handles Opus output gain; will report when I do) - is going to handle Opus output gain. It's the correct behaviour. If Opus uses R128 and everything else uses ReplayGain, then Opus uses R128 and everything else uses ReplayGain. 🤷

If every decoder/player other than foobar2000 is going to decode/play Opus 5 dB quieter than other formats, then foobar2000 not doing it merely deceives the user - Opus sounds as loud as other formats in foobar2000, but then quieter anywhere else. If Opus using a different gain/loudness standard than other formats is a problem for the user, foobar2000 should not hide it from them.

Re: Opus 'output gain' seems to be set incorrectly

Reply #11
The spec says "Players and media frameworks SHOULD apply it by default".
This is a recommendation and foobar2000 follows it. ReplayGain is enabled by default.

"If a player chooses to apply any volume adjustment or gain modification, such as the R128_TRACK_GAIN (see Section 5.2), the adjustment MUST be applied in addition to this output gain in order to achieve playback at the normalized volume"
This part of the spec is also followed. All gains are applied when gains are applied.

It's not a bug that foobar2000 doesn't force decoding the file with R128 reference level. And in case you didn't know the Opus behavior of foobar2000 has been perfected over several years. It's just insulting that you come here to insist foobar's decoder should be changed to be as limited as opusdec is.

Re: Opus 'output gain' seems to be set incorrectly

Reply #12
But furthermore, the output gain must be applied regardless of which gain mode is used, or even if none is used. Straight from RFC 7845, page 15:
Quote
   6.  Output Gain (16 bits, signed, little endian):
(...)
       Players and media frameworks SHOULD apply it by default.  If a
       player chooses to apply any volume adjustment or gain
       modification, such as the R128_TRACK_GAIN (see Section 5.2), the
       adjustment MUST be applied in addition to this output gain in
       order to achieve playback at the normalized volume.
Note that while the document does only initially say "SHOULD", it does say that it "MUST" be used if a player "chooses to apply any volume adjustment" - which foobar2000 does, as it has a volume control.

I take it to mean the header gain can be optionally applied, but if a player adjusts the volume by reading tags, the header gain volume must be the used to calculate the adjustment to achieve correct volume.

However, not only does foobar2000 not apply the output gain at all if the gain mode is set to "None", if the gain mode is set to either "Album" or "Track", it does not apply that gain in addition to the output gain, which is also something it "MUST" do. So all of that mess is a bug, as it does not follow the RFC.

Does fb2k even write a header gain by default? In preferences (advanced) you can choose to write either the track or album gain as the header gain, or not write it at all. If you write the track gain to the header, the Track Gain tag would be written as zero. If you don't, the header gain is zero and the track gain tag specifies the track gain volume.

The ReplayGain volume adjustment seems to work the same way whether the Track Gain is written as header gain or R128 tag. If you disable ReplayGain the opus header gain is ignored, and the track plays at the same volume as if the gain were saved to a tag (there's no volume adjustment). When Track Gain is enabled on playback, the volume is adjusted the same way (whether the track gain volume is saved as header gain or an R128 tag). That's how it seems to work to me, anyway.

When you enable ReplayGain on playback, fb2k adjusts the R128 volume to ReplayGain volume no matter which way the track gain volume is written to the file. That seems fair enough. You're enabling ReplayGain, not "ReplayGain except for opus files, which have a different volume". The alternative would be for fb2k to write incorrect R128 tags, but that'd mess with other players ability to adjust to the R128 volume.

 
SimplePortal 1.0.0 RC1 © 2008-2020