]> code.delx.au - pulseaudio/commitdiff
resampler: Fix volume on downmix to mono
authorDavid Henningsson <david.henningsson@canonical.com>
Wed, 8 Aug 2012 14:01:38 +0000 (16:01 +0200)
committerDavid Henningsson <david.henningsson@canonical.com>
Wed, 15 Aug 2012 07:27:48 +0000 (09:27 +0200)
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@canonical.com>
src/pulsecore/resampler.c

index 9f19559133922d7cfc6cfeac8befe9808108cd0d..7ac5f19cba7dd338ea20a8d2e0c32ca4f1bf599d 100644 (file)
@@ -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,9 +759,16 @@ 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;
             }