INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Paul's guide to Album Gain (APE files only)  (Read 2404 times)

paulr

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 527
  • nothing more to say...
Paul's guide to Album Gain (APE files only)
« on: April 21, 2004, 05:09:07 pm »

I am not sure if this is the best place for this post, but since it uses external tools, I figured here was good.  :)  I apologize for the formatting in advance...  The script I show below will probably stretch the post, but I didn't want to split the line as it will be easiest to copy and paste it instead of typing it.



First of all, the disclaimer:  DO NOT attempt this unless you are 100% comfortable with the concepts outlined here.  I suggest going to the Hydrogen Audio forums and doing some research on Foobar2000’s masstagger before attempting this.  DO NOT take my word for anything here…  Verify it for yourself.

Second.  TEST this stuff on COPIES of music files in your library.  Do not just run it without understanding what it’s doing.

Third.  I will NOT be held responsible for anything that happens.  What I am outlining here is what worked for me.  It should work for you, but make sure BEFORE you apply this to your library.

Fourth.  This ONLY works for APEv2 tags (I have not tested it with any other tags.  It will NOT work for MP3’s).  I have very few mp3’s in my library and am not too worried about album gain for them.  The track gain MC calculates is perfect for my MP3s.  I don’t have the patience to figure out how the ID tags used in MP3’s work, so if you would like something like this for MP3’s, please figure it out and feel free to add your method to this post!  Hopefully, the method I outline here for APE files will give you some ideas on how to proceed.

Now, with that out of the way, on to the good stuff…

MC’s replay gain calculations follow the Replay Gain proposal (http://www.replaygain.org) exactly as far as I can tell.  The only thing missing is the analysis for album-wide replay gain.  Album gain is especially useful when listening to albums from artists like Pink Floyd or The Alan Parsons Project, who record individual tracks at widely varying degrees of loudness.  Album gain will analyze the entire album and provide an optimum gain value so that the album *as a whole* fits in with the rest of your library (some songs may still be louder and some quieter than others).

The external tool we will be using for this is foobar2000 (http://www.foobar2000.org).  Foobar also follows the replay gain proposal, except for one important part.  It adds 6 dB to the calculation automatically.  What we want is the album gain calculation from Foobar, but *minus* the 6 dB it adds.  That way, the APE files we process will still match up with the proposal AND with MC’s calculations for all other media types (i.e. MP3).

I will outline the steps below, and will try to explain what is going on at each step:

1.   Make sure all of the tags in your library are up to date.  Later, we will “Update Library from Tags” in MC and you don’t want anything other than the replay gain tag changing.  DO NOT SKIP THIS STEP.
2.   Use Media Center to analyze your library…  This step is probably already complete if you keep up with it.  If you don’t already have this step done, then you aren’t using replay gain anyway and should stop here.
3.   Get yourself a copy of foobar200 at the link above.
4.   In foobar, go to foobar2000>preferences.  Find “core” in the tree and click on it.  Then, in field “Restrict incoming files to”, enter “*.APE” without the quotes.  Click “Save All”, then “Close”, then exit and restart foobar.  Go back to the entry we just made and make sure it stuck…  There have been reports of foobar losing settings, so make sure it is still there.
5.   Next, go to playlist>add directory.  Select the directory that contains the files you want to process for album gain.  If you want to process your entire library, then select the root folder of your library.
6.   Now, select ALL of the songs that show up in the playlist.  Right click and go to “Replay Gain”, next select “Scan selection as multiple albums” OR “Scan selection as album” depending on if you have selected multiple albums or a single album.  This analysis will take some time depending on how many files you are processing….  Foobar stores its replay gains in different tags than MC.  It actually stores track gain, album gain, and track and album peak values.  The tag names are:  replaygain_album_gain, replaygain_track_gain, etc.  Don’t worry about this part.  The new tags that foobar adds will NOT affect Media Center at all… It’s just extra data as far as MC is concerned.
7.   Now that all of your files are analyzed, here comes the masstagger script…  This step WILL MODIFY the replay gain that MC uses.  As stated above, TEST this on COPIES of some of your files to insure it is working correctly BEFORE you apply this to your library.
8.   Right click on the files that were just analyzed and select “Masstagger”, then “Edit tags”.
9.   Under “Actions to Perform” click “Add”
10.   Select “Format value from other fields…” ......  Note:  I suggest copying and pasting the values below.
11.   In “Destination Field Name” enter (without the quotes) “REPLAY GAIN (RADIO)”
12.   In “Formatting Pattern” enter (without the quotes) “$puts(char,.)$puts(tag,$if2(%__replaygain_album_gain%,%_replaygain_track_gain%))$puts(spacer,$strchr($get(tag),$get(char)))$sub($get(tag),6).$num($trim($right($get(tag),$sub($len($get(tag)),$get(spacer)))),0)”
13.   See below for an explanation of the Formatting Pattern script
14.   Hit “OK” and click “Save to file”  Give it a name and save it somewhere handy.  Next time you need it, you can click “Load from file” and just load it up.
15.   Now, simply click “Run”.
16.   Back in Media Center, go to “Media Library” in the tree and select “Audio”.  Then select “File Format”.  Then click on APE in the window.  At the bottom of the screen where it lists all of your APE files, select all the files.  Right click and select “Library Tools” and then “Update Library from Tags”.  Now, all of the album gains are in MC’s Replay Gain field…
17.   Enjoy!  

I hope this guide helps anyone who has been wanting proper album gain inside the GREAT software called Media Center!  If anyone extends this to work on MP3’s, please feel free to add to this thread.
I MUST INSIST however, that BEFORE anyone tries this, they read my warnings up top and understand what they are doing.  I know how much it would upset me if I screwed up my library…  That said, this method has worked for me perfectly, and I am very happy with the results.

If you have any questions, please feel free to ask and I will do my best to help!

Regards,
Paul

Logged

paulr

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 527
  • nothing more to say...
Re:Paul's guide to Album Gain (APE files only)
« Reply #1 on: April 21, 2004, 05:09:22 pm »

Explanation of the Formatting Pattern script:
First, as explained above, foobar automatically adds 6 dB to the replay gain calculation.  We want to remove this adjustment before we update the MC library.  Unfortunately, foobar doesn’t do floating point math, only integer math.  So, we must use some string functions in order to get the correct result…

$puts(char,.) – char is a variable that will hold the decimal point we will need to locate so that we can SAVE the fractional part of the replay gain value.

$puts(tag,_____) – saves the replay gain value into a variable called tag.

$if2(%__replaygain_album_gain%,%__replaygain_track_gain%) – this function tests for the existence of an album gain value.  If there is no album gain value, it uses the track gain value… This is useful for files that are not part of an album.

$puts(spacer,$strchr($get(tag),$get(char))) – This finds the location of the decimal point (char) in the replay gain (tag).

$sub($get(tag),6). – This subtracts 6 from the replay gain (tag) and adds a decimal point.  (the result of the subtraction is a whole number (e.x. 7.12 minus 6 equals 1… NOT 1.12).  Note the decimal point OUTSIDE of the closed parentheses.

$num($trim($right($get(tag),$sub($len($get(tag)),$get(spacer)))),0) – This one removes everything up to and including the decimal point.  What’s left is the fractional portion of the replay gain tag…

Putting an example to this:
Replaygain_album_gain = 7.65

The function builds the new MC Replay Gain (radio) tag thus:
7.65 minus 6 equals 1
PLUS
.
PLUS
the fractional part of 7.65 (.65)
EQUALS
1.65

1.65 gets stored into the “Replay Gain (radio)” tag, which is then read back into MC using the Update Library from Tags function….
Logged
Pages: [1]   Go Up