[pulseaudio-discuss] [PATCH] resampler: Fix volume on downmix to mono

David Henningsson david.henningsson at canonical.com
Thu Aug 9 04:58:02 PDT 2012


Patch credit: kwanghui

When downmixing to mono, we should average the signal instead of
summing it to avoid clipping.

BugLink: http://pulseaudio.org/ticket/934
BugLink: https://bugs.launchpad.net/bugs/416190

Signed-off-by: David Henningsson <david.henningsson at canonical.com>
---
 src/Makefile.am           |    1 -
 src/pulsecore/resampler.c |   11 +++++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

I first checked Arun's suggested patch, which does not work (output is zero,
because mono is not handled in the other cases). The original patch by kwanghui
seems to work.

Anyone against me committing this one?

diff --git a/src/Makefile.am b/src/Makefile.am
index 7f947bd..2913319 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -228,7 +228,6 @@ TESTS_default = \
 		memblockq-test \
 		channelmap-test \
 		thread-mainloop-test \
-		utf8-test \
 		format-test \
 		get-binary-name-test \
 		ipacl-test \
diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 9f19559..af749ae 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -716,7 +716,7 @@ static void calc_map_table(pa_resampler *r) {
              *
              * 2) Mono Handling:
              *    S:Mono: Copy into all D:channels
-             *    D:Mono: Copy in all S:channels
+             *    D:Mono: Avg all S:channels
              *
              * 3) Mix D:Left, D:Right:
              *    D:Left: If not connected, avg all S:Left
@@ -759,12 +759,19 @@ static void calc_map_table(pa_resampler *r) {
              * best to pass it to L+R.
              */
 
-            if (a == b || a == PA_CHANNEL_POSITION_MONO || b == PA_CHANNEL_POSITION_MONO) {
+            if (a == b || a == PA_CHANNEL_POSITION_MONO) {
                 m->map_table_f[oc][ic] = 1.0;
 
                 oc_connected = TRUE;
                 ic_connected[ic] = TRUE;
             }
+            else if (b == PA_CHANNEL_POSITION_MONO) {
+                if(n_ic)
+                    m->map_table_f[oc][ic] = 1.0f / (float) n_ic;
+
+                oc_connected = TRUE;
+                ic_connected[ic] = TRUE;
+            }
         }
 
         if (!oc_connected && remix) {
-- 
1.7.9.5



More information about the pulseaudio-discuss mailing list