Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Replaygain scanner should store R128_TRACK_GAIN in opus files and not REPLAYGAIN_TRACK_GAIN #1345

Closed
38github opened this issue Aug 10, 2018 · 44 comments

Comments

@38github
Copy link

Might be what makes the difference in volume between flac and opus.

CDrummond added a commit that referenced this issue Aug 10, 2018
@CDrummond
Copy link
Owner

Can you checkout git/master (for 2.3.3). I've changed the tag reading/writing to use R128_TRACK_GAIN and R128_ALBUM_GAIN for Opus files. NOTE: any previous REPLAYGAIN_TRACK/ALBUM_GAIN tags are not removed.

Does this resolve the issue?

@38github 38github changed the title Replaygain scanner stores R128_TRACK_GAIN in opus files and not also REPLAYGAIN_TRACK_GAIN REMOVE Aug 10, 2018
@38github 38github changed the title REMOVE Replaygain scanner stores R128_TRACK_GAIN in opus files and not also REPLAYGAIN_TRACK_GAIN Aug 10, 2018
@38github
Copy link
Author

I will start up my Arch distro and compile it.

@38github
Copy link
Author

I compiled Arch's AUR package cantata-git and the difference is still there. Opus files play louder than FLAC which is the opposite of some other players that play opus lower than FLAC. deadbeef-git works "like it should" and maybe Alex the developer can exchange some ideas?

@CDrummond
Copy link
Owner

a) Have you confirmed with a tag editor that the correct tags have been written? i.e. jsut to confirm that Cantata is working, and the tags are there.
b) Do the files playback with the correct level in other apps? You mentioned deadbeef. Does this playback Cantata's tagged files with the correct loundness? If so, then issue is MPD. Cantata does not playback files - it simply controls MPD. Have you confirmed that MPD supports the R128_TRACK_GAIN tags for opus?

@38github
Copy link
Author

a) Ican not see if the r128_track_gain tag is added using any of the players/taggers (Cantata, EasyTAG, Deadbeef and VLC). If I had wine installed on this machine I would be able to run Foobar2000 which probably would show it.

b) Scanning using Cantata seem to add replaygain tags to both opus and FLAC files. They play the same volume in Deadbeef and VLC but not in Cantata itself even though that program was used to scan the files. When I open up the files i Deadbeef I can see that they both have REPLAYGAIN_ALBUMGAIN and REPLAYGAIN_TRACKGAIN.

If I scan the opus and the FLAC file in Deadbeef they both get the mentioned tags and play at the same volume in Deadbeef and VLC but again not in Cantata.

c) I found beetbox/beets#2557 which mentions that MPD uses r128 and probably not replaygain for opus if I understood it correctly.

@CDrummond CDrummond changed the title Replaygain scanner stores R128_TRACK_GAIN in opus files and not also REPLAYGAIN_TRACK_GAIN Replaygain scanner should store R128_TRACK_GAIN in opus files and not REPLAYGAIN_TRACK_GAIN Aug 11, 2018
@CDrummond
Copy link
Owner

a) Please use kid3-qt - this shows all tags. If you have correctly scanned an opus file, then the tags will be R128_TRACK_GAIN and R128_ALBUM_GAIN. I have just tested this with a single opus file, and these tags were present. So, I know this is working. If you do not have these tags - then you are running the wrong Cantata version (are you sure you installed it?)

b) Cantata does not play files. MPD plays the files. ALL Cantata is doing is processing and tagging the replay gain values.

Please use a decent tag editor to remove all REPLAYGAIN and R128 tags (as stated Cantata will not remove existing tags). This will then reset the file to a default setting. Then re-scan with a newly built and installed Cantata. Confirm with kid3-qt that R128_TRACK_GAIN and R128_ALBUM_GAIN are in the list of tags. (REPLAYGAIN_TRACK_PEAK and REPLAY_GAIN_ALBUM_PEAK will also be present, as these are calculated, but I don't think these are used). Then play the file with MPD and with deadbeef. Are the levels now correct?

ps. I've updated the issue title to be consistent with how I see this issue. And if correct, then Cantata now writes the correct tag name.

@CDrummond
Copy link
Owner

Any updates? Have you had a chance to try the above?

@38github
Copy link
Author

I created a FLAC and encoded it with opusenc. I then removed all tags from the files with kid3 except the artist and track tag so that cantata would show them. I scanned the two files with cantata they got the same replaygain tags but the opus file also recieved the r128 track and album tags which kid3 confirmed. The opus file does play louder (I guess 3dB louder) than the FLAC. In Deadbeef they also play at different volumes. What caught my attention though is that both replaygain and r128gain have -13.89 values. If I am correct r128 has a lower reference loudness and the tag should have maybe -16.89 or bigger than the replaygain tag.

@38github
Copy link
Author

In Deadbeef the opus file has the following tag values:
REPLAYGAIN_TRACKGAIN: 4.95
REPLAYGAIN_ALBUMGAIN: 4.95
OPUS_HEADER_GAIN: 5.00

These tags are not visible in kid3.

@38github
Copy link
Author

If I scan the files in Deadbeef then the files play back at the same volume in Deadbeef but not in Cantata.

@CDrummond
Copy link
Owner

So, just to be clear - the opus file that Cantata scanned, this should only have; R128_TRACK_GAIN, REPLAYGAIN_TRACK_PEAK, R128_ALBUM_GAIN, and REPLAYGAIN_ALBUM_PEAK. It should not have REPLAYGAIN_TRACK_GAIN and REPLAYGAIN_ALBUM_GAIN. Looking at the code, there is no way Cantata could have added R128_TRACK_GAIN and REPLAYGAIN_TRACK_GAIN So, I am confused when you state:

cantata they got the same replaygain tags but the opus file also recieved the r128 track and album tags

This is not possible just using Cantata. With a fresh file, just scanned by Cantata, it is not possible.

All that I have changes is the tag name that the replaygain _GAIN tags are stored under. The calculation has not, and will not, be changed - it uses libebur128, and always has done.

Again, Cantata does not playback files - MPD does.

If I scan the files in Deadbeef then the files play back at the same volume in Deadbeef but not in Cantata.

Should deadbeef not be writing REPLAYGAIN_TRACK_GAIN? Not REPLAYGAIN_TRACKGAIN??? MPD (which is doing the playback), only reads R128_TRACK_GAIN (AFAIK) for opus.

If deadbeef writes REPLAYGAIN_TRACKGAIN: 4.95 what value does Cantata write for R128_TRACK_GAIN ???

@38github
Copy link
Author

The problem is then that MPD only reads the r128 tags in opus files which leads to music files following different loudness standards.

@38github
Copy link
Author

I did the same thing again but with another file and another computer (Solus) that doesn't have the git version. Cantana added the following tags (kid3 information):

OPUS
REPLAYGAIN_ALBUMGAIN: -7.53dB
REPLAYGAIN_ALBUMPEAK: 1.155877
REPLAYGAIN_TRACKGAIN: -7.53dB
REPLAYGAIN_TRACKPEAK: 1.155877

FLAC
REPLAYGAIN_ALBUMGAIN: -7.53dB
REPLAYGAIN_ALBUMPEAK: 1.155877
REPLAYGAIN_TRACKGAIN: -7.53dB
REPLAYGAIN_TRACKPEAK: 1.000000

No R128_TRACK_GAIN was added the OPUS file. Using Deadbeef 0.7.2 tagger I saw no R128_TRACK GAIN either. Why it shows no R128_TRACK_GAIN might be because the OPUS support in 0.7.2 is, if I am correct, not as good as in the git/master.

When I say Cantata plays I know it is MPD that plays in but I play it from inside of Cantata.

@CDrummond
Copy link
Owner

CDrummond commented Aug 20, 2018

I think we need to clarify a few things.

  1. Only git/master is going to write the R128_XXX tags - as the change is not in a released build.
  2. I thought the change was because for opus the R128_XXX tags should be used? Is that not the case???
  3. As stated, the only change I have made is in the name of the tag. ie. what was REPLAYGAIN_TRACK_GAIN is now (for opus) R128_TRACK_GAIN (likewise for ALBUM_GAIN). Nothing else has changed. i.e. the value that would have been written to REPLAYGAIN_TRACK_GAIN is now (for opus) written to R128_TRACK_GAIN - the exact same value.

Is it safe to assume that you thunk deadbeef produces the correct replaygain values? For both FLAC and Opus? I've never used deadbeef (will try later), but I can see some subtle differences in its replygain scanning code that I could adapt. e.g. It uses a different 'reference' level. However, there is no specific opus scanning code - it would be the same for all codecs.

Can you try the following:

  1. Create 2 untagged FLAC and 2 untagged Opus files of the same track
  2. Use deadbeef to perform replaygain scanning of 1 FLAC and 1 Opus
  3. Use (git/master) Cantata to perform replaygain scanning of the other FLAC and Opus files
  4. List the XX_GAIN, XXX_PEAK headers of all tracks here
  5. Play all tracks in deadbeef. I assume the deadbeef ones will play louder (or quieter?) than the Cantata ones. But, do the Cantata ones play consistent with each other? Please state the loudness order of the tracks.

In this thread https://hydrogenaud.io/index.php/topic,104878.0.html one poster thinks R128_XXX should be REPLAYGAIN_XXX - 5 ... this is all getting a bit messy...

@38github
Copy link
Author

38github commented Aug 20, 2018

  1. Created cantata.flac, cantata.opus, deadbeef.flac and deadbeef.opus. Made sure in kid3 that there were no tags in the files.
  2. Scanned deadbeef.flac and deadbeef.opus with Deadbeef.
  3. Scanned cantata.flac and cantata.opus with Cantata (git).
  4. The results (according to kid3):

deadbeef.flac:
REPLAYGAIN_ALBUMGAIN: -8.520000
REPLAYGAIN_ALBUMPEAK: 1.211718
REPLAYGAIN_TRACKGAIN: -8.510000
REPLAYGAIN_TRACKPEAK: 1.000000

deadbeef.opus:
R128_ALBUM_GAIN: 0
R128_TRACK_GAIN: 0

cantata.flac:
REPLAYGAIN_ALBUMGAIN: -8.52 dB
REPLAYGAIN_ALBUMPEAK: 1.211718
REPLAYGAIN_TRACKGAIN: -8.51 dB
REPLAYGAIN_TRACKPEAK: 1.000000

cantata.opus:
R128_ALBUM_GAIN: -8.52 dB
R128_TRACK_GAIN: -8.52 dB
REPLAYGAIN_ALBUMPEAK: 1.1211718
REPLAYGAIN_TRACKPEAK: 1.211718

@38github
Copy link
Author

38github commented Aug 20, 2018

When using Deadbeef to view the tags the result is the following:
deadbeef.flac:
REPLAYGAIN_ALBUMGAIN: -8.520000
REPLAYGAIN_ALBUMPEAK: 1.211718
REPLAYGAIN_TRACKGAIN: -8.510000
REPLAYGAIN_TRACKPEAK: 1.000000

deadbeef.opus:
REPLAYGAIN_TRACKGAIN: -8.52 dB
REPLAYGAIN_ALBUMGAIN: -8.52 dB
OPUS_HEADER_GAIN: -8.52 dB

cantata.flac:
REPLAYGAIN_ALBUMGAIN: -8.52 dB
REPLAYGAIN_ALBUMPEAK: 1.211718
REPLAYGAIN_TRACKGAIN: -8.51 dB
REPLAYGAIN_TRACKPEAK: 1.000000

cantata.opus:
REPLAYGAIN_ALBUMGAIN: -4.97 dB
REPLAYGAIN_TRACKGAIN: -4.97 dB
REPLAYGAIN_ALBUMPEAK: 1.1211718
REPLAYGAIN_TRACKPEAK: 1.211718
OPUS_HEADER_GAIN: 5.00 dB

In Cantata/MPD, cantata.flac and cantata.opus does not play equally loud. The same goes for deadbeef.flac and deadbeef.opus. However, in Deadbeef the files deadbeef.flac and deadbeef.opus do play equally loud but cantata.flac and cantata.opus does not.

@CDrummond
Copy link
Owner

That's interesting, thanks. Odd that The Cantata opus is both 0 - that's definitely an error. Can you upload the opus files (assuming they are non-copyright files) somewhere, so that I can download and test?


Can I just confirm...

01.flac:
REPLAYGAIN_ALBUMGAIN: -8.52 dB
...
02.flac:
REPLAYGAIN_ALBUMGAIN: -8.520000

Does kid3 really show -8.52 dB for REPLAYGAIN_ALBUMGAIN ? As it has the dB string? Do the Cantata and deadbeef FLACs play the same? (In which case the dB is not required)

@38github
Copy link
Author

Yes, I noticed that too that one adds "dB" and one not. One interesting thing also is that when use Deadbeef's tag editor I can see that the cantata.opus also has a OPUS_HEADER_GAIN = 5.00 dB that the Deadbeef replaygain scan file does not.

@38github
Copy link
Author

https://ufile.io/96rf3
Let me know when you have downloaded it so that I can remove it. Unfortunately it is a copyrighted song but doing these things again with another would have meant a lot of work. I have also put a one day time limit on the download.

@CDrummond
Copy link
Owner

CDrummond commented Aug 20, 2018

OK, but I wont be able to access that file until 5pm BST at the earliest (which is about 5hours from now).


As to OPUS_HEADER_GAIN - that is not created by Cantata. No idea where it is coming from. Perhaps you have the Cantata and deadbeef files mixed up?

[edit] In fact, you do have them mixed up. Cantata does append the dB string to its tags.

@38github
Copy link
Author

I haven't said that Cantata does not add dB. I said that one of them adds dB. I have done the test again and my results are correct. The cantata.* files were scanned with Cantata and the deadbeef.* files were scanned with Deadbeef. In Deadbeef' tag editor the cantata.opus has a OPUS_HEADER_GAIN tag and the deadbeef.opus does not.

@38github
Copy link
Author

Deadbeef (git) might be buggy because now the deadbeef.opus file also has a OPUS_HEADER_GAIN tag but its value is -8.52 dB compared to cantata.opus value which is 5.00 dB

@CDrummond
Copy link
Owner

Cantata does not add OPUS_HEADER_GAIN. You can scan the Cantata code, and you will not find that string (I just have). I've never heard of it before. The only value you have listed with OPUS_HEADER_GAIN is 5.00 - nowhere in the comments above is there a -8.52 associated with OPUS_HEADER_GAIN

You seem to be mixing files up, which is causing a lot of confusion with this issue.

@38github
Copy link
Author

I am not mixing up the files. I have double checked them. I am only reporting the tags the different tag editors report. If the Cantata does not write that tag and Deadbeef still show it then I don't know why that is the case.

@CDrummond
Copy link
Owner

Wait - so its deadbeef showing it? That's different, I only care what a tag editor shows. Hence why asking you to use kid3 (or another, no preference on my end). I think deadbeef is showing you the settings it will use, and the default for this (guessing) is 5db. Therefore, this value does not necessarily come from the file itself.

When I'm asking for values, these need to come from a tag editor - which will show you the only parts that I care about. i.e. I care what is set in the actual file, not what some (good or otherwise) player thinks that values should be.

Now, its possible that OPUS_HEADER_GAIN should be set. Have you tried using a tag-editor to manually set this tag?


I see you have edited your posts above, which makes things clearer - thanks :-)

Is it correct to assume you now have:

deadbeef.opus:
R128_ALBUM_GAIN: 0
R128_TRACK_GAIN: 0
OPUS_HEADER_GAIN: -8.52 dB

cantata.opus:
R128_ALBUM_GAIN: -8.52 dB
R128_TRACK_GAIN: -8.52 dB

If so, and OPUS_HEADER_GAIN is defaulting to 5 - I guess when you play each of these in vlc, deadbeef, that they have different volumes? Cantata lower? What about if you edit cantata.opus manually to have:

R128_ALBUM_GAIN: -8.52 dB
R128_TRACK_GAIN: -8.52 dB
OPUS_HEADER_GAIN: 0.0 dB

Do they now play at the same volume?

@38github
Copy link
Author

Deadbeef is both a player and a tag editor. I will stop using it in this search for a solution if it makes it more difficult.

@38github
Copy link
Author

38github commented Aug 20, 2018

Is it correct to assume you now have:

If I use kid3 that you prefer I only get:

deadbeef.opus
R128_ALBUM_GAIN: 0
R128_TRACK_GAIN: 0

cantata.opus
R128_ALBUM_GAIN: -8.52 dB
R128_TRACK_GAIN: -8.52 dB
REPLAYGAIN_ALBUMPEAK: 1.1211718
REPLAYGAIN_TRACKPEAK: 1.211718

@38github
Copy link
Author

38github commented Aug 20, 2018

If so, and OPUS_HEADER_GAIN is defaulting to 5 - I guess when you play each of these in vlc, deadbeef, that they have different volumes? Cantata lower? What about if you edit cantata.opus manually to have:

Players and files that play with equal loudness:

VLC + cantata.* (opus is a liiiiiiittle louder but can't be more than 1 dB or something)
Deadbeef + deadbeef.*

Players and files that play without equal loudness:

Cantata/MPD + cantata.*
Deadbeef + cantata.*

I wonder why opus developers opted for r128 and made it so difficult to apply popular replaygain. It is starting to drive me crazy and I might soon give up on opus just because of this issue that is important to me.

@CDrummond
Copy link
Owner

...as asked, what about using a tag-editor to set OPUS_HEADER_GAIN to 0.0 dB in cantata.opus? It might be that Cantata just needs to give this field a value? Only guessing though...

@38github
Copy link
Author

38github commented Aug 20, 2018

When I added OPUS_HEADER_GAIN and value 0 the files still played unequally in Cantata and Deadbeef. The same if I set it to 0.0 dB. In VLC the difference was still the 1 dB (guess). When I instead set the value to -8.52 dB Deadbeef played them at equal loudness but Cantata still didn't play them at equal loudness. VLC was the same as before.

@38github
Copy link
Author

38github commented Aug 20, 2018

I edited my post where I posted the tags that Deadbeef shows. This post is after the kid3 results. There are so many numbers and tags that I messed up that one. It is also strange that Deadbeef calls tags REPLAYGAIN which kid3 called R128.

@CDrummond
Copy link
Owner

The replaygain scanning code is based upon https://github.com/jiixyj/loudness-scanner Looking at this, it seems to handle the opus case. Also, R128_TRACK_GAIN, etc, need to be an integer number - so is a different format to REPLAY_TRACK_GAIN. I'll try to port the modifications to Cantata.

I think the reason you see REPLAYGAIN with deedbeaf is that it tries to hide the differences shown in the UI. In the file, I think the R128 tags, etc, are used.

CDrummond added a commit that referenced this issue Aug 21, 2018
@CDrummond
Copy link
Owner

OK, I think I understand things better now.

  1. OPUS_HEADER_GAIN is not really a tag. Its part of the opus header field.
  2. The values written to R128_XXX need to take into account OPUS_HEADER_GAIN. So the total is R128_XXX + OPUS_HEADER_GAIN

Some scanners, and the loudness-scanner above, modify OPUS_HEADER_GAIN. It appears as if this always affects decoding the file. If I had Cantata set this, then running the replaygain scanner again would result in lower values - as (I assume) the raw packets are modfied when ffmpeg loads them.

I've updated Cantata's code to (I think) correctly set R128_XXX, but not adjusting OPUS_HEADER_GAIN

Can you please checkout git/master and see if this is better? Please use new opus files, i.e. ones that have not had any replaygain scanning performed - just so that OPUS_HEADER_GAIN has not been adjusted by anything.

@38github
Copy link
Author

The volume of the scanned cantata.opus is now closer to cantata.flac when being played back by Cantata/MPD. I am guessing the issue can be with MPD (too) because the deadbeef.* files that are played at the same volume in Deadbeef does not do so in Cantata.

@38github
Copy link
Author

The cantata.opus scanned with Cantata now has (according to kid3):

R128_ALBUM_GAIN: -2181
R128_TRACK_GAIN: -2181

@CDrummond
Copy link
Owner

Yup, those values look OK. As stated, the values are integers. The actual value is -2181/256 = -8.52dB

You say the volume is closer. How close? Almost the same, just slightly better? If you play the flac and opus with MPD with MPDs replaygain disabled, is it the same difference then?

@38github
Copy link
Author

38github commented Aug 21, 2018

Oh, thank you for that integer information. I had no idea.

The cantata.* files play at the same volume if I turn off replaygain. It doesn't matter if replaygain is enabled or disabled it plays cantata.opus at the exact same loudness.

@CDrummond
Copy link
Owner

Hmmm... If it plays at the same volume (in MPD I assume) that means that MPD is ignoring the R128 tags. Even if the Cantata values were wrong, I'd expect a difference between replaygain on and off.


I've made a small change to the code. As is, there is no change. But can you please try:

  1. Edit tags/tags.cpp and change line 910 from #if 1 to #if 0
  2. Rebuild Cantata
  3. Again, with a fresh untouched opus, perform RG scanning.

This should update the opus header - and makes the R128 tags all 0 for me. Is the level better with this? The problem is that you can then not turn off replaygain - as the file always has it. However, this is what other appear to do... Its not compiled in by default, as I'm not sure about it yet.

...to be honest, I'm not sure about any of it. Guess I need to compile a custom MPD with proper R128 opus support.

@38github
Copy link
Author

I compile cantata using Arch's AUR service since I am a total "noob" at compiling anything more than using ./configure make make install etc. I am not sure how I can change on .cpp file without disturbing the course of PKGBUILD's compiling.

@38github
Copy link
Author

A lot of people on the net have been against Xiph's decision of the ebu r128 standard instead of replaygain v2 since it creates problems. replaygain v2 is, if I am correct, ebu r128 but with a higher reference volume (89 dB). EBU R128 use "23 LUFS". I wonder why they would not allow opus to have replaygain tags together with r128.

@CDrummond
Copy link
Owner

CDrummond commented Aug 23, 2018

Code updated. Can you try (once more) with untouched opus files?

@38github
Copy link
Author

The opus file is unfortunately still louder.

@CDrummond
Copy link
Owner

Don't think I have any players that correctly read these. Can you try:

  1. With tag editor, edit Cantata's opus and set both R128_XXX_GAIN tags to -901
  2. Better now?
  3. With tag editor, edit Cantata's opus and set both R128_XXX_GAIN tags to -3461
  4. Better now?

Which of these two is better? Are either like the FLAC?

CDrummond added a commit that referenced this issue Aug 27, 2018
that sounds the same between FLACs and OPUS for me with MPD 0.20.21

Also, only apply the difference (when reading tags) if the unmodified
tag is not 0

Issue #1345
@CDrummond
Copy link
Owner

I build MPD 0.20.21 with libopus support. Tried 3 Cantata opus files:

  1. One with R128_XXX set to the REPLAYGAIN_XXX values - but stored in there integer format (e.g. val*256)
  2. One the same as the above but with -5.0db applied
  3. Again, but with +5.0db applied

1 - Volume levels matched
2 - Was louder
3 - Was quieter

So, for me, this issue is now (for MPD at least) resolved.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants