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

Peter Gansterer e9425333 at stud4.tuwien.ac.at
Thu Apr 8 20:43:31 CEST 2004



On Thu, 8 Apr 2004, D Richard Felker III wrote:

> > Option names should use "-" instead of "_".  Also please add the option to
> > the man page.
> > Thanks
> >
> > Diego
>
> IMO it doesn't even need any separator. -a52drc would be fine...

OK, I chose the "-a52drc" option and added it to the english and german
manpagese (my french and italian are a little rusty and I dont speak the
remaining languages :-)
I hope the placement in the manpage is ok. It seemed to be in alphabetic
order, so it landed just before "-aid".

Full patch included.

- 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-08 20:39:21.352084104 +0200
@@ -388,6 +388,13 @@
 
 .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 Range
+Compression 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-08 20:39:16.357843344 +0200
@@ -596,6 +596,13 @@
 .
 .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-03-24 16:16:36.000000000 +0100
+++ main.new/cfg-common.h	2004-04-08 20:38:19.396502784 +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	2003-10-02 16:13:52.000000000 +0200
+++ main.new/libmpcodecs/ad_liba52.c	2004-04-08 20:37:57.877774128 +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-07 14:46:14.000000000 +0200
+++ main.new/mencoder.c	2004-04-08 20:37:57.882773368 +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	2003-04-07 18:03:37.000000000 +0200
+++ main.new/mplayer.h	2004-04-08 20:37:57.884773064 +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