Revision: 2323
          http://gtkpod.svn.sourceforge.net/gtkpod/?rev=2323&view=rev
Author:   tmzullinger
Date:     2009-04-18 00:09:01 +0000 (Sat, 18 Apr 2009)

Log Message:
-----------
Prefer Audiophile (Album) over Radio (Track) gain

Also adjust the ordering of the tags checked.  We now check the APE tag
first, because if a user has set it they likely would want to use that
value instead of the one added automatically by Lame at encode time.
Thanks to Tino Keitel for the patch.

This also resets the GainData struct in mp3_get_track_ape_replaygain(),
so that we don't end up using some mix of data from the LAME Tag and the
APE tag for ReplayGain.

Modified Paths:
--------------
    gtkpod/trunk/ChangeLog
    gtkpod/trunk/src/mp3file.c

Modified: gtkpod/trunk/ChangeLog
===================================================================
--- gtkpod/trunk/ChangeLog      2009-04-18 00:08:51 UTC (rev 2322)
+++ gtkpod/trunk/ChangeLog      2009-04-18 00:09:01 UTC (rev 2323)
@@ -1,3 +1,19 @@
+2009-04-17  Todd Zullinger  <[email protected]>
+
+       Patch from: Tino Keitel
+
+       * src/mp3file.c:
+         Prefer Audiophile (Album) over Radio (Track) gain.
+
+         Adjust the ordering of the tags checked.  We now check the APE
+         tag first, because if a user has set it they likely would want
+         to use that value instead of the one added automatically by
+         Lame at encode time.
+
+         Also resets GainData struct in mp3_get_track_ape_replaygain(),
+         so that we don't end up using some mix of data from the LAME
+         Tag and the APE tag for ReplayGain.
+
 2009-04-17  Paul Richardson <phantom_sf at users.sourceforge.net>
 
        * Reverted src/mp3file.c and configure.in due to lack of released

Modified: gtkpod/trunk/src/mp3file.c
===================================================================
--- gtkpod/trunk/src/mp3file.c  2009-04-18 00:08:51 UTC (rev 2322)
+++ gtkpod/trunk/src/mp3file.c  2009-04-18 00:09:01 UTC (rev 2323)
@@ -2066,7 +2066,6 @@
  *
  * Read the specified file and scan for Ape Tag ReplayGain information.
  *
- * The function only modifies the gains if they have not previously been set.
  */
 gboolean mp3_get_track_ape_replaygain(const gchar *path, GainData *gd)
 {
@@ -2094,6 +2093,13 @@
        g_return_val_if_fail (gd, FALSE);
        g_return_val_if_fail (path, FALSE);
 
+       gd->radio_gain = 0;
+       gd->audiophile_gain = 0;
+       gd->peak_signal = 0;
+       gd->radio_gain_set = FALSE;
+       gd->audiophile_gain_set = FALSE;
+       gd->peak_signal_set = FALSE;
+
        file = fopen (path, "r");
 
        if (!file)
@@ -2158,9 +2164,9 @@
                goto rg_fail;
        if (fread(dbuf, 1, data_length, file) != data_length)
                goto rg_fail;
-       
+
        for (i = 0; i < entries; i++) {
-               if (gd->radio_gain_set && gd->peak_signal_set) break;
+               if (gd->radio_gain_set && gd->peak_signal_set && 
gd->audiophile_gain_set) break;
                pos = pos2 + entry_length;
                if (pos > data_length - 10) break;
 
@@ -2174,6 +2180,41 @@
 
                if (entry_length + 1 > sizeof(buf))
                        continue;
+
+               /* album gain */
+               if (!gd->audiophile_gain_set && !strcasecmp(&dbuf[pos],
+                                       "REPLAYGAIN_ALBUM_GAIN")) {
+                       memcpy(buf, &dbuf[pos2], entry_length);
+                       buf[entry_length] = '\0';
+
+                       d = g_ascii_strtod(buf, &ep);
+                       if ((ep == buf + entry_length - 3)
+                                       && (!strncasecmp(ep, " dB", 3))) {
+                           gd->audiophile_gain = d;
+                               gd->audiophile_gain_set = TRUE;
+                               DEBUG ("album gain (ape): %f\n", 
gd->audiophile_gain);
+                       }
+
+                       continue;
+               }
+               if (!gd->peak_signal_set && !strcasecmp(&dbuf[pos],
+                                       "REPLAYGAIN_ALBUM_PEAK")) {
+                       memcpy(buf, &dbuf[pos2], entry_length);
+                       buf[entry_length] = '\0';
+
+                       d = g_ascii_strtod(buf, &ep);
+                       if (ep == buf + entry_length) {
+                               d *= 0x800000;
+                               gd->peak_signal = (guint32) floor(d + 0.5);
+                               gd->peak_signal_set = TRUE;
+                               DEBUG ("album peak signal (ape): %f\n",
+                                       (double)gd->peak_signal / 0x800000);
+                       }
+
+                       continue;
+               }
+
+               /* track gain */
                if (!gd->radio_gain_set && !strcasecmp(&dbuf[pos],
                                        "REPLAYGAIN_TRACK_GAIN")) {
                        memcpy(buf, &dbuf[pos2], entry_length);
@@ -2259,19 +2300,32 @@
     gd.audiophile_gain_set = FALSE;
     gd.peak_signal_set = FALSE;
 
-    mp3_get_track_lame_replaygain (path, &gd);
+    mp3_get_track_ape_replaygain (path, &gd);
+    if (gd.audiophile_gain_set)
+    {
+       track->soundcheck = replaygain_to_soundcheck (gd.audiophile_gain);
+       DEBUG ("using ape album gain\n");
+       return TRUE;
+    }
     if (gd.radio_gain_set)
     {
        track->soundcheck = replaygain_to_soundcheck (gd.radio_gain);
-       DEBUG ("using lame radio gain\n");
+       DEBUG ("using ape radio gain\n");
        return TRUE;
     }
 
-    mp3_get_track_ape_replaygain (path, &gd);
+    mp3_get_track_lame_replaygain (path, &gd);
+    if (gd.audiophile_gain_set)
+    {
+       track->soundcheck = replaygain_to_soundcheck (gd.audiophile_gain);
+       /* This is highly unlikely, lame does not write audiofile gain. */
+       DEBUG ("using lame album gain\n");
+       return TRUE;
+    }
     if (gd.radio_gain_set)
     {
        track->soundcheck = replaygain_to_soundcheck (gd.radio_gain);
-       DEBUG ("using ape radio gain\n");
+       DEBUG ("using lame radio gain\n");
        return TRUE;
     }
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to