[PATCH 04/10] remap: Add stereo to mono special case remapping

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Peter Meerwald <p.meerwald@xxxxxxxxxxxxxxxxxx>

add special-case C code for stereo-to-mone remapping

v2:
* use consistent array addressing

Signed-off-by: Peter Meerwald <p.meerwald at bct-electronic.com>
---
 src/pulsecore/remap.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/src/pulsecore/remap.c b/src/pulsecore/remap.c
index 5d0cd62..9300ab0 100644
--- a/src/pulsecore/remap.c
+++ b/src/pulsecore/remap.c
@@ -86,6 +86,53 @@ static void remap_mono_to_stereo_c(pa_remap_t *m, void *dst, const void *src, un
     }
 }
 
+static void remap_stereo_to_mono_c(pa_remap_t *m, void *dst, const void *src, unsigned n) {
+    unsigned i;
+
+    switch (*m->format) {
+        case PA_SAMPLE_FLOAT32NE:
+        {
+            float *d = (float *) dst, *s = (float *) src;
+
+            for (i = n >> 2; i > 0; i--) {
+                d[0] = (s[0] + s[1])*0.5f;
+                d[1] = (s[2] + s[3])*0.5f;
+                d[2] = (s[4] + s[5])*0.5f;
+                d[3] = (s[6] + s[7])*0.5f;
+                s += 8;
+                d += 4;
+            }
+            for (i = n & 3; i; i--) {
+                d[0] = (s[0] + s[1])*0.5f;
+                s += 2;
+                d += 1;
+            }
+            break;
+        }
+        case PA_SAMPLE_S16NE:
+        {
+            int16_t *d = (int16_t *) dst, *s = (int16_t *) src;
+
+            for (i = n >> 2; i > 0; i--) {
+                d[0] += (s[0] + s[1])/2;
+                d[1] += (s[2] + s[3])/2;
+                d[2] += (s[4] + s[5])/2;
+                d[3] += (s[6] + s[7])/2;
+                s += 8;
+                d += 4;
+            }
+            for (i = n & 3; i; i--) {
+                d[0] += (s[0] + s[1])/2;
+                s += 2;
+                d += 1;
+            }
+            break;
+        }
+        default:
+            pa_assert_not_reached();
+    }
+}
+
 static void remap_channels_matrix_c(pa_remap_t *m, void *dst, const void *src, unsigned n) {
     unsigned oc, ic, i;
     unsigned n_ic, n_oc;
@@ -172,13 +219,16 @@ static void init_remap_c(pa_remap_t *m) {
             m->map_table_i[0][0] == PA_VOLUME_NORM && m->map_table_i[1][0] == PA_VOLUME_NORM) {
         m->do_remap = (pa_do_remap_func_t) remap_mono_to_stereo_c;
         pa_log_info("Using mono to stereo remapping");
+    } else if (n_ic == 2 && n_oc == 1 &&
+            m->map_table_i[0][0] == PA_VOLUME_HALF && m->map_table_i[0][1] == PA_VOLUME_HALF) {
+        m->do_remap = (pa_do_remap_func_t) remap_stereo_to_mono_c;
+        pa_log_info("Using stereo to mono remapping");
     } else {
         m->do_remap = (pa_do_remap_func_t) remap_channels_matrix_c;
         pa_log_info("Using generic matrix remapping");
     }
 }
 
-
 /* default C implementation */
 static pa_init_remap_func_t remap_func = init_remap_c;
 
-- 
1.7.9.5



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux