Skip to content

Take opus output gain into account when checking replaygain_limit peak - #1201

Merged
flyingmutant merged 11 commits into
cmus:masterfrom
Dareka826:opus-gain-replaygain-check
Oct 18, 2022
Merged

flyingmutant merged 11 commits into
cmus:masterfrom
Dareka826:opus-gain-replaygain-check

Conversation

@Dareka826

Copy link
Copy Markdown
Contributor

This pull request incorporates the output gain value from opus files when deciding if the replaygain adjustment would go over the 1.0 peak limit. (Issue #1200)
I don't know if this is a good solution to this problem and would appreciate any feedback.

@Dareka826 Dareka826 changed the title Opus gain replaygain check Take opus output gain into account when checking replaygain_limit peak May 27, 2022

@gavtroy gavtroy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I'm not sure if it's the scenario you encountered but here's the one I see this benefitting:

Some loudness scanners set R128_TRACK_GAIN=0 and encode the replaygain information as an output_gain targeting -23 LUFS. Replaygain is based on -18 LUFS so we add +5 dB. However the limiter needs to know the decoder gain to check the combined gain is not positive, otherwise it will simply refuse to apply the +5 and opus files will play quieter.

I'm still tempted to just disable the limit for opus files. -_-

Comment thread ip/opus.c Resolved
Comment thread ip/opus.c Resolved
Comment thread player.c Outdated
db = replaygain_preamp + gain;

scale = pow(10.0, db / 20.0);
check_scale = pow(10.0, (db + player_info_priv.ti->output_gain) / 20.0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense to adjust the fallback peak value (line 384)? Along the lines of

if (isnan(peak))
    peak = pow(10.0, player_info_priv.ti->output_gain / 20);

Where output_gain is 0 this will still result in a fallback peak of 1.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt like this made sense because I use the output gain and R128 as a "combined replaygain" such that players that don't respect R128 tags play at -18 LUFS and those that do play at -23 LUFS + preamp. The decision to calculate a separate scale to be used when checking the limit came from this. I don't know if you suggestion results in the same calculation. I think that the assumed peak at 1.0 idea is good, since that way the combination of output gain + R128 is guaranteed to never exceed the original volume of the file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, what if there exist both an older replaygain peak tag and output gain? Wouldn't it make more sense not to rely on the non-existence of the peak tag when taking the output gain into consideration? I don't know if the standard allows it, but you could probably make some programs tag the file with rg1.0 tags.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's technically possible for an opus file to have a REPLAYGAIN_TRACK_PEAK tag but it's not going to happen in practice and not really worth trying to account for in the code. If it did occur, the output gain would probably be 0 anyway, and if both occurred together, would it describe the peak before or after the output gain is applied?

Using check_scale isn't ideal because when it's exceeded we apply replaygain_scale = limit, and limit won't account for the output_gain. I'm not 100% confident in any of the maths for my suggestion but the results were at least roughly what I was expecting. 🤷

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. The limit wouldn't denote the full volume if output_gain is applied. Your idea to calculate the peak based on output_gain is much better. Changed in 967ebe2.

Comment thread track_info.c Resolved
@flyingmutant
flyingmutant merged commit fed356b into cmus:master Oct 18, 2022
@flyingmutant

Copy link
Copy Markdown
Member

Merged (finally), thanks!

bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request May 27, 2024
https://build.opensuse.org/request/show/1176840
by user mia + anag+factory
- Update to 2.11.0
  * Add support for .nomedia file
    gh#cmus/cmus#1190
  * Fix a typo in an error message
    gh#cmus/cmus#1206
  * Take opus output gain into account when checking
    replaygain_limit peak
    gh#cmus/cmus#1201
  * #1219: Update Unofficial IRC channel
    gh#cmus/cmus#1220
  * Recognize artist/album sort keys from ffmpeg plugin
    gh#cmus/cmus#1165
  * Fix missing combining marks on last character in a field
    gh#cmus/cmus#1151
  * Use wcwidth for u_char_width
    gh#cmus/cmus#1198
  * Fix under-allocation when many zero-width characters are
    present
    gh#cmus/cmus#1152
  * Draw title and command lines on first update
    gh#cmus/cmus#1257
  * Switch to -latest os in build workflow
    gh#cmus/cmus#1265
  * ip/mp4: Use MP4FindTrackId() rather than assuming it's
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants