Add Album Volume Increase via Replay Gain Tag

I have recently discovered MP3Tag and hope to use it to achieve a task that I'm sure is quite simple but as I can fine no scripting guide, is taxing me.

I have around 4000 mp3 files that I have ripped over the years. I have recently done a major clean up of the key tags so I can port them to my iPhone. I have used foobar2000 to apply ReplayGain to level the volume and have tested with both the "Scan Per File Track" and "Scan Selection as Single Album" However, even if I set the base decibel level from 89db to 94db, It still makes the same adjustment to the ReplayGain tags. I would like to increase the overall volume of all files to prevent me having to play everything at full volume on the iPhone. For some reason many tracks, even at full volume are too quite when using the std earphones (rather than the in ear ones) on a busy street. Foobar ReplayGain seems to decrease all the tracks by 5-7db and I would rather it left them at the same level. I think the base db setting is only for the foobar player and not for the tag creation.
Thus I thought I could use MP3tag to change the adjustment on the Album ReplayGain Tag from the -7 to say 0 across all files. I'm sure it can easily be done with the custom actions but I have no idea how to find syntax for the script. I have already set up one custom action to convert the ReplayGain tags to iTunes ones using Format Tag “COMMENT ITUNNORM “ to "$rg2sc(%REPLAYGAIN_TRACK_GAIN%)"

Hi James Buist, yes, the ReplayGain method makes a file quietly when ReplayGain is activated within the Player, that means levels down the original volume in order to give the loudness regulator the headroom to work. There is a standard lost of 6dB, that means half the volume, that means the amplifier needs 6dB more power to produce the same volume as without ReplayGain.
Please read directly from the author David Robinson how ReplayGain works.
There is a forum post with following links of interest:
Anyone figure out how to port RG to WMP PEAKVALUE and AVERAGEVALUE?

If you want to do some simple math on the already correct calculated ReplayGain values (basically not recommended), then look into the Mp3tag scripting language. There are functions for adding or multiplying and such more.
Well ... such scripting functions do you find within foobar too.



This will ingore the decimal values behind a . or ,

I tried that but it just changes comment itune norm to 5 and writes over the rest of the data that has come from converting replay gain info.

Any other ideas?

Thanks for that. Very informative and explains a good deal. The question now is how to bump up the overall volume to compensate as many tracks are still too quiet on the iphone even at max volume. And I do have the volume limit turned off.

Maybe you need mp3gain for these files

This formula can handle adding of positive and negative dB values.

For example +6.00 dB.
$div($add(+600,$replace(%replaygain_track_gain%,'.',)),100)'.'$num($replace($mod($add(+600,$replace(%replaygain_track_gain%,'.',)),100),'-',),2)' dB'
+2.02 dB
-2.78 dB
+8.02 dB
+3.22 dB

For example -3.33 dB.
$div($add(-333,$replace(%replaygain_track_gain%,'.',)),100)'.'$num($replace($mod($add(-333,$replace(%replaygain_track_gain%,'.',)),100),'-',),2)' dB'
+2.02 dB
-2.78 dB
-1.31 dB
-6.11 dB

Edit. Added ' dB' at end of the numberstring.

Important Note
As user 'kieranwood85' pointed out in his post from 2012-02-01 (following in this thread) the scripting formula shown above in this post has a quirk. There is a small region in the number line, where the formula does not respect negative values.

In my post from 2012-02-02 (following in this thread) I modified the formula to work correctly, hopefully ;-).
Add Album Volume Increase via Replay Gain Tag



I want to apply this to a flac file. the problem is in flac' the units string ' dB' most also be inckuded in the value. How do I add the string " dB" to the right of the new value? I could find the & operator for strings


Why do you search for a '&' operator? Should it be documented in the manual? What should it do?
Well, you could not find such an operator, because there is no such operator defined within Mp3tag scripting language. Maybe you know the '&' operator from some other programming language, but these are different worlds. Mp3tag has no explicite concatenation operator. Pretty bad, from my point of view. So ... if you want to see something side by side, then write it side by side.
I have edit my post from above to have a trailing ' dB'.


Many thanks!

Sorry for all the noob questions, but I'm a little bit confused. What exactly am i suppose to do with you line of code? I copied and paste it in the value (View-customize coulombs).

At firs it seemed to work as all track gain values updated correctly. I did "select all" and saved' but by checking track gain data using foobar2000 nothing was physically changed! all original values are still there. I guess I putting the script in the wrong place? Why are there "functions" available in the "value" field' if they have no affect on the tag data' just the way data is displayed? In other words' how do I tun scripts? I tried creating a new action using your line of script' but I didn't know which option to choose..

can you please add a simple explanation what to do with functions' so they have actual effect on data that can be saved permanently?


The list view is generally an output area for the stored data.
Yes, you can manually edit cells in the list view spread sheet, but only in the case of the underlying tag-field is writeable.

There are other ways to edit tag-field content.

  • Use the "Tag-Panel" ("field view") for mainly manually work on some basic tag-fields.
  • Use a ready made "Converter".
  • Use an "Action".

To change an existing value by applying a complicated formula written in Mp3tag Scripting Language the best way is to use an action "Format value", for example:

Begin Action Group Test 2010#20101023.ReplayGainTrackGain_Math
Action #1
Actiontype 5: Format value
Formatstring: $div($add(+600,$replace(%replaygain_track_gain%,'.',)),100)'.'$num($replace($mod($add(+600,$replace(%replaygain_track_gain%,'.',)),100),'-',),2)'÷dB'
Note: Replace each special ÷ character with one space character.
End Action Group Test 2010#20101023.ReplayGainTrackGain_Math (1 Action)


See new action group in post following in this thread ...
Add Album Volume Increase via Replay Gain Tag


OK thanks

Well I finally got it to "work" but unfortunately it does not work... I was able to change the replaygain data successfully. All values were increased by 6 dB. saved it. An even Foobar2000 confrimed the changes. BUT neither Foobar2000 nor by Logitec Squeezebox make any use of the replaygain data! Both players simply ignore it' as if there was no replaygain tagging available. If I rescan using Foorab2000 and reapply replaygain' then both players work fine using it.

I think that mp3tag changes the data's values correctly in terms pf the values' but it messes up some overhead code that tells the players that replaygain data is available.

According to author's site' there should be a 3bit code name embedded in the replaygain word:

When I look at original replaygain data (unmodified by mp3tag) using mp3tag spreadsheet; I see the dB units as text next to the values. Perhaps after modifying the data the ' dB' shouldn't re written back? or maybe there should be an additional field with code word?

What do you think mate?

Thanks again

One more interesting fact:

If I re-save the data written by mp3tag using fooba2000 edit replaygain option by simply copying the value written by mp3tag and pasting it back using foobar2000 replaygain for this specific file returns to normal! (used by the players). What could be the problem here?

Do you remember that I have said "basically not recommended"?

Well, it seems to be an ambigous case.
Please test following action group and report back.

Begin Action Group Test 2010#20101023.ReplayGainTrackGain_Math

Action #1
Actiontype 5: Format value

Action #2
Actiontype 5: Format value

Action #3
Actiontype 5: Format value
Formatstring: $div($add(+600,$replace(%replaygain_track_gain%,'.',)),100)'.'$num($replace($mod($add(+600,$replace(%replaygain_track_gain%,'.',)),100),'-',),2)'÷dB'

Action #4
Actiontype 5: Format value

Note: Replace each special ÷ character with one space character.
End Action Group Test 2010#20101023.ReplayGainTrackGain_Math (4 Actions)


Make sure that the players are configured to "Use Replay Gain Adjusting" and "Preferred Mode is Track Mode" or something like that.

If you use WinAmp, then check out the different settings.
And if you are already in the specific WinAmp settings dialog, then you see that WinAmp already has a built in ReplayGain PreAmp, which makes the current game of manually adjusting the ReplayGain values rather needless and superflously.


See new action group in post following in this thread ...
Add Album Volume Increase via Replay Gain Tag


OK tried it, but still no go.

Even if I manually cut the original replaygain value using mp3tag spreadsheet' save it to the file with the filed blank' then paste the same original value back to the cell' save it again, that's it for the replaygain data for this file.. it will no longer work for any player. If I only repeat the same thing using foobar2000 replaygain edit option' everything goes back to normal and the players can use it again. Looks like a bug in mp3tag. It messes things up... By the way' using Foobar2000 edit replaygain option' I do not see the dB chars' only a value like -7.1234567... Looks like the data mp3tag is writing is in a non-numerical format' but in text format...

The problem for me is I'm not using my pc for playback' I using Squeezebox player' which does not have a pre-gain option.

Th replaygain method scale the digital words before they are passed optically to the amplifier to be converted from digital to analog' there for a scaled down word translate in lower dynamic range' as the DAC does not use the full scale resolution of the 16bits.. Replaygain reduces music files of audiophile reference cd's such as jazz music by up to 10dB... This is really an anti-audiophile approach... I"d prefer to switch it off' until I'll be able to control it

Thanks again. If you"ll manage to figure out the problem' please let me know

Sorry to hear this, because the action group from above did it for me, together with Winamp.

There might be a quirk in Mp3tag.
But it could also be a quirk in the player software, will say, it is possible that the player is not able to read the altered sequence of RG tag-fields which do not following one after another in a continuous series after the change of one RG tag-field.
After changing the value of a RG tag-field Mp3tag writes the changed tag-field at the end of the current tag-block, so that the sequence of RG tag-fields is broken.

But there is another thing I have seen.
The overall size of the entire tag-block changes, even when there is no change in the length of the accessed RG tag-field.

This causes Winamp to display two different values in two dialogs of the same file. RG does not work.

After running the action group from above Winamp displays the same value in both dialogs of the same file. RG does work.


So, this might be a little out of date but I have just read this article and it seems to be what I was looking for.

I am intending on using the fb2k RG scanner to tag all my music with the four RG tags and then convert these to the iTunes 'COMMENT iTunNorm' using $rg2sc. Nothing particularly special so far.

I wanted, however, to increase the REPLAYGAIN_TRACK_GAIN values by 3dB and send these to $rg2sc, so something like,


This is to overcome the problem I have seen elsewhere when the 89dB SPL is just a little too low for iProducts. Since the original RG tag is designed for RG compliant devices (which should have a pre-amp feature to boost quiet outputs as in fb2k) I see no need to actually add 3dB to the RG tag. This avoids the tag re-ordering problem mentioned above.

All good so far,

I might have spotted a small problem though. I was going to use the action from DetlevD earlier to create a intermediate tag that I send to $rg2sc.

The code was,

$div($add(+600,$replace(%replaygain_track_gain%,'.',)),100)'.'$num($replace($mod($add(+600,$replace(%replaygain_track_gain%,'.',)),100),'-',),2)' dB'

This does work for the examples given but breaks for a specific case when the original gain is -6.xx dB. In this case the first part of the equation would go something like,

-6.51 dB : Start
-651 : Remove decimal point
-51 : Add 600
0 : Divide by 100

Notice the '-' (negative) sign has gone now. The second part of the equation will always be positive and so the output becomes positive. I get 0.50 dB, I should have -0.50.

Also when the RG value becomes positive there is no '+' (positive) symbol prepended which I think is needed. This missing '+' might explain the change in overall tag size? Not sure.

So finally I propose the action below to add an offset of RG gains whilst keeping the exact format written by fb2k.

[$ifgreater($add(+300,$replace(%RGTRACKPLUS1%,'.',)),0,'+','-')$replace($div($add(+300,$replace(%RGTRACKPLUS1%,'.',)),100),'-',)'.'$num($replace($mod($add(+300,$replace(%RGTRACKPLUS1%,'.',)),100),'-',),2)' dB']

(Note: the %RGTRACKPLUS1% tag can be swapped for either %REPLAYGAIN_ALBUM_GAIN% or %REPLAYGAIN_TRACK_GAIN%. I create the tag %RGTRACKPLUS1% automatically to be the track gain unless not available in which case use the album gain.)

The output of this can then be fed into $rg2sc and so create the iTunNorm tags with an offset from the RG tags. Obviously the offset can be changed by replacing 300 (for 3dB) with 600 (for 6dB) or what ever you fancy.

I have tried this on a few tracks and the results I get by manually adding 3dB to the REPLAYGAIN_TRACK_GAIN then running $rg2sc match those I get by adding 3dB with the code above. Also if I use the code to directly overwrite the REPLAYGAIN_TRACK_GAIN all of the tags are recognised immediately in fb2k and winamp. A small note is that it sometimes takes winamp a little while before the track gain is updated in the 'Basic Info' tab but it is always correct and up-to-date in the 'ID3v2' tab.

Let me know what you think because I'm going to run this through my collection soon and don't want to get it wrong.


Well years later now ... never thought about such weird things again of manipulating RG info data.

Hmm, I cannot see any quirk with the formula given above in the posts from Oct 23/25 2010.
See attached picture.
I did use your example value -6.51 dB and lift it by +6 dB to 0.51 dB.
Please explain, where is the problem?
Is it the missing '+' sign?

See also ...
"Gains are specified textually in decibels. Negative gains (attenuation) are prefixed with a '-'. Positive gains have no prefix."


Ok so I might be misunderstanding the scales being used, but the problem is,
-6.51 + 6.00 = -0.51
-6.51 + 7.00 = 0.49

Thanks for this reference. It means foobar2000 is not tagging to that specification since it adds '+' symbols.

Is there a better way now?