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

ubitux ubitux at gmail.com
Sat Aug 14 21:55:48 CEST 2010


On Tue, Aug 10, 2010 at 10:20:24PM +0200, Grigori Goronzy wrote:
> Given the coefficients you pass to the pan filter, that's expected. :)
> They sum up to 2.5 for each channel, ideally they should sum up to 1.
> However I am not sure how volume will suffer if they're scaled down to
> achieve that.

Oh I see. Well then here is a new patch with coefficients that sum up to
1.0. The volume is indeed reduced, but no more saturation.

Also, I note that the channels assignements was wrong if I followed the
FLAC specs (are they wrong or is there a convertion somewhere?). So I used
those two samples in order to get the right assignement:

  http://www-mmsp.ece.mcgill.ca/documents/audioformats/wave/Samples/Microsoft/6_Channel_ID.wav
  http://www-mmsp.ece.mcgill.ca/documents/audioformats/wave/Samples/Microsoft/8_Channel_ID.wav

It also seems it's the right assignment for FLAC; I got the right sound
for all my videos with Flac 5.1.

I think the patch is good now, so could I have a review of it?

Regards,

-- 
ubitux
-------------- next part --------------
Index: mplayer.c
===================================================================
--- mplayer.c	(revision 31961)
+++ mplayer.c	(working copy)
@@ -1648,7 +1648,75 @@
 ///@}
 // 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 8:
+        af_add(mpctx->mixer.afilter, "pan=2:"
+                                     "0.4:0:"      // Front left
+                                     "0:0.4:"      // Front right
+                                     "0.15:0:"     // Back left
+                                     "0:0.15:"     // Back right
+                                     "0.25:0.25:"  // Center
+                                     "0.1:0.1:"    // LFE
+                                     "0.1:0:"      // Auxiliary left
+                                     "0:0.1"       // Auxiliary right
+        );
+        break;
+    case 7:
+        af_add(mpctx->mixer.afilter, "pan=2:"
+                                     "0.4:0:"      // Front left
+                                     "0:0.4:"      // Front right
+                                     "0.2:0:"      // Back left
+                                     "0:0.2:"      // Back right
+                                     "0.3:0.3:"    // Center
+                                     "0.1:0:"      // Auxiliary left
+                                     "0:0.1"       // Auxiliary right
+        );
+        break;
+    case 6:
+        af_add(mpctx->mixer.afilter, "pan=2:"
+                                     "0.4:0:"      // Front left
+                                     "0:0.4:"      // Front right
+                                     "0.2:0:"      // Back left
+                                     "0:0.2:"      // Back right
+                                     "0.3:0.3:"    // Center
+                                     "0.1:0.1"     // LFE
+        );
+        break;
+    case 5:
+        af_add(mpctx->mixer.afilter, "pan=2:"
+                                     "0.5:0:"      // Front left
+                                     "0:0.5:"      // Front right
+                                     "0.2:0:"      // Back left
+                                     "0:0.2:"      // Back right
+                                     "0.3:0.3"     // Center
+        );
+        break;
+    case 4:
+        af_add(mpctx->mixer.afilter, "pan=2:"
+                                     "0.6:0:"      // Front left
+                                     "0:0.6:"      // Front right
+                                     "0.4:0:"      // Back left
+                                     "0:0.4"       // Back right
+        );
+        break;
+    case 3:
+        af_add(mpctx->mixer.afilter, "pan=2:"
+                                     "0.6:0:"      // Left
+                                     "0:0.6:"      // Right
+                                     "0.4:0.4"     // Center
+        );
+        break;
+    }
 
+}
+
 void reinit_audio_chain(void) {
     if (!mpctx->sh_audio)
         return;
@@ -1707,6 +1775,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