From 73156649e76ac4000931990edcdcb3be31aade7b Mon Sep 17 00:00:00 2001 From: "Alexander E. Patrakov" Date: Sat, 13 Oct 2018 22:11:20 +0500 Subject: [PATCH] resampler: Fix confusion between rear and side channels for 5.1 layouts mpv and vlc play "normal" 5.1 AC3 and DTS files as if they had a "5.1 (Side)" layout. Which is fine and consistent with ITU recommendations if the user has a proper 7.1 system. But if the user actually has a 5.1 system, PulseAudio will try to remap, poorly, between the "5.1 (Side)" and "5.1" layouts, sending either an average between front and rear channels, or an attenuated version of that average, depending on the remixing-use-all-sink-channels setting. This is not desired, the "Side" channels should be sent to "Rear", it is only an unfortunate nomenclature confusion. This patch does not fix 5.1 <-> 7.1 remixing. Signed-off-by: Alexander E. Patrakov --- src/pulsecore/resampler.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c index d42cbc2..6a4ded6 100644 --- a/src/pulsecore/resampler.c +++ b/src/pulsecore/resampler.c @@ -914,6 +914,8 @@ static void setup_remap(const pa_resampler *r, pa_remap_t *m, bool *lfe_remixed) * The algorithm works basically like this: * * 1) Connect all channels with matching names. + * This also includes fixing confusion between "5.1" and + * "5.1 (Side)" layouts, done by mpv. * * 2) Mono Handling: * S:Mono: See setup_oc_mono_map(). @@ -1007,6 +1009,26 @@ static void setup_remap(const pa_resampler *r, pa_remap_t *m, bool *lfe_remixed) } if (!oc_connected) { + /* Maybe it is due to 5.1 rear/side confustion? */ + for (ic = 0; ic < n_ic; ic++) { + pa_channel_position_t a = r->i_cm.map[ic]; + if (ic_connected[ic]) + continue; + + if ((a == PA_CHANNEL_POSITION_REAR_LEFT && b == PA_CHANNEL_POSITION_SIDE_LEFT) || + (a == PA_CHANNEL_POSITION_SIDE_LEFT && b == PA_CHANNEL_POSITION_REAR_LEFT) || + (a == PA_CHANNEL_POSITION_REAR_RIGHT && b == PA_CHANNEL_POSITION_SIDE_RIGHT) || + (a == PA_CHANNEL_POSITION_SIDE_RIGHT && b == PA_CHANNEL_POSITION_REAR_RIGHT)) { + + m->map_table_f[oc][ic] = 1.0f; + + oc_connected = true; + ic_connected[ic] = true; + } + } + } + + if (!oc_connected) { /* Try to find matching input ports for this output port */ if (on_left(b) && !(r->flags & PA_RESAMPLER_NO_FILL_SINK)) { -- 2.7.4