Skip to content

replaygain: target level refactor - #3065

Merged
sampsyo merged 9 commits into
beetbox:masterfrom
zsinskri:r128-targetlevel-config
Jul 25, 2019
Merged

replaygain: target level refactor#3065
sampsyo merged 9 commits into
beetbox:masterfrom
zsinskri:r128-targetlevel-config

Conversation

@zsinskri

@zsinskri zsinskri commented Oct 28, 2018

Copy link
Copy Markdown
Contributor

Remove REPLAYGAIN_* vs R128_* tag handling from the Backends, restrict it to the main plugin logic. That is archieved by passing the target loudness level to the backend with every album/track. It also necessitates that all Backends properly implement the target level.
As the different tag formats call for different default target levels this also seperates the configuration of those levels.

@zsinskri

Copy link
Copy Markdown
Contributor Author

The latest push merges master (or rather #3056, from which this branch was forked), resolving conflicts. It also fixes the ReplayGainLdnsCliMalformedTest, which caused unrelated tests to fail, due to missing cleanup.

@zsinskri

Copy link
Copy Markdown
Contributor Author

Is there any guideline on when to merge and when to rebase for this project? I will rework this branch's structure if a rebase is preferred.

@zsinskri
zsinskri force-pushed the r128-targetlevel-config branch from 29418b9 to 26b83b0 Compare June 19, 2019 18:57
zsinskri added a commit to zsinskri/beets that referenced this pull request Jun 19, 2019
When using the ffmpeg replaygain backend to create R128_*_GAIN tags,
automatically set the targetlevel to -23 LUFS.

Note: This will be made configurable by GitHub PullRequest beetbox#3065
zsinskri added a commit to zsinskri/beets that referenced this pull request Jul 14, 2019
Add replaygain backend using ffmpeg's ebur128 filter.

The album gain is calculated as the mean of all BS.1770 gating block powers.
Besides differences in gating block offset, this should be equivalent to a
BS.1770 analysis of a proper concatenation of all tracks.

Just calculating the mean of all track gains (as implemented by the bs1770gain
backend) yields incorrect results as that would:
- completely ignore track lengths
  - just using length in seconds won't work either (e.g. BS.1770 ignores
    passages below a threshold)
- take the mean of track loudness, not power

When using the ffmpeg replaygain backend to create R128_*_GAIN tags, the
targetlevel will be set to -23 LUFS. GitHub PullRequest beetbox#3065 will make this
configurable.
It will also skip peak calculation, as there is no R128_*_PEAK tag.

It is checked if the libavfilter library supports replaygain calculation. Before
version 6.67.100 that did require the `--enable-libebur128` compile-time-option,
after that the ebur128 library is included in libavfilter itself. Thus we
require either a recent enough libavfilter version or the `--enable-libebur128`
option.
zsinskri added a commit to zsinskri/beets that referenced this pull request Jul 19, 2019
Add replaygain backend using ffmpeg's ebur128 filter.

The album gain is calculated as the mean of all BS.1770 gating block powers.
Besides differences in gating block offset, this should be equivalent to a
BS.1770 analysis of a proper concatenation of all tracks.

Just calculating the mean of all track gains (as implemented by the bs1770gain
backend) yields incorrect results as that would:
- completely ignore track lengths
  - just using length in seconds won't work either (e.g. BS.1770 ignores
    passages below a threshold)
- take the mean of track loudness, not power

When using the ffmpeg replaygain backend to create R128_*_GAIN tags, the
targetlevel will be set to -23 LUFS. GitHub PullRequest beetbox#3065 will make this
configurable.
It will also skip peak calculation, as there is no R128_*_PEAK tag.

It is checked if the libavfilter library supports replaygain calculation. Before
version 6.67.100 that did require the `--enable-libebur128` compile-time-option,
after that the ebur128 library is included in libavfilter itself. Thus we
require either a recent enough libavfilter version or the `--enable-libebur128`
option.
zsinskri added 7 commits July 22, 2019 12:49
This test caused other tests to fail due to missing cleanup.
Configure the replaygain analysis by passing arguments to the Backends. This
avoids the difference between ReplayGain and EBU r128 backends; every Backend
can now fulfil both tasks. Additionally it eases Backend development as the
difference between the two tag formats is now completely handled in the main
Plugin, not in the Backends.
Allow to configure the target level for R128_* tags separately from REPLAYGAIN_*
tags and skip peak calculation for R128_* tags if possible.
Assert that analysing the same track with different target levels yields
different gain adjustments.
Assert that the replaygain plugin does not write REPLAYGAIN_* tags but R128_*
tags, when instructed to do so.

This test is skipped for the `command` backend as it does not support OPUS.
- document `r128_targetlevel`
- explain difference between `targetlevel` and `r128_targetlevel`
- deprecate `method` option: use `targetlevel` instead.
Add changelog entries for the introduction of the `r128_targetlevel`
configuration option, superseding the `method` option.
@zsinskri
zsinskri force-pushed the r128-targetlevel-config branch from d0b9749 to da602d7 Compare July 22, 2019 11:45
@zsinskri

Copy link
Copy Markdown
Contributor Author

Rebased onto master.

@zsinskri

Copy link
Copy Markdown
Contributor Author

#3056 is merged. This is now ready for review.

@sampsyo sampsyo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great! Here are just a few suggestions.

Comment thread beetsplug/replaygain.py Outdated
Comment thread beetsplug/replaygain.py Outdated
Comment thread beetsplug/replaygain.py Outdated
Comment thread beetsplug/replaygain.py Outdated
Comment thread docs/changelog.rst Outdated
Comment thread docs/plugins/replaygain.rst Outdated
zsinskri and others added 2 commits July 26, 2019 01:02
Apply improvements suggested in GitHub PullRequest beetbox#3065:
- be idiomatic
  - 0 is falsy
  - check enum equality, not identity
  - mutate list by constructing a new one
- improve documentation
  - fix a typo
  - do not mention deprecation of a config option
@sampsyo

sampsyo commented Jul 25, 2019

Copy link
Copy Markdown
Member

Awesome; thank you! This is a heroic effort that required lots of special domain expertise, so I wanted to offer extra appreciation for getting this right. ✨

@sampsyo
sampsyo merged commit ddede4e into beetbox:master Jul 25, 2019
snorkelopstesting2-coder pushed a commit to snorkel-marlin-repos/beetbox_beets_pr_3065_90bdf715-8476-451c-b36a-4c80266114b5 that referenced this pull request Oct 22, 2025
Original PR #3065 by zsinskri
Original: beetbox/beets#3065
snorkelopstesting1-a11y added a commit to snorkel-marlin-repos/beetbox_beets_pr_3065_90bdf715-8476-451c-b36a-4c80266114b5 that referenced this pull request Oct 22, 2025
@snejus snejus added the replaygain replaygain plugin label Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

replaygain replaygain plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants