Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ReplayGain functionality #96

Open
mooninite opened this issue Apr 1, 2019 · 12 comments
Open

Update ReplayGain functionality #96

mooninite opened this issue Apr 1, 2019 · 12 comments

Comments

@mooninite
Copy link

mooninite commented Apr 1, 2019

The metaflac tool allows users to update their flac files with REPLAYGAIN_* tags. The support offered by metaflac is lacking:

  1. No multi-channel support.
  2. All files must have the same characteristics regarding bit, sample rate, and channels.
  3. Loudness algorithm is unknown? In-house?

Over time there have been advances in loudness algorithms and even a well-adopted standard has come about called "ITU BS.1770-4" a.k.a. "EBU R 128" and a few tools have been created that follow this standard.

I'm creating this issue to update metaflac because most users and even some software (Soundkonverter) uses metaflac's replay gain functionality. Updating it here will benefit everyone.

Would this project be willing to adopt an EBU R 128 library and switch metaflac to use it?

@lvqcl
Copy link
Contributor

lvqcl commented Apr 1, 2019

"R128GAIN is a FFmpeg and SoX based EBU R128 compliant loudness scanner." IMHO it's too heavy for flac / metaflac. Also, abandoned? (last update was in 2014).

libebur128, on the other hand, looks compact enough.

@Moonbase59
Copy link

Moonbase59 commented Jun 24, 2019

Since EBU R128/ITU-R BS.1770 are the better (and agreed-upon standard) algorithms for loudness calculation, and even ReplayGain v2 uses these nowadays, I’d propose to add these. Probably the old ReplayGain v1 algorithm (and the --add-replay-gain option) could be kept a while for backwards compatibility.

Since bs1770gain and others re-use the "old ReplayGain tags" BUT add "LU"/"LUFS" as a unit (instead of "dB"), there should be a means to set the desired unit.

We’d need a possibility to set the desired loudness target, too: EBU R128 (Europe) use -23 LUFS and gating, ATSC A/85 (USA) use -24 LUFS and no gating, and ReplayGain v2 uses -18 LUFS (for compatibility reasons, assumed to be about the same as the old 89 dB reference level).

In theory, there could be 3 "modes" like "ebu", "atsc" and "replaygain" using the exact same loudness code and generating tags like these (example from my tests) — or just specify the intended loudness target (like -18.0, -23.0 or -24.0 LUFS).

EBU:
REPLAYGAIN_ALBUM_GAIN=-12.4 LU
REPLAYGAIN_ALGORITHM=BS.1770
REPLAYGAIN_REFERENCE_LOUDNESS=-23.0 LUFS
REPLAYGAIN_TRACK_GAIN=-12.4 LU

ATSC:
REPLAYGAIN_ALBUM_GAIN=-13.4 LU
REPLAYGAIN_ALGORITHM=BS.1770
REPLAYGAIN_REFERENCE_LOUDNESS=-24.0 LUFS
REPLAYGAIN_TRACK_GAIN=-13.4 LU

REPLAYGAIN:
REPLAYGAIN_ALBUM_GAIN=-7.4 LU
REPLAYGAIN_ALGORITHM=BS.1770
REPLAYGAIN_REFERENCE_LOUDNESS=-18.0 LUFS
REPLAYGAIN_TRACK_GAIN=-7.4 LU
— and/or (for compatibility) —
REPLAYGAIN_ALBUM_GAIN=-7.4 dB
REPLAYGAIN_ALGORITHM=BS.1770
REPLAYGAIN_REFERENCE_LOUDNESS=89 dB
REPLAYGAIN_TRACK_GAIN=-7.4 dB

If defaults are needed, I’d suggest using EBU 128 (BS.1770-2 or newer, -23 LUFS target, gating), because these turn out to be most widely used. ATSC A/85 was mainly intended for HD TV anyway, if I remember correctly.

There have been some changes in the BS.1770 specs over the years, I’d recommend using at least BS.1770-2 (Gate 10) or BS.1770-3 (some filter added, I forgot which).

Side note: EBU R128/ITU-R BS.1770 are clearly the better algorithms for loudness perception, and also use less computing power. They tend to "punish" modern overcompressed (mostly Pop/Metal/Rock) productions as well as overcompressed commercials. The overall experience is much more pleasing, although some might need to get used to the now "quieter" Pop/Rock/Metal albums.

Eventually, this might end the notorious "loudness wars" (I hope) and stop producers from compressing everything to death just in order to be perceived "louder" than the competition (und thus losing beautiful detail!).

So YES, I agree with the TO and very much hope this can be done. In the broadcasting world, we use it for so many years now, there are tools that support it alreday (bs1770gain, ffmpeg) and I strongly support the notion to also "have it in the original place" (FLAC, Xiph)!

See also: http://bs1770gain.sourceforge.net/

@lvqcl
Copy link
Contributor

lvqcl commented Jun 24, 2019

In theory, there could be 3 "modes" like "ebu", "atsc" and "replaygain" using the exact same loudness code and generating tags like these (example from my tests) — or just specify the intended loudness target (like -18.0, -23.0 or -24.0 LUFS).

EBU:
REPLAYGAIN_ALBUM_GAIN=-12.4 LU
REPLAYGAIN_ALGORITHM=BS.1770
REPLAYGAIN_REFERENCE_LOUDNESS=-23.0 LUFS
REPLAYGAIN_TRACK_GAIN=-12.4 LU

And all existing players won't be able to recognize these tags. Why break backward compatibility? It's totally unnecessary IMHO.

@Moonbase59
Copy link

Moonbase59 commented Jun 25, 2019

That’s actually not true—many are moving with the times. Professional broadcasters and playout systems use this STANDARD for a long time now. Software like Audacious, Foobar2000, ffmpeg and IDJC already support this, just to mention a few. It’s more a question like »Why use fb2k or bs1770gain instead of native tools?«.

I strongly feel there IS a need to adopt newer standards (it can easily be done WITHOUT breaking backwards compatibility). Technological innovation (and worldwide standards) are important—had we been closing our eyes to progess forever, we wouldn’t have Linux, for instance, or even the beautiful FLAC format! :-)

@lvqcl
Copy link
Contributor

lvqcl commented Jun 25, 2019

My post was not about algorithms, but about tags.
For example, foobar2000 uses new algorithm to calculate loudness, but it writes tags that are 100% compatible with the old standard.

@Moonbase59
Copy link

Moonbase59 commented Jun 28, 2019

That’s why I suggest having a "replaygainv2" mode that still uses "dB" instead of "LU"/"LUFS". I do agree that it’s still necessary to have a mode that uses the new algorithm but still keeps the old tag format (like, for instance, desbma’s r128gain).

@Moonbase59
Copy link

I made my own "loudgain" in the meantime (uses libebur128), maybe you want to pick up some ideas. It’s far from perfect but perfectly fits our needs.
I’d still love to see EBU R128/RG2 functionality in the native tools. :-)

@averms
Copy link

averms commented Aug 21, 2019

I've always felt like having replaygain scanning and tagging is a bit out of the scope of metaflac. If r128gain and loudness-scanner exist, why not use them instead? It is too bad that soundKonverter uses metaflac but I think that is their problem.

@jherby2k
Copy link

I support updating the algorithm, or at least adding R128 as an option, but don't see why the tag format should change. http://wiki.hydrogenaud.io/index.php?title=ReplayGain_2.0_specification says to keep the tag format as-is.

@DanielTheGreat
Copy link

Why waste time with Metaflac when you have such an amazing tool as Xrecode3, which, apart from converting anything to anything (audio), can analyse and tag (or apply to the audio samples) any output file (1–6 channels) with ReplayGain (album and/or track), EBU-R128, or (what he calls "Loudness Normalization") EBU-R128 with dynamic clip-limiting? [Some (mostly classical) multi-channel SACDs I've ripped, when scaled using EBU-R128 cause clipping, so I now always use the Loudness Normalization method for Mch SACDs.]

[Not associated with Xrecode3; just a huge fan!]

Daniel

@audiomuze
Copy link

I agree flac and metaflac should be enhanced to include support for EBU R 128 via --add-replay-gain type parameter.

Perhaps the simplest is to leverage libebur128 and add a parameter --add-r128-replay-gain but write the same tags. It'd be a real pity to see flac and metaflac remain behind current standards in handling loudness.

@ktmf01
Copy link
Collaborator

ktmf01 commented Dec 31, 2022

There is a tool to scan FLAC files here: https://pypi.org/project/r128gain/ and https://github.com/desbma/r128gain

Anyone is welcome to supply a patch to implement this directly into flac and metaflac.

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

No branches or pull requests

8 participants