[pulseaudio-discuss] [PATCH 05/10] remap: Add 4-channel special case remapping

Peter Meerwald pmeerw at pmeerw.net
Fri Mar 29 08:56:46 PDT 2013


From: Peter Meerwald <p.meerwald at bct-electronic.com>

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

diff --git a/src/pulsecore/remap.c b/src/pulsecore/remap.c
index 9300ab0..1c4eb57 100644
--- a/src/pulsecore/remap.c
+++ b/src/pulsecore/remap.c
@@ -86,6 +86,59 @@ static void remap_mono_to_stereo_c(pa_remap_t *m, void *dst, const void *src, un
     }
 }
 
+static void remap_mono_to_ch4_c(pa_remap_t *m, void *dst, const void *src, unsigned n) {
+    unsigned i;
+
+    switch (*m->format) {
+        case PA_SAMPLE_FLOAT32NE:
+        {
+            float *d, *s;
+
+            d = (float *) dst;
+            s = (float *) src;
+
+            for (i = n >> 2; i; i--) {
+                d[0] = d[1] = d[2] = d[3] = s[0];
+                d[4] = d[5] = d[6] = d[7] = s[1];
+                d[8] = d[9] = d[10] = d[11] = s[2];
+                d[12] = d[13] = d[14] = d[15] = s[3];
+                s += 4;
+                d += 16;
+            }
+            for (i = n & 3; i; i--) {
+                d[0] = d[1] = d[2] = d[3] = s[0];
+                s++;
+                d += 4;
+            }
+            break;
+        }
+        case PA_SAMPLE_S16NE:
+        {
+            int16_t *d, *s;
+
+            d = (int16_t *) dst;
+            s = (int16_t *) src;
+
+            for (i = n >> 2; i; i--) {
+                d[0] = d[1] = d[2] = d[3] = s[0];
+                d[4] = d[5] = d[6] = d[7] = s[1];
+                d[8] = d[9] = d[10] = d[11] = s[2];
+                d[12] = d[13] = d[14] = d[15] = s[3];
+                s += 4;
+                d += 16;
+            }
+            for (i = n & 3; i; i--) {
+                d[0] = d[1] = d[2] = d[3] = s[0];
+                s++;
+                d += 4;
+            }
+            break;
+        }
+        default:
+            pa_assert_not_reached();
+    }
+}
+
 static void remap_stereo_to_mono_c(pa_remap_t *m, void *dst, const void *src, unsigned n) {
     unsigned i;
 
@@ -133,6 +186,53 @@ static void remap_stereo_to_mono_c(pa_remap_t *m, void *dst, const void *src, un
     }
 }
 
+static void remap_ch4_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] + s[2] + s[3])*0.25f;
+                d[1] = (s[4] + s[5] + s[6] + s[7])*0.25f;
+                d[2] = (s[8] + s[9] + s[10] + s[11])*0.25f;
+                d[3] = (s[12] + s[13] + s[14] + s[15])*0.25f;
+                s += 16;
+                d += 4;
+            }
+            for (i = n & 3; i; i--) {
+                d[0] = (s[0] + s[1] + s[2] + s[3])*0.25f;
+                s += 4;
+                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] + s[2] + s[3])/4;
+                d[1] = (s[4] + s[5] + s[6] + s[7])/4;
+                d[2] = (s[8] + s[9] + s[10] + s[11])/4;
+                d[3] = (s[12] + s[13] + s[14] + s[15])/4;
+                s += 16;
+                d += 4;
+            }
+            for (i = n & 3; i; i--) {
+                d[0] = (s[0] + s[1] + s[2] + s[3])/4;
+                s += 4;
+                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;
@@ -219,10 +319,20 @@ 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 == 1 && n_oc == 4 &&
+            m->map_table_i[0][0] == PA_VOLUME_NORM && m->map_table_i[1][0] == PA_VOLUME_NORM &&
+            m->map_table_i[2][0] == PA_VOLUME_NORM && m->map_table_i[3][0] == PA_VOLUME_NORM) {
+        m->do_remap = (pa_do_remap_func_t) remap_mono_to_ch4_c;
+        pa_log_info("Using mono to 4-channel 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 if (n_ic == 4 && n_oc == 1 &&
+            m->map_table_i[0][0] == PA_VOLUME_QUARTER && m->map_table_i[0][1] == PA_VOLUME_QUARTER &&
+            m->map_table_i[0][2] == PA_VOLUME_QUARTER && m->map_table_i[0][3] == PA_VOLUME_QUARTER) {
+        m->do_remap = (pa_do_remap_func_t) remap_ch4_to_mono_c;
+        pa_log_info("Using 4-channel to mono remapping");
     } else {
         m->do_remap = (pa_do_remap_func_t) remap_channels_matrix_c;
         pa_log_info("Using generic matrix remapping");
-- 
1.7.9.5



More information about the pulseaudio-discuss mailing list