Web lists-archives.com

[MPlayer-dev-eng] [PATCH] Determine replay gain




I'm going to utilize this in the GUI.

Ingo
Index: libmpdemux/demuxer.h
===================================================================
--- libmpdemux/demuxer.h	(revision 37927)
+++ libmpdemux/demuxer.h	(working copy)
@@ -110,6 +110,7 @@
 #define DEMUXER_CTRL_SWITCH_VIDEO 14
 #define DEMUXER_CTRL_IDENTIFY_PROGRAM 15
 #define DEMUXER_CTRL_CORRECT_PTS 16
+#define DEMUXER_CTRL_GET_REPLAY_GAIN 17
 
 #define SEEK_ABSOLUTE (1 << 0)
 #define SEEK_FACTOR   (1 << 1)
Index: libmpdemux/demux_audio.c
===================================================================
--- libmpdemux/demux_audio.c	(revision 37927)
+++ libmpdemux/demux_audio.c	(working copy)
@@ -42,6 +42,9 @@
 
 #define HDR_SIZE 4
 
+#define LAST_BITS(k, n) ((k) & ((1 << (n)) - 1))
+#define MIDDLE_BITS(k, m, n) LAST_BITS((k) >> (m), ((n) - (m)))
+
 typedef struct da_priv {
   int frmt;
   double next_pts;
@@ -66,6 +69,8 @@
   struct mp3_hdr *next;
 } mp3_hdr_t;
 
+static int r_gain;
+
 int hr_mp3_seek = 0;
 
 /**
@@ -317,7 +322,29 @@
       data = stream_read_dword(s);
 
       if (data & 0x1)                   // frames field is present
-        return stream_read_dword(s);    // frames
+        data = stream_read_dword(s);    // frames
+
+      if (stream_skip(s, 108)) {
+        unsigned int dword;
+
+        dword = stream_read_dword(s);
+
+        if (dword == MKBETAG('L','A','M','E') && stream_skip(s, 11)) {
+          uint32_t word;
+
+          word = stream_read_word(s);
+
+          /* Radio ReplayGain */
+          if (MIDDLE_BITS(word, 13, 15) == 1) {
+            r_gain = MIDDLE_BITS(word, 0, 8);
+
+            if (word & (1 << 9))
+              r_gain *= -1;
+          }
+        }
+      }
+
+      return data;
     }
 
     /* VBRI (at fixed position: 32 bytes after header) */
@@ -435,6 +462,7 @@
     return 0;
 
   sh_audio = new_sh_audio(demuxer,0, NULL);
+  r_gain = INT32_MIN;
 
   switch(frmt) {
   case MP3:
@@ -836,6 +864,11 @@
     	    *((int *)arg)=(int)( (priv->next_pts*100)  / audio_length);
 	    return DEMUXER_CTRL_OK;
 
+	case DEMUXER_CTRL_GET_REPLAY_GAIN:
+	    if (r_gain == INT32_MIN) return DEMUXER_CTRL_DONTKNOW;
+	    *((int *)arg) = r_gain;
+	    return DEMUXER_CTRL_OK;
+
 	default:
 	    return DEMUXER_CTRL_NOTIMPL;
     }
_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng