[pulseaudio-discuss] [PATCH 09/11] remap: Cleanup remap function selection, add pa_set_remap_func() helper

Peter Meerwald pmeerw at pmeerw.net
Thu Apr 24 09:09:17 PDT 2014


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

Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
 src/pulsecore/remap.c     |   37 +++++++++++++++++--------------------
 src/pulsecore/remap.h     |    3 +++
 src/pulsecore/remap_mmx.c |   11 +----------
 src/pulsecore/remap_sse.c |   11 +----------
 4 files changed, 22 insertions(+), 40 deletions(-)

diff --git a/src/pulsecore/remap.c b/src/pulsecore/remap.c
index a550b56..6bec79f 100644
--- a/src/pulsecore/remap.c
+++ b/src/pulsecore/remap.c
@@ -166,6 +166,19 @@ bool pa_setup_remap_arrange(const pa_remap_t *m, int8_t arrange[PA_CHANNELS_MAX]
     return true;
 }
 
+void pa_set_remap_func(pa_remap_t *m, pa_do_remap_func_t func_s16,
+    pa_do_remap_func_t func_float) {
+
+    pa_assert(m);
+
+    if (m->format == PA_SAMPLE_S16NE)
+        m->do_remap = func_s16;
+    else if (m->format == PA_SAMPLE_FLOAT32NE)
+        m->do_remap = func_float;
+    else
+        pa_assert_not_reached();
+}
+
 /* set the function that will execute the remapping based on the matrices */
 static void init_remap_c(pa_remap_t *m) {
     unsigned n_oc, n_ic;
@@ -178,28 +191,12 @@ static void init_remap_c(pa_remap_t *m) {
             m->map_table_i[0][0] == 0x10000 && m->map_table_i[1][0] == 0x10000) {
 
         pa_log_info("Using mono to stereo remapping");
-        switch (m->format) {
-        case PA_SAMPLE_S16NE:
-            m->do_remap = (pa_do_remap_func_t) remap_mono_to_stereo_s16ne_c;
-            break;
-        case PA_SAMPLE_FLOAT32NE:
-            m->do_remap = (pa_do_remap_func_t) remap_mono_to_stereo_float32ne_c;
-            break;
-        default:
-            pa_assert_not_reached();
-        }
+        pa_set_remap_func(m, (pa_do_remap_func_t) remap_mono_to_stereo_s16ne_c,
+            (pa_do_remap_func_t) remap_mono_to_stereo_float32ne_c);
     } else {
         pa_log_info("Using generic matrix remapping");
-        switch (m->format) {
-        case PA_SAMPLE_S16NE:
-            m->do_remap = (pa_do_remap_func_t) remap_channels_matrix_s16ne_c;
-            break;
-        case PA_SAMPLE_FLOAT32NE:
-            m->do_remap = (pa_do_remap_func_t) remap_channels_matrix_float32ne_c;
-            break;
-        default:
-            pa_assert_not_reached();
-        }
+
+        pa_set_remap_func(m, remap_channels_matrix_s16ne_c, remap_channels_matrix_float32ne_c);
     }
 }
 
diff --git a/src/pulsecore/remap.h b/src/pulsecore/remap.h
index adf3526..66ab7bc 100644
--- a/src/pulsecore/remap.h
+++ b/src/pulsecore/remap.h
@@ -56,4 +56,7 @@ void pa_set_init_remap_func(pa_init_remap_func_t func);
  */
 bool pa_setup_remap_arrange(const pa_remap_t *m, int8_t arrange[PA_CHANNELS_MAX]);
 
+void pa_set_remap_func(pa_remap_t *m, pa_do_remap_func_t func_s16,
+    pa_do_remap_func_t func_float);
+
 #endif /* fooremapfoo */
diff --git a/src/pulsecore/remap_mmx.c b/src/pulsecore/remap_mmx.c
index ef8c961..bb81de0 100644
--- a/src/pulsecore/remap_mmx.c
+++ b/src/pulsecore/remap_mmx.c
@@ -136,16 +136,7 @@ static void init_remap_mmx(pa_remap_t *m) {
             m->map_table_i[0][0] == 0x10000 && m->map_table_i[1][0] == 0x10000) {
 
         pa_log_info("Using MMX mono to stereo remapping");
-        switch (m->format) {
-        case PA_SAMPLE_S16NE:
-            m->do_remap = (pa_do_remap_func_t) remap_mono_to_stereo_s16ne_mmx;
-            break;
-        case PA_SAMPLE_FLOAT32NE:
-            m->do_remap = (pa_do_remap_func_t) remap_mono_to_stereo_float32ne_mmx;
-            break;
-        default:
-            pa_assert_not_reached();
-        }
+        pa_set_remap_func(m, remap_mono_to_stereo_s16ne_mmx, remap_mono_to_stereo_float32ne_mmx);
     }
 }
 #endif /* defined (__i386__) || defined (__amd64__) */
diff --git a/src/pulsecore/remap_sse.c b/src/pulsecore/remap_sse.c
index 3d28330..2c24c60 100644
--- a/src/pulsecore/remap_sse.c
+++ b/src/pulsecore/remap_sse.c
@@ -135,16 +135,7 @@ static void init_remap_sse2(pa_remap_t *m) {
             m->map_table_i[0][0] == 0x10000 && m->map_table_i[1][0] == 0x10000) {
 
         pa_log_info("Using SSE2 mono to stereo remapping");
-        switch (m->format) {
-        case PA_SAMPLE_S16NE:
-            m->do_remap = (pa_do_remap_func_t) remap_mono_to_stereo_s16ne_sse2;
-            break;
-        case PA_SAMPLE_FLOAT32NE:
-            m->do_remap = (pa_do_remap_func_t) remap_mono_to_stereo_float32ne_sse2;
-            break;
-        default:
-            pa_assert_not_reached();
-        }
+        pa_set_remap_func(m, remap_mono_to_stereo_s16ne_sse2, remap_mono_to_stereo_float32ne_sse2);
     }
 }
 #endif /* defined (__i386__) || defined (__amd64__) */
-- 
1.7.9.5



More information about the pulseaudio-discuss mailing list