diff options
author | cigaes <cigaes@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2010-09-26 08:45:40 +0000 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-11-02 04:18:07 +0200 |
commit | 579d743159c665b643e5c53d7e0cf27e89043ac4 (patch) | |
tree | 67ba422418e978102941d9bc6d8531bb9a5ad3ee /libaf | |
parent | 6335de8621aa511cc85a60a97ffb3eddf0e35d8d (diff) | |
download | mpv-579d743159c665b643e5c53d7e0cf27e89043ac4.tar.bz2 mpv-579d743159c665b643e5c53d7e0cf27e89043ac4.tar.xz |
audio: auto-add downmix filter when stereo output is requested
When -channels 2 [default] is specified and the audio decoder used
does not support internal downmixing, automatically add a pan filter
after the decoder to downmix to stereo.
Patch by Clément Bœsch, ubitux gmail com
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32356 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libaf')
-rw-r--r-- | libaf/af.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libaf/af.c b/libaf/af.c index 5238e6bc85..0190a75f5e 100644 --- a/libaf/af.c +++ b/libaf/af.c @@ -410,6 +410,26 @@ static int fixup_output_format(af_stream_t* s) return AF_OK; } +/** + * Automatic downmix to stereo in case the codec does not implement it. + */ +static void af_downmix(af_stream_t* s) +{ + static const char * const downmix_strs[AF_NCH + 1] = { + /* FL FR RL RR FC LF AL AR */ + [3] = "pan=2:" "0.6:0:" "0:0.6:" "0.4:0.4", + [4] = "pan=2:" "0.6:0:" "0:0.6:" "0.4:0:" "0:0.4", + [5] = "pan=2:" "0.5:0:" "0:0.5:" "0.2:0:" "0:0.2:" "0.3:0.3", + [6] = "pan=2:" "0.4:0:" "0:0.4:" "0.2:0:" "0:0.2:" "0.3:0.3:" "0.1:0.1", + [7] = "pan=2:" "0.4:0:" "0:0.4:" "0.2:0:" "0:0.2:" "0.3:0.3:" "0.1:0:" "0:0.1", + [8] = "pan=2:" "0.4:0:" "0:0.4:" "0.15:0:" "0:0.15:" "0.25:0.25:" "0.1:0.1:" "0.1:0:" "0:0.1", + }; + const char *af_pan_str = downmix_strs[s->input.nch]; + + if (af_pan_str) + af_append(s, s->first, af_pan_str); +} + /* Initialize the stream "s". This function creates a new filter list if necessary according to the values set in input and output. Input and output should contain the format of the current movie and the @@ -421,6 +441,7 @@ static int fixup_output_format(af_stream_t* s) The return value is 0 if success and -1 if failure */ int af_init(af_stream_t* s) { + struct MPOpts *opts = s->opts; int i=0; // Sanity check @@ -436,6 +457,10 @@ int af_init(af_stream_t* s) // Check if this is the first call if(!s->first){ + // Append a downmix pan filter at the beginning of the chain if needed + if (s->input.nch != opts->audio_output_channels + && opts->audio_output_channels == 2) + af_downmix(s); // Add all filters in the list (if there are any) if (s->cfg.list) { while(s->cfg.list[i]){ |