[MPlayer-dev-eng] [PATCH] Automatic downmix

Clément Bœsch ubitux at gmail.com
Sun Sep 26 10:42:33 CEST 2010


On Sun, Sep 26, 2010 at 10:37:12AM +0200, Nicolas George wrote:
> Le quintidi 5 vendémiaire, an CCXIX, Clément Bœsch a écrit :
> > Ok I think I get it. So do those values seem fine to you? :
> 
> I don't think we need "magical" coefficient that no one knows where exactly
> they come from. There may be very elegant and attractive acoustical theory
> behind those coefficient, but this theory stops at two practical objections:
> 
> - Not all surround files were mastered the same way. There are standards for
>   AC3 and a few other formats (and actually, the standard for AC3 defines
>   several sets of downmixing coefficients), but if you get a 6-channels
>   Vorbis file, you do not which standard it follows.
> 
> - MPlayer is a domestic tool, where speakers are placed near the screen
>   where there is place and sound reverberates on the furniture in a
>   completely uncontrolled way.
> 
> Therefore, I do not think more than one significant digit would be relevant
> for these coefficients.
> 
> If someone calibrated the position of his sofa with regard to his speakers,
> he is always free to add the relevant pan filter himself.
> 
> Regards,


Well, they don't seem that stupid in fact (at least for the non-dolby
ones). You can test it yourself, I attached an updated patch.

Regards,

-- 
Clément B.
-------------- next part --------------
Index: libaf/af.c
===================================================================
--- libaf/af.c	(revision 32355)
+++ libaf/af.c	(working copy)
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "osdep/strsep.h"
+#include "libmpcodecs/dec_audio.h"
 
 #include "af.h"
 
@@ -412,6 +413,27 @@
     return AF_OK;
 }
 
+/**
+ * Automatic downmix to stereo in case the codec does not implement it.
+ */
+static af_instance_t *af_downmix(af_stream_t* s)
+{
+    static const char * const downmix_strs[AF_NCH + 1] = {
+        /*                 FL       FR        RL        RR          FC          LFE         AL        AR */
+        [3] = "pan=2:" ".586:0:" "0:.586:"                     ".414:.414",
+        [4] = "pan=2:" ".500:0:" "0:.500:" ".500:0:" "0:.500",
+        [5] = "pan=2:" ".369:0:" "0:.369:" ".369:0:" "0:.369:" ".261:.261",
+        [6] = "pan=2:" ".293:0:" "0:.293:" ".293:0:" "0:.293:" ".207:.207:" ".207:.207",
+        [7] = "pan=2:" ".270:0:" "0:.270:" ".270:0:" "0:.270:" ".191:.191:"              ".270:0:" "0:.270",
+        [8] = "pan=2:" ".227:0:" "0:.227:" ".227:0:" "0:.227:" ".160:.160:" ".160:.160:" ".227:0:" "0:.227",
+    };
+    const char *af_pan_str = downmix_strs[s->input.nch];
+
+    if (af_pan_str)
+        return af_append(s, s->first, af_pan_str);
+    return NULL;
+}
+
 /* Initialize the stream "s". This function creates a new filter list
    if necessary according to the values set in input and output. Input
    and output should contain the format of the current movie and the
@@ -438,6 +460,9 @@
 
   // Check if this is the first call
   if(!s->first){
+    // Append a downmix pan filter at the beginning of the chain if needed
+    if (s->input.nch != audio_output_channels && audio_output_channels == 2)
+      af_downmix(s);
     // Add all filters in the list (if there are any)
     if (s->cfg.list) {
       while(s->cfg.list[i]){


More information about the MPlayer-dev-eng mailing list