[MPlayer-dev-eng] [PATCH] Automatic downmix
Clément Bœsch
ubitux at gmail.com
Mon Sep 13 00:46:28 CEST 2010
On Sat, Sep 11, 2010 at 07:44:18PM +0200, Reimar Döffinger wrote:
> On Sat, Sep 11, 2010 at 07:26:30PM +0200, Clément Bœsch wrote:
> > On Sat, Sep 11, 2010 at 06:44:58PM +0200, Reimar Döffinger wrote:
> > > On Sat, Sep 11, 2010 at 04:18:15PM +0200, Clément Bœsch wrote:
> > > > @@ -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;
> > >
> > > Please test this very carefully, especially make sure that
> > > all kinds of mono/stereo files still work with -channels 6.
> > > I am for some reason quite convinced this was 0 for a good reason.
> >
> > Oh you've right, sorry: If I play a stereo file, I get the sound in only
> > right and left while the current behaviour gives output to the 6 physical
> > channels with a stereo audio.
> >
> > Well then I'm going to try something else, but if anyone has an idea how
> > it could be fixed please share…
>
> Use
> ao_data.channels=-audio_output_channels;
> as initial value.
> The extend init_audio_filters to handle a negative channels values
> as "at most this many channels".
> For this, place your af_add code there.
> No promise it will work, but I expect in init_audio_filters you
> are most likely to have all the flexibility you need.
Thanks a lot for those information!
Instead of hacking the channels field, I just got it directly globally in
libaf/af.c
Maybe it's still not the right place but it seems to work:
- Basic stereo files use all my 6 physical channels
- 6_channel_ID.flac is downmixed to two channels by default and init is
done like this: 48000Hz 2ch floatle
- 6_channel_ID.flac is not downmixed if -channels 6 is specified and init
is done like this: 44100Hz 6ch s16le
It works for my case but I'm wondering about the format changement… maybe
you can enlight me about it.
Regards,
--
Clément B.
-------------- next part --------------
Index: libaf/af.c
===================================================================
--- libaf/af.c (revision 32210)
+++ 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"
@@ -361,6 +362,74 @@
}
/**
+ * Automatic downmix to stereo in case the codec does not implement it.
+ */
+static void downmix_if_needed(af_stream_t* s)
+{
+ if (audio_output_channels != 2)
+ return;
+ switch (s->last->data->nch) {
+ case 8:
+ af_append(s, s->last, "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_append(s, s->last, "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_append(s, s->last, "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_append(s, s->last, "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_append(s, s->last, "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_append(s, s->last, "pan=2:"
+ "0.6:0:" // Left
+ "0:0.6:" // Right
+ "0.4:0.4" // Center
+ );
+ break;
+ }
+}
+
+/**
* Extend the filter chain so we get the required output format at the end.
* \return AF_ERROR on error, AF_OK if successful.
*/
@@ -396,6 +465,8 @@
return AF_ERROR;
}
+ downmix_if_needed(s);
+
// Re init again just in case
if(AF_OK != af_reinit(s,s->first))
return AF_ERROR;
More information about the MPlayer-dev-eng
mailing list