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

ubitux ubitux at gmail.com
Tue Aug 10 20:56:38 CEST 2010


Hello again,

Here is a new version of the patch, calling pan audio filter instead of
hrtf (I still note saturations with pan, but less). I tried to get this
working up to 6 channels. But those settings may be specific to the FLAC
format only, so should this code be called only in that case? Is there any
better place?

The settings are based on this page:
http://flac.sourceforge.net/format.html#frame_header (see <4>).

I know this code is a (bad) hack, even if it allows MPlayer to play much
more videos without trouble…

So the question is: should I make a proper patch (without depending on a
filter) to the flac decoder in {libavcodec,libavformat}/flacdec.c?

Regards,

-- 
ubitux
-------------- next part --------------
Index: mplayer.c
===================================================================
--- mplayer.c	(revision 31950)
+++ mplayer.c	(working copy)
@@ -1647,6 +1647,48 @@
 ///@}
 // OSDMsgStack
 
+/**
+ * \brief Automatic downmix to stereo in case the codec does not implement it
+ */
+static void downmix_if_needed()
+{
+    if (audio_output_channels != 2)
+        return;
+    switch (mpctx->sh_audio->channels) {
+    case 6:
+        af_add(mpctx->mixer.afilter, "pan=2:"
+                                     "1:0:"      // Left
+                                     "0:1:"      // Right
+                                     "0.7:0.7:"  // Center
+                                     "0.3:0.3:"  // LFE
+                                     "0.5:0:"    // Back left
+                                     "0:0.5"     // Back right
+        );
+        break;
+    case 5:
+        af_add(mpctx->mixer.afilter, "pan=2:"
+                                     "1:0:"      // Left
+                                     "0:1:"      // Right
+                                     "0.7:0.7:"  // Center
+                                     "0.5:0:"    // Back left
+                                     "0:0.5"     // Back right
+        );
+    case 4:
+        af_add(mpctx->mixer.afilter, "pan=2:"
+                                     "1:0:"      // Left
+                                     "0:1:"      // Right
+                                     "0.5:0:"    // Back left
+                                     "0:0.5"     // Back right
+        );
+    case 3:
+        af_add(mpctx->mixer.afilter, "pan=2:"
+                                     "1:0:"      // Left
+                                     "0:1:"      // Right
+                                     "0.7:0.7"   // Center
+        );
+        break;
+    }
+}
 
 void reinit_audio_chain(void) {
     if (!mpctx->sh_audio)
@@ -1706,6 +1748,8 @@
     }
     mpctx->mixer.audio_out = mpctx->audio_out;
     mpctx->mixer.volstep = volstep;
+
+    downmix_if_needed();
     return;
 
 init_error:


More information about the MPlayer-dev-eng mailing list