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

Peter Gansterer e9425333 at stud4.tuwien.ac.at
Thu Apr 8 00:50:21 CEST 2004


Hi folks,

I don't know policies of that list, so I just try and go ahead:

I would like to contribute a small patch which creates a new option to
control a52 dynamic range compression.

For those too lazy to look it up:
That's the AC3 feature responsible for making loud scenes more silent and
vice versa for listening at night near agressive neigbours.

With mplayer, compression is always set to "full compression". That is
a52_dynrng is never initialized and library default is full compression.
I cannot live with that default behaviour for viewing DVDs in our small
"office theatre", because in that environment loud scenes tend to be WAY
too silent.

So I compiled that small patch. It adds a new option "-a52_drc" which is
float [0..1], where
        0 is no compression (loud is loud) and
        1 is full compression (default, so without the option,
                behaviour doesn't change)

The patch applies to the latest CVS version of mplayer1. I would really
appreciate if it could be included in some coming release.

I am willing to document the option, I just didn't get into that before
knowing it would be accepted. I can also try to make the stuff OSD
controllable but I cannot guarantee anything here for I do not really know
the code.

thx,
- peda.
-------------- next part --------------
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 00:33:56.966053240 +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 ------------------------------
+        {"a52_drc", &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 00:33:19.293780296 +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 00:32:49.246348200 +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 00:32:43.331247432 +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