Hello,

This is the first in a series of patches I hope to do to update from
patches in from our bug tracker. I hope as well to get comments, and
the community gives these concepts and patches the big ACK or NACK. I
will try to keep these patches up to date until they're either
accepted or given the NACK, at which time I'll pop it off my guilt and
close the bug. Most of these patches I have neutral feelings about
acceptance. I may attempt to provide new better versions with
criticism though, please keep in mind that I am not a developer.

This patch works for me with the test mp3 at the bug link below,
though I don't notice or know the difference with before or after.

For more information about this particular patch, please see:
http://musicpd.org/mantis/view.php?id=562

Feel free to pull it from my git tree:
Using a mpd-mk tree as a reference to minimize bandwidth:
git clone --reference mpd-mk/ git://repo.or.cz/mpd-mk/avuton.git

or just plain old:
git clone git://repo.or.cz/mpd-mk/avuton.git

From: Avuton Olrich <[EMAIL PROTECTED]>
Date: Sun, 23 Nov 2008 23:37:28 +0000 (-0800)
Subject: Add RVA2 tag support to MPD
X-Git-Url: 
http://repo.or.cz/w/mpd-mk/avuton.git?a=commitdiff_plain;h=ff66792aad6ba1ef888b0381577c93a27c8b76a7

Add RVA2 tag support to MPD

This patch adds RVA2 (relative volume adjustment) tag
support to mpd, as a fallback if no replaygain tags are
found. The code is almost directly from madplay (GPL).

RVA2 tags are generated for example by the "normalize" utility.

Originally by: Pauli Virtanen <[EMAIL PROTECTED]>  Wed, 22 Feb 2006 23:13:25 
+0200
Updated by: Avuton Olrich <[EMAIL PROTECTED]>
---

diff --git a/src/decoder/mp3_plugin.c b/src/decoder/mp3_plugin.c
index 69cc7d0..ebf1669 100644
--- a/src/decoder/mp3_plugin.c
+++ b/src/decoder/mp3_plugin.c
@@ -204,6 +204,95 @@ mp3_fill_buffer(struct mp3_data *data)
 }

 #ifdef HAVE_ID3TAG
+/* Parse mp3 RVA2 frame. Shamelessly stolen from madplay. */
+static int parse_rva2(struct id3_tag * tag, struct replay_gain_info *
replay_gain_info)
+{
+       struct id3_frame const * frame;
+
+       id3_latin1_t const *id;
+       id3_byte_t const *data;
+       id3_length_t length;
+       int found;
+
+       enum {
+               CHANNEL_OTHER         = 0x00,
+               CHANNEL_MASTER_VOLUME = 0x01,
+               CHANNEL_FRONT_RIGHT   = 0x02,
+               CHANNEL_FRONT_LEFT    = 0x03,
+               CHANNEL_BACK_RIGHT    = 0x04,
+               CHANNEL_BACK_LEFT     = 0x05,
+               CHANNEL_FRONT_CENTRE  = 0x06,
+               CHANNEL_BACK_CENTRE   = 0x07,
+               CHANNEL_SUBWOOFER     = 0x08
+       };
+
+       found = 0;
+
+       /* relative volume adjustment information */
+
+       frame = id3_tag_findframe(tag, "RVA2", 0);
+       if (!frame) return 0;
+
+       id   = id3_field_getlatin1(id3_frame_field(frame, 0));
+       data = id3_field_getbinarydata(id3_frame_field(frame, 1),
+                                       &length);
+
+       if (!id || !data) return 0;
+
+       /*
+        * "The 'identification' string is used to identify the
+        * situation and/or device where this adjustment should apply.
+        * The following is then repeated for every channel
+        *
+        *   Type of channel         $xx
+        *   Volume adjustment       $xx xx
+        *   Bits representing peak  $xx
+        *   Peak volume             $xx (xx ...)"
+        */
+
+       while (length >= 4) {
+               unsigned int peak_bytes;
+
+               peak_bytes = (data[3] + 7) / 8;
+               if (4 + peak_bytes > length)
+                       break;
+
+               if (data[0] == CHANNEL_MASTER_VOLUME) {
+                       signed int voladj_fixed;
+                       double voladj_float;
+
+                       /*
+                        * "The volume adjustment is encoded as a fixed
+                        * point decibel value, 16 bit signed integer
+                        * representing (adjustment*512), giving +/- 64
+                        * dB with a precision of 0.001953125 dB."
+                        */
+
+                       voladj_fixed  = (data[1] << 8) | (data[2] << 0);
+                       voladj_fixed |= -(voladj_fixed & 0x8000);
+
+                       voladj_float  = (double) voladj_fixed / 512;
+
+                       replay_gain_info->tuples[REPLAY_GAIN_TRACK].peak = 
voladj_float;
+                       replay_gain_info->tuples[REPLAY_GAIN_ALBUM].peak = 
voladj_float;
+
+                       DEBUG("parseRVA2: Relative Volume "
+                               "%+.1f dB adjustment (%s)\n",
+                               voladj_float, id);
+
+                       found = 1;
+                       break;
+               }
+
+               data   += 4 + peak_bytes;
+               length -= 4 + peak_bytes;
+       }
+
+       return found;
+}
+#endif
+
+#ifdef HAVE_ID3TAG
 static struct replay_gain_info *
 parse_id3_replay_gain_info(struct id3_tag *tag)
 {
@@ -245,6 +334,11 @@ parse_id3_replay_gain_info(struct id3_tag *tag)
                free(value);
        }

+       if (!found) {
+               /* fall back on RVA2 if no replaygain tags found */
+               found = parse_rva2(tag, replay_gain_info);
+       }
+       
        if (found)
                return replay_gain_info;
        replay_gain_info_free(replay_gain_info);
-- 
avuton
--
 "I've got a fever. And the only prescription is more cowbell." --
Christopher Walken

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team

Reply via email to