You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Opus: replaygain_preamp behaves weird when playback gain is non-zero #1200
Opus files which have a non-zero 'Playback gain' value in the header and have R128 tags don't get affected by replaygain. If the 'Playback gain' is 0dB, the replaygain is applied fine.
This opusinfo output:
User comments section follows...
R128_TRACK_GAIN=-1280
Opus stream 1:
Playback gain: -15.5391 dB
should have the same result as:
User comments section follows...
R128_TRACK_GAIN=-5258
Opus stream 1:
Playback gain: 0 dB
but only the 2nd track is affected by the replaygain and replaygain_preamp settings. (With replaygain_preamp set to 0, they should have the same volume since cmus adds 5dB to R128 tags)
uname -a:
Linux RinLT 5.17.9-zen1-1-zen #1 ZEN SMP PREEMPT Fri, 20 May 2022 06:39:22 +0000 x86_64 GNU/Linux
changed the title [-]Opus: replaygain ignored when playback gain is non-zero[/-][+]Opus: replaygain_preamp behaves weird when playback gain is non-zero[/+]on May 25, 2022
I don't know if I'm describing this problem well, so here's an example:
sine.zip contains two copies of a generated sine wave:
one has the R128 replaygain tag at -4438 (-17.3359 dB) and 0 dB output gain,
the other has the R128 tag at -1280 (-5 dB) and the output gain at -12.3359 dB.
This way players that don't support R128 tags play the 2nd file at -18 LUFS and players that do at -23 (with cmus adding 5 dB to match replaygain 1.0).
These files sound exactly the same when replaygain is enabled in cmus.
Now, the problem:
When replaygain_preamp is set to a value below 0, e.g. -10, both files sound quieter
When it's a positive value, only the file with 0 dB output gain is louder
With replaygain we typically have REPLAYGAIN_TRACK_PEAK tags saying how much the volume can be raised without introducing clipping (or how much it needs to be lowered to remove it). With the default setting of replaygain_limit=true, cmus will lower the final gain if the adjusted peak would exceed 1.0.
Peak normalizations are difficult to calculate reliably for lossy codecs because of variation in excursion heights due to decoder differences. In the authors' investigations, they were not applied consistently or broadly enough to merit inclusion here.
I disagree with their conclusion, but in any case we don't get the peak so we have to make do without. Today we just assume the peak is 1.0 meaning the volume will never be raised, but there's a case to be made for assuming ample headroom instead. The risk of some clipping is probably preferable to some songs playing much too quietly.
I think the track_info struct needs an additional output_gain member along the album and track gain, which would store the codec gain value for checking the replaygain loudness. This would also be useful if any more future codecs implement this kind of functionality.
Activity
Dareka826 commentedon May 25, 2022
It seems that
replaygainis being applied ok, except thereplaygain_preampsetting only works on opus files with 'Playback gain' set if it's negative.[-]Opus: replaygain ignored when playback gain is non-zero[/-][+]Opus: replaygain_preamp behaves weird when playback gain is non-zero[/+]Dareka826 commentedon May 25, 2022
I don't know if I'm describing this problem well, so here's an example:
sine.zip contains two copies of a generated sine wave:
This way players that don't support R128 tags play the 2nd file at -18 LUFS and players that do at -23 (with cmus adding 5 dB to match replaygain 1.0).
These files sound exactly the same when
replaygainis enabled in cmus.Now, the problem:
replaygain_preampis set to a value below 0, e.g.-10, both files sound quietergavtroy commentedon May 26, 2022
With replaygain we typically have
REPLAYGAIN_TRACK_PEAKtags saying how much the volume can be raised without introducing clipping (or how much it needs to be lowered to remove it). With the default setting ofreplaygain_limit=true, cmus will lower the final gain if the adjusted peak would exceed 1.0.RFC 7845 wasn't a fan:
I disagree with their conclusion, but in any case we don't get the peak so we have to make do without. Today we just assume the peak is 1.0 meaning the volume will never be raised, but there's a case to be made for assuming ample headroom instead. The risk of some clipping is probably preferable to some songs playing much too quietly.
Dareka826 commentedon May 26, 2022
But if cmus doesn't raise volume is peak is at 1.0, then why does the file without output gain still get louder?
Both of these files have their peak assumed at 1.0:
Dareka826 commentedon May 26, 2022
Nevermind, I misunderstood what you wrote. Now I see that in that case cmus sees that it has headroom to work with thanks to the gain information.
Wouldn't a solution then be to somehow take the opus output gain into account in
update_rg_scale()?Dareka826 commentedon May 26, 2022
I think the
track_infostruct needs an additionaloutput_gainmember along the album and track gain, which would store the codec gain value for checking the replaygain loudness. This would also be useful if any more future codecs implement this kind of functionality.