Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Possible Bug in Foobar2000 ReplayGain Scanner (EBU R128) (Read 776 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Possible Bug in Foobar2000 ReplayGain Scanner (EBU R128)

Hi all,

I believe I may have found a bug in the Foobar2000 ReplayGain (RG) scanner. I've been using Foobar2000 as my go-to tool for audio tagging for years, so I’m surprised to be reporting this—surely someone else would’ve noticed by now if this were a widespread issue. But here’s what I’ve observed:

I'm using the EBU R128 compliant scanner with oversampling enabled for true peak detection. The issue is that the calculated gain appears to be incorrect.

In most of my FLAC files, you can estimate the LUFS value (as if scanned with bs1770 or ffmpeg loudnorm, which are both EBU R128 compliant) using this formula:

LUFS = -18 - ReplayGain

For example, Foobar2000 reports a track gain of -1.86 dB for one of the tracks (and it's similarly wrong across the entire album). According to the formula, this would correspond to:
LUFS = -18 - (-1.86) = -16.14 dB

However, when I scan the same track using bs1770 and loudnorm, both report approximately -10.20 LUFS. That’s a nearly 6 dB difference, which seems too large to be a minor variation or rounding error.

I also tested the track with the older ReplayGain algorithm in Foobar2000, and it gave a track gain of -2.61 dB—closer, but still not accurate. Using metaflac (which uses the legacy ReplayGain algorithm, not EBU R128), I got:
REPLAYGAIN_TRACK_GAIN = -8.58 dB
That’s yet another value, quite different from both the EBU R128 and old RG methods in Foobar.

Here are some additional details:

Foobar2000 version: 2.24.3 (64-bit)

Also tested with an older 32-bit version, with the same results

No errors appear in the console log

The file plays normally, so the audio itself doesn't seem corrupted

I’ve rescanned, deleted tags, and re-tagged multiple times

I searched the forum but couldn’t find any similar reports

I’d be happy to share the file in question, though I’m not sure of the best way to do that.

Thanks in advance for looking into this!


Re: Possible Bug in Foobar2000 ReplayGain Scanner (EBU R128)

Reply #1
And how many channels does this audio file have?

Re: Possible Bug in Foobar2000 ReplayGain Scanner (EBU R128)

Reply #2
stereo.
Here are tags as foobar2000 wrote them and for the same file results with 'loudnorm'(which are essentially the same as ffmpeg loudnorm or bs1770):
----
Code: [Select]
zh@acus:/mnt/nvmeraid/music/flac/Hadouk Trio/Live à FIP (2006)$ metaflac --list --block-type="VORBIS_COMMENT"  2.03.Loukoumotive.flac
METADATA block #1
  type: 4 (VORBIS_COMMENT)
  is last: false
  length: 830
  vendor string: reference libFLAC 1.3.1 20141125
  comments: 25
    comment[0]: ALBUM=Live à FIP
    comment[1]: ALBUM DYNAMIC RANGE=13
    comment[2]: ARTIST=Hadouk Trio
    comment[3]: COMMENT=ExactAudioCopy v0.95b3
    comment[4]: DATE=2006
    comment[5]: DISCNUMBER=2
    comment[6]: DYNAMIC RANGE=13
    comment[7]: GENRE=World Fusion
    comment[8]: MUSICBRAINZ_ALBUMID=b4df2be1-abec-46f1-abe4-143d73b8ebf1
    comment[9]: MUSICBRAINZ_ALBUMSTATUS=Official
    comment[10]: MUSICBRAINZ_ALBUMTYPE=Live
    comment[11]: MUSICBRAINZ_ARTISTID=c747d48e-975b-4b46-bf81-4ff42df82bb4
    comment[12]: MUSICBRAINZ_DISCID=vvOKAOmG23kfvSv8bN_Cl3UE6RY-
    comment[13]: MUSICBRAINZ_RELEASEGROUPID=d109473a-6448-3a21-a413-1e43849fcb66
    comment[14]: MUSICBRAINZ_TRACKID=1b3fd245-8e3b-416f-9498-ae51fad8eddb
    comment[15]: ORIGINAL RELEASE DATE=2006
    comment[16]: TITLE=Loukoumotive
    comment[17]: DISCTOTAL=2
    comment[18]: TRACKTOTAL=7
    comment[19]: TRACKNUMBER=03
    comment[20]: ZEXCLUDE=1
    comment[21]: replaygain_track_gain=-1.86 dB
    comment[22]: replaygain_track_peak=1.168876
    comment[23]: replaygain_album_gain=-1.21 dB
    comment[24]: replaygain_album_peak=1.168876

--- after  loudnorm:


Code: [Select]
zh@acus:~$ metaflac --list --block-type="VORBIS_COMMENT"  rg.flac
METADATA block #1
  type: 4 (VORBIS_COMMENT)
  is last: false
  length: 762
  vendor string: reference libFLAC 1.3.1 20141125
  comments: 23
    comment[0]: ALBUM=Live à FIP
    comment[1]: ALBUM DYNAMIC RANGE=13
    comment[2]: ARTIST=Hadouk Trio
    comment[3]: COMMENT=ExactAudioCopy v0.95b3
    comment[4]: DATE=2006
    comment[5]: DISCNUMBER=2
    comment[6]: DISCTOTAL=2
    comment[7]: DYNAMIC RANGE=13
    comment[8]: GENRE=World Fusion
    comment[9]: MUSICBRAINZ_ALBUMID=b4df2be1-abec-46f1-abe4-143d73b8ebf1
    comment[10]: MUSICBRAINZ_ALBUMSTATUS=Official
    comment[11]: MUSICBRAINZ_ALBUMTYPE=Live
    comment[12]: MUSICBRAINZ_ARTISTID=c747d48e-975b-4b46-bf81-4ff42df82bb4
    comment[13]: MUSICBRAINZ_DISCID=vvOKAOmG23kfvSv8bN_Cl3UE6RY-
    comment[14]: MUSICBRAINZ_RELEASEGROUPID=d109473a-6448-3a21-a413-1e43849fcb66
    comment[15]: MUSICBRAINZ_TRACKID=1b3fd245-8e3b-416f-9498-ae51fad8eddb
    comment[16]: ORIGINAL RELEASE DATE=2006
    comment[17]: REPLAYGAIN_TRACK_GAIN=-7.80 dB
    comment[18]: REPLAYGAIN_TRACK_PEAK=1.358385
    comment[19]: TITLE=Loukoumotive
    comment[20]: TRACKNUMBER=03
    comment[21]: TRACKTOTAL=7
    comment[22]: ZEXCLUDE=1

for loudnorm i only scanned 1 file so album values are missing, but i think this is sufficient. here is the audio file information:

Code: [Select]
zh@acus:~$ mediainfo rg.flac
General
Complete name                            : rg.flac
Format                                   : FLAC
Format/Info                              : Free Lossless Audio Codec
File size                                : 56.3 MiB
Duration                                 : 8 min 27 s
Overall bit rate mode                    : Variable
Overall bit rate                         : 931 kb/s
Album                                    : Live à FIP
Part                                     : 2
Part/Total                               : 2
Track name                               : Loukoumotive
Track name/Position                      : 03
Track name/Total                         : 7
Performer                                : Hadouk Trio
Genre                                    : World Fusion
Recorded date                            : 2006
Cover                                    : Yes
Cover type                               : Cover (front)
Cover MIME                               : image/jpeg
Comment                                  : ExactAudioCopy v0.95b3
ALBUM DYNAMIC RANGE                      : 13
DYNAMIC RANGE                            : 13
MUSICBRAINZ_ALBUMSTATUS                  : Official
MUSICBRAINZ_ALBUMTYPE                    : Live
MUSICBRAINZ_RELEASEGROUPID               : d109473a-6448-3a21-a413-1e43849fcb66
ORIGINAL RELEASE DATE                    : 2006
ZEXCLUDE                                 : 1

Audio
Format                                   : FLAC
Format/Info                              : Free Lossless Audio Codec
Duration                                 : 8 min 27 s
Bit rate mode                            : Variable
Bit rate                                 : 930 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 44.1 kHz
Bit depth                                : 16 bits
Compression mode                         : Lossless
Replay gain                              : -7.80 dB
Replay gain peak                         : 1.358385
Stream size                              : 56.3 MiB (100%)
Writing library                          : libFLAC 1.3.1 (2014-11-25)
MD5 of the unencoded content             : FB415EEB5935FDAD30BCFCEBFA3B228B

Hope this helps!
thank you

Re: Possible Bug in Foobar2000 ReplayGain Scanner (EBU R128)

Reply #3
Please share the track. You can send a private message to me, I will deliver to Peter if I can confirm it.

Re: Possible Bug in Foobar2000 ReplayGain Scanner (EBU R128)

Reply #4
Hi, here is the link to the file. PM sent as well.
Link removed by moderator

Re: Possible Bug in Foobar2000 ReplayGain Scanner (EBU R128)

Reply #5
Your track is HDCD encoded and you have HDCD decoder installed. HDCD decoder lowers the volume by 6 dB for you as that's how it's configured to work by default when track uses Peak Extension feature. Otherwise it could not expand the peaks.

Re: Possible Bug in Foobar2000 ReplayGain Scanner (EBU R128)

Reply #6
Your track is HDCD encoded and you have HDCD decoder installed. HDCD decoder lowers the volume by 6 dB for you as that's how it's configured to work by default when track uses Peak Extension feature. Otherwise it could not expand the peaks.
Ha !!! You're 100% correct (as expected :) !!!
I completely forgot i had HDCD plugin installed ... and that decoding is done as input to replaygain...downside is if one uses those files outside foobar2000 which i do (Roon server) ... years ago i had setup foobar2000 to convert hdcd to 24bit flac so i can forget about hdcd decoding but lost that setup long time ago and never figured out how to re-create it (it wasn't important). Until now - time to brush up on old posts :)
Thank you Case !!!

Re: Possible Bug in Foobar2000 ReplayGain Scanner (EBU R128)

Reply #7
If I may recommend, do not permanently convert to 24-bits. I spent recently days reading, debugging and studying HDCD stuff and for example noticed that the reverse-engineered HDCD implementation that was supposed to match "reference" Windows Media Player output infact did not match it entirely. And all the decoders made after it had the same bug but in addition didn't match its output on bit level. If you alter the files permanently you run a chance of having an incorrect conversion.

My recommendation would instead be to switch the HDCD decoder to never halve loudness. That way RG values aren't complete bogus and RG takes care of preventing clipping. All the benefits with no downsides.

Re: Possible Bug in Foobar2000 ReplayGain Scanner (EBU R128)

Reply #8
If I may recommend, do not permanently convert to 24-bits. I spent recently days reading, debugging and studying HDCD stuff and for example noticed that the reverse-engineered HDCD implementation that was supposed to match "reference" Windows Media Player output infact did not match it entirely. And all the decoders made after it had the same bug but in addition didn't match its output on bit level. If you alter the files permanently you run a chance of having an incorrect conversion.

My recommendation would instead be to switch the HDCD decoder to never halve loudness. That way RG values aren't complete bogus and RG takes care of preventing clipping. All the benefits with no downsides.
Thank you - ... i have compiled libhdcd as well as hdcd-extract (https://github.com/bp0/libhdcd and https://github.com/rjek/hdcd-fixup respectively) and was thinking of it being 'reference' level. Think ffmpeg uses same library as well.
Would you advise against it ?
Thanks again !

Re: Possible Bug in Foobar2000 ReplayGain Scanner (EBU R128)

Reply #9
As you no doubt have seen the ffmpeg decoder is based on old foo_hdcd sources, which was based on old hdcd.exe. Original foo_hdcd replicated the hdcd.exe flaw, and newer optimizations have altered the output to no longer match reference.

Perhaps I'm anal, but I'd absolutely keep my lossless CD rips in their original format. That saves space, keeps them burnable in original format if ever needed, allows verifying their validity with online CD databases and allows utilizing any possible future fixes in HDCD decoders.

If you want to read the full story where my HDCD opinions come from, you are welcome to do so in this thread: https://hydrogenaud.io/index.php/topic,126955.0.html. That thread also has a link to my version of foo_hdcd decoder that is to the best of my knowledge the most correct implementation.

Re: Possible Bug in Foobar2000 ReplayGain Scanner (EBU R128)

Reply #10
I agree with Case here - keep CD rips as CD rips.
If you want to bring them on a portable player that does not decode HDCD, then ... just use a lossy?