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

Clément Bœsch ubitux at gmail.com
Sat Sep 11 16:18:15 CEST 2010


On Wed, Sep 08, 2010 at 03:23:25PM +0200, Nicolas George wrote:
> 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.)
> 

Can you try with this updated patch?

Regards,

-- 
Clément B.
-------------- next part --------------
Index: mplayer.c
===================================================================
--- mplayer.c	(revision 32153)
+++ mplayer.c	(working copy)
@@ -1647,6 +1647,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)
@@ -1665,7 +1732,7 @@
     if (!(initialized_flags & INITIALIZED_AO)) {
         current_module="af_preinit";
         ao_data.samplerate=force_srate;
-        ao_data.channels=0;
+        ao_data.channels=audio_output_channels;
         ao_data.format=audio_output_format;
         // first init to detect best values
         if(!init_audio_filters(mpctx->sh_audio,   // preliminary init
@@ -1706,6 +1773,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