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: Difference between Mp3gain and Replaygain (Read 141613 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Difference between Mp3gain and Replaygain

Replaygain and MP3Gain

I was confused about the differences between Replaygain and MP3Gain, so wrote this note explaining the difference.  I hope this is the correct forum, please move it if it would be better somewhere else.

I realise that the FAQ has a section "Replaygain: WaveGain vs. MP3Gain" but that doesn't obviously cover the features I describe below.

I illustrate the difference by describing adjustment of playback volume using MP3Gain and Foobar2000 (a Replaygain-aware MP3 player). I'm assuming the reader is familiar with the priciples behind Replaygain.

------------------------------------------------------------------------- -

An MP3 file is composed of many blocks of audio, one after the other. Each block corresponds to a few milliseconds of music. Each block has a global gain field which tells an MP3 file player how loud to play that block.  In addition to these global gain fields, each MP3 file can also have a Replaygain header which applies to the whole file, and which tells a Replaygain-aware MP3 player how loud to play that file.

MP3Gain determines the Replaygain values for the MP3 file. MP3Gain then writes to the global gain header of every block, adjusting them all up or down by the same amount in order to achieve those Replaygain values.  MP3Gain also writes a Replaygain header which applies to the whole MP3 file. Since MP3Gain has adjusted the global gain field for each block to give the right volume, the volume adjustments in that Replaygain header will be small.  This MP3 file will then play at the right volume in all players, whether or not they are Replaygain-aware.

Foobar2000 doesn't write to the global gain field of individual blocks. It determines and writes only the Replaygain header which applies to the whole MP3 file.  The value it writes to the Replaygain header will therefore be different to that written by MP3Gain since each block is left with it's original global gain field setting.

It is potentially easy to screw this up.

For example, let's say we have a file which is VERY LOUD. We use Foobar2000 to adjust the Replaygain header, which of course writes a value which tells a Replaygain-aware player to turn everything down a lot.

Now suppose we use MP3Gain to adjust the playback volume. And suppose that this time MP3Gain is set to IGNORE tags in the file (i.e. "Options" > "Tags" > "Ignore (do not read or write tags)" is checked). It will still adjust the global gain field of each block (and turn them all down), but it will ignore the Replaygain header, i.e. leave it at the setting which Foobar2000 used.

If we then play our MP3 file in a player which is NOT Replaygain-aware, everything will be fine - the MP3 file will play at the right volume because the global gain field for each individual block has been turned down.

BUT what happens if we then play the MP3 file in an Replaygain-aware player? Now the file will be played much too quietly because the global gain field settings for each block have been turned down AND the Replaygain header for the whole MP3 file is still telling the player to turn down the whole file.

The safest solution to all this is to make sure that if you use MP3Gain on your files, it is NOT set to ignore tags in the file. Then it won't matter which you use to adjust the Replaygain (Foobar2000 or MP3Gain, in any order) since either will set the value of Replaygain correctly.

Edit:  Correction. Since I wrote the above paragraph I have got to know foobar2000 better.

There are several different types of headers (usually called "tags") which hold information about an MP3 file - two of the most common are ID3 and APE.  Most MP3 taggers and CD rippers use ID3 tags to hold artist information.  MP3Gain uses APE tags to hold MP3Gain and Replaygain information.

Because foobar2000 ignores ID3 tags if it finds an APE tag, it is better NOT to let MP3Gain add tags to MP3 files if you intend to use foobar2000 as your MP3 player.  If you do let MP3Gain write tags, you will find that foobar2000 will not display Artist/Album/Track etc correctly unless that information is also in the APE tag.  Since most MP3 taggers use the ID3 tags to store that information,  it will almost certainly not be displayed.

You will lose very little by not letting MP3Gain write tags - each individual block of music has had it's global gain header adjusted so it will always play correctly to within 1.5dB (MP3Gain's accuracy).  To set MP3Gain to not write tags to the file make sure "Options" > "Tags" > "Ignore (do not read or write tags)" is NOT checked.  MP3Gain can also remove tags which it has previously added.  If you want the ReplayGain correction to be exact, you can use foobar2000 to adjust the ReplayGain.  foobar2000 can be configured to write ReplayGain values to ID3 tags so any previously-stored Artist/Album/Track information is not lost.

The above correction may not apply to players other than foobar2000.

------------------------------------------------------------------------- -

Note that the advantage of using MP3Gain is that the global gain header for each block MUST be supported by all MP3 players, hardware or software.  The Replaygain header is not supported by all players.

Difference between Mp3gain and Replaygain

Reply #1
Experts, do you confirm the above ? Can I include it in the FAQ ?

Difference between Mp3gain and Replaygain

Reply #2
IIRC it's not a 'global gain header' but a 'global gain field' in each frame header.

Also

Quote
This Replaygain header tells a Replaygain-aware player the gain settings which apply to the WHOLE FILE so that - in conjunction with the many global gain settings which MP3Gain has just written - the MP3 is played at the right volume.


The wording doesn't make it clear the Replaygain header doesn't necessarily be supported for the file to still sound right.

Difference between Mp3gain and Replaygain

Reply #3
IIRC, I had problems with mp3gain screwing up my tags when I set it to not ignore them.

For example, I'd ripped and encoded a CD in EAC which correctly tagged the mp3 files. Then I ran mp3gain album mode on them (set to not ignore tags). Loaded them into fb2k and the tags were gone, thus having to use masstagger to set them.

On the next CD rip/encode I did everything the same except told mp3gain to ignore tags, and then the tags were recognized when loaded into fb2k.

Difference between Mp3gain and Replaygain

Reply #4
Quote
IIRC, I had problems with mp3gain screwing up my tags when I set it to not ignore them.

For example, I'd ripped and encoded a CD in EAC which correctly tagged the mp3 files. Then I ran mp3gain album mode on them (set to not ignore tags). Loaded them into fb2k and the tags were gone, thus having to use masstagger to set them.

On the next CD rip/encode I did everything the same except told mp3gain to ignore tags, and then the tags were recognized when loaded into fb2k.
[a href="index.php?act=findpost&pid=230400"][{POST_SNAPBACK}][/a]


It didn't exactly mess up your tags; it actually didn't touch them.  Rather it appended an additional APEv2 tag to the end of your file with the gain info.  Foobar does not support mixing APEv2 and ID3v2 tags, so it ignored the ID3v2 tags and read the APEv2.

One solution would be to use APEv2 tags on your files.

Difference between Mp3gain and Replaygain

Reply #5
But the thing is, I've never used ID3v2; I've always had EAC use v1.1.  Regardless, I'll give it a try again when I'm at home to verify it.

I don't know that EAC can add APE tags. Can it?

Difference between Mp3gain and Replaygain

Reply #6
I can confirm this behaviour when using this procedure, EAC adds id3v1.1 tags, mp3gain adds APEv2 tag to store undo info, Foobar2000 doesn't display any tags, but Winamp does. The id3v1.1 tags are still there. If I tell mp3gain to remove all tags it added, the problem is solved. Perhaps there is a way to tell Foobar to ignore APEv2 tags and only read id3v1.1 tags instead.

Difference between Mp3gain and Replaygain

Reply #7
I can confirm that using only APE tags will solve this dilemma.  If you rip a CD with EAC to MP3 and choose NOT to tag them, you can safely mp3gain or masstag the files via foobar in any order you please and the information will be written, displayed, and played correctly.

This is will the ignore tags option of mp3gain left unchecked.

Difference between Mp3gain and Replaygain

Reply #8
To solve this problem you can:

A) Use foobar2000 to calculate the RG info and then apply it on mp3gain
or
B) Scan the files and apply the gain in p3gain then use tag.exe to write ape2 tags and delete the unneeded id3v1 tags.
"You have the right to remain silent. Anything you say will be misquoted, then used against you."

Difference between Mp3gain and Replaygain

Reply #9
I've edited my original post in response to some of the comments here.  I'm glad if it proves useful.

I realise that there are other issues with MP3Gain and Replaygain.  For example, the Replaygain header always allows track OR album gain to be selected in your MP3 player, but if MP3Gain is set to ignore tags then it is necessary to make this decision beforehand.  And then there are the tagging problems discussed above.

The purpose of my post was to describe the differences between volume adjustments as implemented by Replaygain and MP3Gain as I couldn't find that information elsewhere.

Difference between Mp3gain and Replaygain

Reply #10
Added a correction concerning ID3/APE tags after poking foobar2000 with a sharp stick for a few weeks.

Difference between Mp3gain and Replaygain

Reply #11
Quote
Since MP3Gain has adjusted the global gain field for each block to give the right volume...
I assume that each block is scaled by an identical value?  Is that true?  If so, you might want to explicitly state it, to avoid questions like this one.  :-)

(n.b. When the blocks are scaled with non-identical scale factors, it is called "compression.")
------- Rick -------
--------------------

Difference between Mp3gain and Replaygain

Reply #12
Quote
I assume that each block is scaled by an identical value?  Is that true?

Thanks for your advice.

I want to be careful with wording here.  I don't know if the value in the global gain headers are logarithmic or linear, so "scaling" might not be quite the right word.  I also don't want to mention decibels etc etc too much - I want to keep it as plainly-worded as possible.  I know I have just added a mention of 1.5dB in my recent edit.

I've edited the 4th paragraph to say: "MP3Gain then writes to the global gain header of every block, adjusting them all up or down by the same amount in order to achieve those Replaygain values."

Do you think this sums up your suggestion without being technical?

Difference between Mp3gain and Replaygain

Reply #13
Quote
To solve this problem you can:

A) Use foobar2000 to calculate the RG info and then apply it on mp3gain
or
B) Scan the files and apply the gain in p3gain then use tag.exe to write ape2 tags and delete the unneeded id3v1 tags.
[a href="index.php?act=findpost&pid=230512"][{POST_SNAPBACK}][/a]


B is essentially what I do.  Perhaps it would be possible to ask Glen to add an option to copy ID3 fields to ape in the next mp3gain release?
"You can fight without ever winning, but never win without a fight."  Neil Peart  'Resist'

Difference between Mp3gain and Replaygain

Reply #14
Quote
Quote
I assume that each block is scaled by an identical value?  Is that true?

I've edited the 4th paragraph to say: "MP3Gain then writes to the global gain header of every block, adjusting them all up or down by the same amount in order to achieve those Replaygain values."

Do you think this sums up your suggestion without being technical?
[a href="index.php?act=findpost&pid=236513"][{POST_SNAPBACK}][/a]

Absolutely!  Thanks for taking the comment in the spirit it was offered.

-- Rick
------- Rick -------
--------------------

Difference between Mp3gain and Replaygain

Reply #15
Quote
Perhaps it would be possible to ask Glen to add an option to copy ID3 fields to ape in the next mp3gain release?

Or maybe ask fb2k developers to improve the tag reading? Seems a bit more logical to me. Fb2k is an excellant player, but why can't it handle tags that are not in sync? I asked once in the fb2k forum, but never got an answer unfortunately.

Difference between Mp3gain and Replaygain

Reply #16
i still have some doubts ...

on mp3gain, to what tags it refers on Options/Tags? Glogal (mp3gain) or Frame?

If Global,

"Options" > "Tags" > "Ignore (do not read or write tags)"
would make mp3gain ignore foobar's correction, which is the oposite we want

"Options" > "Tags" > "Recalculate (do not read tags)"
would make mp3gain recalculate the global tag, after computing the frame ones, which we would like

"Options" > "Tags" > "Don't check while adding files"
it would do as if the file has never been gained, either glogally, or by frame?

i allways used MP3gain, and have no problem with foobar reading my tags ... so i don't get this also.

and what should i do, if i want to apply mp3gain to my files, and play them throug fb2k (but not use fb2k gain calculus)?

Difference between Mp3gain and Replaygain

Reply #17
UP the question!

Difference between Mp3gain and Replaygain

Reply #18
Quote
i still have some doubts ...

on mp3gain, to what tags it refers on Options/Tags? Glogal (mp3gain) or Frame?

Global

Quote
If Global,

"Options" > "Tags" > "Ignore (do not read or write tags)"
would make mp3gain ignore foobar's correction, which is the oposite we want

That's right.

Quote
"Options" > "Tags" > "Recalculate (do not read tags)"

would make mp3gain recalculate the global tag, after computing the frame ones, which we would like

That's right.

Quote
"Options" > "Tags" > "Don't check while adding files"
it would do as if the file has never been gained, either glogally, or by frame?

Reading the Help file, with this option MP3Gain doesn't read the tags for each file while it is adding the files, but would read them later when it came to correct the gain for each file.

The end result will be exactly the same as if NO options are checked, but the files will load faster when a directory is selected.

Quote
i allways used MP3gain, and have no problem with foobar reading my tags ... so i don't get this also.

Great!  There's a couple of reasons why this might happen (a) because you have MP3Gain set to "Ignore (do not read or write tags)" or (b) because your MP3 Artist/Album/Track etc information is stored in APE tags, not ID3 tags.  So when Foobar finds the APE tag, it finds ALL the information.

Quote
and what should i do, if i want to apply mp3gain to my files, and play them throug fb2k (but not use fb2k gain calculus)?

In Foobar preferences, Playback tab, Replaygain box, select "disabled".  Foobar will ignore the Replaygain information, but your MP3 will still play at the correct level because MP3Gain has adjusted the gain headers of all the individual blocks of music (which Foobar cannot ignore).

Difference between Mp3gain and Replaygain

Reply #19
Quote
Quote
"Options" > "Tags" > "Recalculate (do not read tags)"

would make mp3gain recalculate the global tag, after computing the frame ones, which we would like

That's right.

Quote
and what should i do, if i want to apply mp3gain to my files, and play them throug fb2k (but not use fb2k gain calculus)?

In Foobar preferences, Playback tab, Replaygain box, select "disabled".  Foobar will ignore the Replaygain information, but your MP3 will still play at the correct level because MP3Gain has adjusted the gain headers of all the individual blocks of music (which Foobar cannot ignore).
[a href="index.php?act=findpost&pid=240028"][{POST_SNAPBACK}][/a]


so, it i run replaygain, with "Options" > "Tags" > "Recalculate (do not read tags)" checked, it would clean the fb2k calculations ... so i don't need to disable the replaygain box in foobar ...

Quote
Quote
"Options" > "Tags" > "Recalculate (do not read tags)"

would make mp3gain recalculate the global tag, after computing the frame ones, which we would like

That's right.

Quote
i allways used MP3gain, and have no problem with foobar reading my tags ... so i don't get this also.

Great!  There's a couple of reasons why this might happen (a) because you have MP3Gain set to "Ignore (do not read or write tags)" or (b) because your MP3 Artist/Album/Track etc information is stored in APE tags, not ID3 tags.  So when Foobar finds the APE tag, it finds ALL the information.


i don't use APE tags ... and i don't have MP3Gain set to Ignore (do not read or write tags) either ... :|

Difference between Mp3gain and Replaygain

Reply #20
I struggled with this issue when I first started using mp3gain with Foobar too.
Now I make sure that my mp3s have proper APE tags BEFORE I mp3gain them. There are two ways that I do this:
1) For mp3s that have info in ID3 tags, I use a tag editor to make sure the info is correct, load them into Foobar and have Foobar rewrite the tags as APE tags, which it will do by default when you right-click and select "rewrite tags from database" (the type of tags Foobar writes when it performs that action are set in the standard inputs section of the preferences). Then I mp3gain normally.
2) For ripping new CDs, I use EAC with wapet.exe (http://www.saunalahti.fi/~cse/files/wapet.zip) with the command line at http://www.hydrogenaudio.org/forums/index....t=ST&f=15&t=203 to write the APE tags at the time of encoding. Then I mp3gain normally and all is right with the world.

Difference between Mp3gain and Replaygain

Reply #21
Quote
so, it i run replaygain, with "Options" > "Tags" > "Recalculate (do not read tags)" checked, it would clean the fb2k calculations ... so i don't need to disable the replaygain box in foobar ...
Ermmmm... it's not that simple. Trouble is, Foobar will write it's Replaygain information to the tag type you have set up in Preferences > Playback > Input > Standard inputs.  If you have that set to "ID3v2 and ID3v1" then that's the tags it will use.

If you then MP3Gain the file, it will write ReplayGain values to an APE2 tag.  Your file will now have two lots of ReplayGain info in two different tags.

Fortunately, Foobar will see the APE2 tag written by MP3Gain and ignore everything else, including the ID3 tags which it earlier wrote itself.  So MP3Gain will effectively have hidden the tags which Foobar wrote, even though they are still there.

If you set Foobar's Preferences > Playback > Input > Standard inputs to "APE2 and ID3v1" then everything WILL happen as you suggest - then Foobar will write it's ReplayGain va;ues to an APE tag and MP3Gain will "clean" it.

Hope this helps!

Difference between Mp3gain and Replaygain

Reply #22
another solution would be if MP3Gain would read/support ID3v2 tags in which foobar has written the replaygain values.

this would be acceptable for me because i have an CD-MP3 player in my car which supports ID3v2 and i want to use MP3Gain with it.
member of the "i have a cat-avatar"-group ;)

Difference between Mp3gain and Replaygain

Reply #23
Just wanted to note that the tag issues I referenced in my post seem to be resolved using the new foobar2000 0.9beta, probably due to it's new ability to merge tag types. Hurrah!

Difference between Mp3gain and Replaygain

Reply #24
I'm just starting to use MP3Gain on my MP3 files. I noticed this behaviour. The "clipping may occur" warning has me a bit concerned. Why would it compute values that may cause clipping? Should I do something to make it so that clipping won't occur?

Edit: I added the /k switch but still get the warning when I do

mp3gain.exe *.mp3 >mp3gain.log
mp3gain.exe /a /c /k *.mp3

Quote
01 There Is No Fourth Tower.mp3
Recommended "Track" dB change: 7.040000
Recommended "Track" mp3 gain change: 5
Max PCM sample at current gain: 13291.338871
Max mp3 global gain field: 255
Min mp3 global gain field: 141

02 Two Bear Feet.mp3
Recommended "Track" dB change: 9.020000
Recommended "Track" mp3 gain change: 6
Max PCM sample at current gain: 11568.669029
Max mp3 global gain field: 255
Min mp3 global gain field: 141

03 Bargaining With Borneo Cannibals.mp3
Recommended "Track" dB change: 8.860000
Recommended "Track" mp3 gain change: 6
WARNING: some clipping may occur with this gain change!
Max PCM sample at current gain: 14026.897870
Max mp3 global gain field: 235
Min mp3 global gain field: 141

04 The Price Is Your Heart!.mp3
Recommended "Track" dB change: 7.780000
Recommended "Track" mp3 gain change: 5
WARNING: some clipping may occur with this gain change!
Max PCM sample at current gain: 14106.647114
Max mp3 global gain field: 255
Min mp3 global gain field: 141

Recommended "Album" dB change for all files: 7.900000
Recommended "Album" mp3 gain change for all files: 5
WARNING: with this global gain change, some clipping may occur in file 03 Bargaining With Borneo Cannibals.mp3
WARNING: with this global gain change, some clipping may occur in file 04 The Price Is Your Heart!.mp3