Author Topic: Volume Adjustment on OPUS files  (Read 958 times)

Genadio

  • Newbie
  • *
  • Posts: 2
When I move the Volume Adjustment slider in the Edit window for the mp3 tracks then I can see that the tag RVAD is added.

But when I do it for opus tracks then there is no new tags in the file. I see that the file was modified and I can hear that the volume is changed, but I do not see any changes in tags.

Where the musicbee's volume adjustments are is saved for opus files?

hiccup

  • Sr. Member
  • ****
  • Posts: 7880
RVAD is not an OPUS tag, so that will be the reason it's not written.

If you do some searches on OPUS + loudness adjustment you will find they created something that is following neither ID3 nor Vorbis Comment protocols for that.
It's a bit of a mess.
You will find the ReplayGain adjustments sometimes in 'R128...' tags, but I believe they are usually written in the fileheader. (so hidden from 'normal' view)

The Tag editor > Volume adjustment slider is something different than ReplayGain.
It's setting may also be written in the header, or maybe it only exists in MusicBee's database, I don't really know, but with some testing you should be able to figure that out.

edit:
Also make sure you use a recent MB 3.5 patch version.
There have been some improvements on handling OPUS files last year.
Last Edit: January 17, 2023, 06:23:00 PM by hiccup

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2459
If you do some searches on OPUS + loudness adjustment you will find they created something that is following neither ID3 nor Vorbis Comment protocols for that.
It's a bit of a mess.
Proposals for volume normalisation came after the release of both MP3 and Vorbis and there was no formally agreed upon implementation. Especially in the early days, it was largely at the discretion of different program vendors implementing their own algorithms.

Being the first new format introduced after the adoption of R128 - a broadcasting standard - Opus was arguably the first one to get it right.

You will find the ReplayGain adjustments sometimes in 'R128...' tags, but I believe they are usually written in the fileheader. (so hidden from 'normal' view)
As per the RFC, Opus added two optional tags: R128_TRACK_GAIN and R128_ALBUM_GAIN.
Opus gain values are integers in the range an integer from -32768 to 32767:

Tag Definitions

Any tools that add other tags probably do so to try and be backwards compatible with players expecting to find (non-standardised) replay gain values.
RVAD may be such a tag, though I've never seen it before and it would appear to be a red herring here.

A file header isn't a hidden area separate from the rest of the data. The name 'header' just refers to its location at the start of the file, before the audio data.
Unless you deliberately do something weird, all metadata values are written in a file header, whether it's MP3, FLAC, Opus or anything else.
A notable exception are ID3v1 tags, which weren't part of the original MP3 specs and are written after the audio data. A file footer, if you will.

Vendors may choose to store sensitive information in a way that makes it harder to alter though. For example, iTunes stored song copyright and purchaser details in a way that couldn't be easily edited by end users. Read about QuickTime atoms if you want to see how complicated a company like Apple can make things.

But back to the original thread topic...

The Tag editor > Volume adjustment slider is something different than ReplayGain.
It's setting may also be written in the header, or maybe it only exists in MusicBee's database, I don't really know, but with some testing you should be able to figure that out.
As per tag values below, for FLAC and MP3 it looks like MusicBee just adds any gain adjustment value to the calculated amount before writing the tag. This makes sense, as there's no reason to know if a value is calculated or adjusted - we just want a final amount to adjust by.

After volume analysis on two copies of the same file:
FLAC: Unadjusted
    REPLAYGAIN_TRACK_GAIN: -0.04 dB
    REPLAYGAIN_TRACK_PEAK: 0.890106
    REPLAYGAIN_ALBUM_GAIN: +0.04 dB
    REPLAYGAIN_ALBUM_PEAK: 0.912440

FLAC: +1 dB adjustment
    REPLAYGAIN_TRACK_GAIN: +0.96 dB
    REPLAYGAIN_TRACK_PEAK: 0.890106
    REPLAYGAIN_ALBUM_GAIN: +1.04 dB
    REPLAYGAIN_ALBUM_PEAK: 0.912440
MP3: Unadjusted
    replaygain_track_gain: +0.22 dB
    replaygain_track_peak: 0.860118
    replaygain_album_gain: +0.04 dB
    replaygain_album_peak: 0.912440
 
MP3: +1 dB adjustment
    replaygain_track_gain: +1.22 dB
    replaygain_track_peak: 0.860118
    replaygain_album_gain: +1.04 dB
    replaygain_album_peak: 0.912440
However, it does appear there is a bug in Opus volume adjustment.
Opus: Unadjusted
     R128_TRACK_GAIN : -22
     R128_ALBUM_GAIN : 0

Opus: +1 dB adjustment
     R128_TRACK_GAIN : -22
     R128_ALBUM_GAIN : 0
It appears no adjustment is being made to the calculated gain amount before writing tag values to Opus files.
Bee excellent to each other...

hiccup

  • Sr. Member
  • ****
  • Posts: 7880
Opus was arguably the first one to get it right.
So you believe there is a 'right'?
Could you point to an official EBU document that describes how their R128 values are supposed to be written to/stored in audio file formats?
I'm interested to learn what OPUS is doing 'right', and MP3 (ID3v2) and FLAC (Vorbis Comments) are doing 'wrong'.

Quote from: hiccup
...but I believe they are usually written in the fileheader. (so hidden from 'normal' view)

Quote from: zak
The name 'header' just refers to its location at the start of the file, before the audio data.
Yes, and that is why I specifically described it as the file header. It's there on purpose.
R128 was mainly developed for broadcasting and streaming purposes.
And for the purposes of that kind of loudness adjustment it is important that the loudness adjustment data can be read before the actual audio/video data.
Hence, it is in the header.
Last Edit: January 18, 2023, 09:21:56 PM by hiccup

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34359
However, it does appear there is a bug in Opus volume adjustment.
Opus: Unadjusted
     R128_TRACK_GAIN : -22
     R128_ALBUM_GAIN : 0

Opus: +1 dB adjustment
     R128_TRACK_GAIN : -22
     R128_ALBUM_GAIN : 0

It appears no adjustment is being made to the calculated gain amount before writing tag values to Opus files.
For OPUS files, there is also the file gain header which isnt a tag - MB prefers writing to that with just the residual to that value is written to the R128 tags. I guess thats not strickly the correct thing to do but should still work correctly with other players

hiccup

  • Sr. Member
  • ****
  • Posts: 7880
MB prefers writing to that with just the residual to that value is written to the R128 tags.
So that explains why the R128 album gain tag always shows 0dB?
The actual value for that is exclusively in the fileheader?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34359
If you do an album analysis then yes. The R128 track value will be the delta from that

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2459
Opus was arguably the first one to get it right.
So you believe there is a 'right'?
Could you point to an official EBU document that describes how their R128 values are supposed to be written to/stored in audio file formats?
I'm interested to learn what OPUS is doing 'right', and MP3 (ID3v2) and FLAC (Vorbis Comments) are doing 'wrong'.
Right in the sense that the people working on Opus recognised the need for volume normalisation and adopted a published standard created by a working group of audio professionals.
Normalisation (i.e. replay gain) for other formats was an afterthought and there were varying implementations. The original MP3 spec didn't even think to include tags for things like track title and artist.
Bee excellent to each other...

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34359
For OPUS files, there is also the file gain header which isnt a tag - MB prefers writing to that with just the residual to that value is written to the R128 tags. I guess thats not strictly the correct thing to do but should still work correctly with other players
just checked what foobar is doing, and it looks like it uses the same approach so what MB is doing is not out of line

hiccup

  • Sr. Member
  • ****
  • Posts: 7880
Normalisation (i.e. replay gain) for other formats was an afterthought and there were varying implementations.
And now with OPUS we have yet another implementation.

But lucky for us all, R128 is available for all of them.
It's just OPUS that has made things more difficult for 'consumer' audio players.

sveakul

  • Sr. Member
  • ****
  • Posts: 2469
This looks like an interesting, on-topic tool for Opus fans and others who have time (lots?) and a willingness to test it:

Zoog: Zero Opus Output Gain:  https://github.com/FrancisRussell/zoog

Windows binaries:  https://github.com/FrancisRussell/zoog/releases/

hiccup

  • Sr. Member
  • ****
  • Posts: 7880
This looks like an interesting, on-topic tool for Opus fans and others who have time (lots?) and a willingness to test it:
Even for those not interested in using that tool, his analysis and description of the workings and potential issues with how OPUS implemented R128 is impressive and gives a lot of insight in the matter.
So thanks!