changeset 12285:67b8d64af8c7

a52 dynamic range compression support by Peter Gansterer
author alex
date Mon, 26 Apr 2004 08:53:41 +0000
parents 309b42443b65
children b52e831261b1
files DOCS/man/de/mplayer.1 DOCS/man/en/mplayer.1 cfg-common.h libmpcodecs/ad_liba52.c
diffstat 4 files changed, 57 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/man/de/mplayer.1	Mon Apr 26 07:43:14 2004 +0000
+++ b/DOCS/man/de/mplayer.1	Mon Apr 26 08:53:41 2004 +0000
@@ -388,6 +388,14 @@
 
 .SH "DEMUXER/STREAM-OPTIONEN"
 .TP
+.B \-a52drc <level>
+Gibt die Höhe der Dynamic Range Compression für den AC3 Audio Stream an.
+<level> ist ein Fließkommawert im Bereich von 0 bis 1, wobei 0 keine Kompression
+und 1 (der Standardwert) volle Kompression bedeutet (laute Passagen werden leiser
+und umgekehrt).
+Diese Option zeigt nur Wirkung, wenn im AC3 Stream die Rangei Compression i
+Information vorhanden ist.
+.TP
 .B \-aid <id> (siehe auch \-alang)
 Gibt die zu verwendende Audiospur an [MPEG: 0\-31 AVI/\:OGM: 1\-99
 ASF/\:RM: 0\-127 VOB(AC3): 128\-159 VOB(LPCM): 160\-191]
--- a/DOCS/man/en/mplayer.1	Mon Apr 26 07:43:14 2004 +0000
+++ b/DOCS/man/en/mplayer.1	Mon Apr 26 08:53:41 2004 +0000
@@ -596,6 +596,14 @@
 .
 .SH "DEMUXER/STREAM OPTIONS"
 .TP
+.B \-a52drc <level>
+Select the Dynamic Range Compression level for AC3 audio streams.
+<level> is a float value ranging from 0 to 1, where 0 means no compression 
+and 1 (which is the default) means full compression (make loud passages more 
+silent and vice versa).
+This option only shows an effect if the AC3 stream contains the required range 
+compression information.
+.TP
 .B \-aid <id> (also see \-alang option)
 Select audio channel [MPEG: 0\-31 AVI/\:OGM: 1\-99 ASF/\:RM: 0\-127
 VOB(AC3): 128\-159 VOB(LPCM): 160\-191 MPEG-TS 17\-8190].
--- a/cfg-common.h	Mon Apr 26 07:43:14 2004 +0000
+++ b/cfg-common.h	Mon Apr 26 08:53:41 2004 +0000
@@ -134,6 +134,8 @@
 	{"channels", &audio_output_channels, CONF_TYPE_INT, CONF_RANGE, 1, 6, NULL},
 	{"format", &audio_output_format, CONF_TYPE_INT, CONF_RANGE, 0, 0x00002000, NULL},
 
+        {"a52drc", &a52_drc_level, CONF_TYPE_FLOAT, CONF_RANGE, 0, 1, NULL},
+
 // ------------------------- codec/vfilter options --------------------
 
 	// MP3-only: select stereo/left/right
@@ -303,6 +305,8 @@
 
 #endif
 
+extern float a52_drc_level;
+
 /* defined in libmpdemux: */
 extern int hr_mp3_seek;
 extern m_option_t demux_rawaudio_opts[];
--- a/libmpcodecs/ad_liba52.c	Mon Apr 26 07:43:14 2004 +0000
+++ b/libmpcodecs/ad_liba52.c	Mon Apr 26 08:53:41 2004 +0000
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <math.h>
 
 #include "config.h"
 #ifdef USE_LIBA52
@@ -19,6 +20,13 @@
 static a52_state_t a52_state;
 static uint32_t a52_flags=0;
 
+#define DRC_NO_ACTION      0
+#define DRC_NO_COMPRESSION 1
+#define DRC_CALLBACK       2
+
+float a52_drc_level = 1.0;
+static int a52_drc_action = DRC_NO_ACTION;
+
 #include "bswap.h"
 
 static ad_info_t info = 
@@ -95,6 +103,11 @@
   return (flags&A52_LFE) ? (channels+1) : channels;
 }
 
+sample_t dynrng_call (sample_t c, void *data) {
+//	fprintf(stderr, "(%lf, %lf): %lf\n", (double)c, (double)a52_drc_level, (double)pow((double)c, a52_drc_level));
+	return pow((double)c, a52_drc_level);
+}
+
 
 static int preinit(sh_audio_t *sh)
 {
@@ -126,6 +139,21 @@
 	mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n");
 	return 0;
   }
+
+
+  /* Init a52 dynrng */
+  if (a52_drc_level < 0.001) {
+	  /* level == 0 --> no compression, init library without callback */
+	  a52_drc_action = DRC_NO_COMPRESSION;
+  } else if (a52_drc_level > 0.999) {
+	  /* level == 1 --> full compression, do nothing at all (library default = full compression) */
+	  a52_drc_action = DRC_NO_ACTION;
+  } else {
+	  a52_drc_action = DRC_CALLBACK;
+  }
+  /* Library init for dynrng has to be done for each frame, see decode_audio() */
+
+
   /* 'a52 cannot upmix' hotfix:*/
   a52_printinfo(sh_audio);
   sh_audio->channels=audio_output_channels;
@@ -186,6 +214,15 @@
 	    mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error decoding frame\n");
 	    return len;
 	}
+
+	/* handle dynrng */
+	if (a52_drc_action != DRC_NO_ACTION) {
+	    if (a52_drc_action == DRC_NO_COMPRESSION)
+		a52_dynrng(&a52_state, NULL, NULL);
+	    else
+		a52_dynrng(&a52_state, dynrng_call, NULL);
+	}
+
 	len=0;
 	for (i = 0; i < 6; i++) {
 	    if (a52_block (&a52_state, a52_samples)){