[pulseaudio-discuss] [PATCH v3] resampler: Always remix between mono and non-mono

Tanu Kaskinen tanuk at iki.fi
Thu Mar 21 04:24:10 PDT 2013


---

v3 fixes the initialization of the input/output_is_mono_only variables
and uses i/o_cm.channels instead of i/o_ss.channels in the loop
condition. The cm/ss change doesn't have any functional change, it's
just more logical, because to loop code reads from the channel map,
not the sample spec.

Thanks to David for pointing these out.

 src/pulsecore/resampler.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 0a3a678..137feab 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -203,6 +203,9 @@ pa_resampler* pa_resampler_new(
         pa_resample_flags_t flags) {
 
     pa_resampler *r = NULL;
+    unsigned c;
+    bool input_is_mono_only = true;
+    bool output_is_mono_only = true;
 
     pa_assert(pool);
     pa_assert(a);
@@ -269,6 +272,28 @@ pa_resampler* pa_resampler_new(
     else if (!pa_channel_map_init_auto(&r->o_cm, r->o_ss.channels, PA_CHANNEL_MAP_DEFAULT))
         goto fail;
 
+    /* If the input or output is mono-only, we ignore the NO_REMIX flag,
+     * because even if remixing is otherwise disabled, it's probably still
+     * desirable to be able to play mono inputs to non-mono outputs and
+     * non-mono inputs to mono outputs. */
+
+    for (c = 0; c < r->i_cm.channels; c++) {
+        if (r->i_cm.map[c] != PA_CHANNEL_POSITION_MONO) {
+            input_is_mono_only = false;
+            break;
+        }
+    }
+
+    for (c = 0; c < r->o_cm.channels; c++) {
+        if (r->o_cm.map[c] != PA_CHANNEL_POSITION_MONO) {
+            output_is_mono_only = false;
+            break;
+        }
+    }
+
+    if (input_is_mono_only || output_is_mono_only)
+        r->flags &= ~PA_RESAMPLER_NO_REMIX;
+
     r->i_fz = pa_frame_size(a);
     r->o_fz = pa_frame_size(b);
 
-- 
1.7.10.4



More information about the pulseaudio-discuss mailing list