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

ubitux ubitux at gmail.com
Wed Sep 8 22:06:56 CEST 2010


On Wed, Sep 08, 2010 at 03:23:25PM +0200, Nicolas George wrote:
> Le septidi 27 thermidor, an CCXVIII, ubitux a écrit :
> > +static void downmix_if_needed()
> 
> I think MPlayer coding style requires "(void)".
> 

Done.

> >      mpctx->mixer.volstep = volstep;
> > +
> > +    downmix_if_needed();
> 
> Is the extra empty line really necessary?
> 

I don't think it is related to the "init audio filters" stuff (even if
it adds one), but I don't mind removing it.

> There is still a problem with this patch: the audio output gets initialized
> for the original number of channels, not the reduced stereo. Example:
> 
> $ ./mplayer -channels 2 -v /tmp/6_Channel_ID.ac3 |& grep 'alsa.*device'
> alsa-init: using device default
> $ ./mplayer -channels 2 -v /tmp/6_Channel_ID.wav |& grep 'alsa.*device'
> alsa-init: device set to surround51
> alsa-init: using device surround51
> 
> (First call: AC3, built-in downmix, second call: WAVE, new generic downmix.)
> 

It is initialized before adding the filter; what problems does this
induce? Just a printing issue?

> Regards,
> 
> -- 
>   Nicolas George

-- 
ubitux
-------------- next part --------------
Index: mplayer.c
===================================================================
--- mplayer.c	(revision 32099)
+++ mplayer.c	(working copy)
@@ -1651,6 +1651,73 @@
 ///@}
 // OSDMsgStack
 
+/**
+ * \brief Automatic downmix to stereo in case the codec does not implement it
+ */
+static void downmix_if_needed(void)
+{
+    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)
@@ -1710,6 +1777,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