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

Reimar Döffinger Reimar.Doeffinger at gmx.de
Mon Sep 13 07:20:09 CEST 2010


On Mon, Sep 13, 2010 at 12:46:28AM +0200, Clément Bœsch wrote:
> 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.

af_pan can only handle float. You should check it still works with an ao
that can only handle int.
Also the behaviour might be less surprising if you'd try to prepend
af_pan first, but I admit that's likely to be quite messy...
Anyway, printing a warning if audio_output_channels < s->last->data->nch
might make sense, the behaviour of -channels 1 compared to -channels 2
is not exactly consistent like this.

> +    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;
> +    }

Much smaller/simpler as:
static const char * const downmix_strs[AF_NCH] = {
NULL, NULL, NULL,
"pan=2:"/*Left:*/"0.6:0:"/*Right:*/"0:0.6:":0.4:0.4".
....
};
const char *str = downmix_strs[s->last->data->nch];
if (str)
    af_append(s, s->last, str);


More information about the MPlayer-dev-eng mailing list