[MPlayer-dev-eng] [PATCH] a52 dynamic range compression option

Peter Gansterer e9425333 at stud4.tuwien.ac.at
Mon Apr 12 20:13:33 CEST 2004



On Fri, 9 Apr 2004, Diego Biurrun wrote:
>
> Thanks.  One small thing, though: You should start new sentences on a new
> line in the man page.
>

Finally back at the computer. Here comes the 3rd try: Full patch,
sentences start on a new line (german and english manpage). From the
existing parts of the manpage I judge you didn't mean a real break (.br)
in the text but just a new line in the source code.

I hope I finally got it right :)

- peda
-------------- next part --------------
diff -Naur main/DOCS/man/de/mplayer.1 main.new/DOCS/man/de/mplayer.1
--- main/DOCS/man/de/mplayer.1	2003-12-08 13:11:52.000000000 +0100
+++ main.new/DOCS/man/de/mplayer.1	2004-04-12 20:04:44.867736016 +0200
@@ -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]
diff -Naur main/DOCS/man/en/mplayer.1 main.new/DOCS/man/en/mplayer.1
--- main/DOCS/man/en/mplayer.1	2004-03-29 06:39:04.000000000 +0200
+++ main.new/DOCS/man/en/mplayer.1	2004-04-12 20:07:17.093594168 +0200
@@ -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].
diff -Naur main/cfg-common.h main.new/cfg-common.h
--- main/cfg-common.h	2004-04-12 19:59:34.351941592 +0200
+++ main.new/cfg-common.h	2004-04-12 20:02:33.345730400 +0200
@@ -134,6 +134,10 @@
 	{"channels", &audio_output_channels, CONF_TYPE_INT, CONF_RANGE, 1, 6, NULL},
 	{"format", &audio_output_format, CONF_TYPE_INT, CONF_RANGE, 0, 0x00002000, NULL},
 
+// ------------------------- a52 options ------------------------------
+        {"a52drc", &a52_drc_level, CONF_TYPE_FLOAT, CONF_RANGE, 0, 1, NULL},
+
+
 // ------------------------- codec/vfilter options --------------------
 
 	// MP3-only: select stereo/left/right
diff -Naur main/libmpcodecs/ad_liba52.c main.new/libmpcodecs/ad_liba52.c
--- main/libmpcodecs/ad_liba52.c	2004-04-12 19:59:37.178511888 +0200
+++ main.new/libmpcodecs/ad_liba52.c	2004-04-12 20:02:33.345730400 +0200
@@ -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)){
diff -Naur main/mencoder.c main.new/mencoder.c
--- main/mencoder.c	2004-04-12 19:59:35.167817560 +0200
+++ main.new/mencoder.c	2004-04-12 20:02:33.346730248 +0200
@@ -154,6 +154,10 @@
 static int force_srate=0;
 static int audio_output_format=0;
 
+// a52
+
+extern float a52_drc_level;
+
 char *vobsub_out=NULL;
 unsigned int vobsub_out_index=0;
 char *vobsub_out_id=NULL;
diff -Naur main/mplayer.h main.new/mplayer.h
--- main/mplayer.h	2004-04-12 20:02:25.987848968 +0200
+++ main.new/mplayer.h	2004-04-12 20:02:33.346730248 +0200
@@ -61,4 +61,6 @@
 extern void exit_player(char* how);
 extern void update_set_of_subtitles();
 
+extern float a52_drc_level;
+
 #endif


More information about the MPlayer-dev-eng mailing list