[pulseaudio-discuss] [PATCH 08/13] tests: Reorganize cpu-remap-test program

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


Make run_remap_test() support up to 8 input and output channels.

Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
 src/tests/cpu-remap-test.c |  187 +++++++++++++++++++++++++-------------------
 1 file changed, 108 insertions(+), 79 deletions(-)

diff --git a/src/tests/cpu-remap-test.c b/src/tests/cpu-remap-test.c
index 6a6988b..1141749 100644
--- a/src/tests/cpu-remap-test.c
+++ b/src/tests/cpu-remap-test.c
@@ -19,47 +19,54 @@
 #include <check.h>
 
 #include <pulsecore/cpu-x86.h>
+#include <pulsecore/cpu.h>
 #include <pulsecore/random.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/remap.h>
 
 #include "runtime-test-util.h"
 
-#define SAMPLES 1028
+#define SAMPLES 1027
 #define TIMES 1000
 #define TIMES2 100
 
-static void run_remap_test_mono_stereo_float(
+static void run_remap_test_float(
         pa_remap_t *remap_func,
         pa_remap_t *remap_orig,
         int align,
         bool correct,
         bool perf) {
 
-    PA_DECLARE_ALIGNED(8, float, s_ref[SAMPLES*2]) = { 0 };
-    PA_DECLARE_ALIGNED(8, float, s[SAMPLES*2]) = { 0 };
-    PA_DECLARE_ALIGNED(8, float, m[SAMPLES]);
-    float *stereo, *stereo_ref;
-    float *mono;
-    int i, nsamples;
+    PA_DECLARE_ALIGNED(8, float, out_buf_ref[SAMPLES*8]) = { 0.0f, };
+    PA_DECLARE_ALIGNED(8, float, out_buf[SAMPLES*8]) = { 0.0f, };
+    PA_DECLARE_ALIGNED(8, float, in_buf[SAMPLES*8]);
+    float *out, *out_ref;
+    float *in;
+    unsigned n_ic = remap_func->i_ss.channels;
+    unsigned n_oc = remap_func->o_ss.channels;
+    unsigned i, nsamples;
+
+    pa_assert(n_ic >= 1 && n_ic <= 8);
+    pa_assert(n_oc >= 1 && n_oc <= 8);
 
     /* Force sample alignment as requested */
-    stereo = s + (8 - align);
-    stereo_ref = s_ref + (8 - align);
-    mono = m + (8 - align);
+    out = out_buf + (8 - align);
+    out_ref = out_buf_ref + (8 - align);
+    in = in_buf + (8 - align);
     nsamples = SAMPLES - (8 - align);
 
-    for (i = 0; i < nsamples; i++)
-        mono[i] = 2.1f * (rand()/(float) RAND_MAX - 0.5f);
+    for (i = 0; i < nsamples * n_ic; i++)
+        in[i] = 2.1f * (rand()/(float) RAND_MAX - 0.5f);
 
     if (correct) {
-        remap_orig->do_remap(remap_orig, stereo_ref, mono, nsamples);
-        remap_func->do_remap(remap_func, stereo, mono, nsamples);
+        remap_orig->do_remap(remap_orig, out_ref, in, nsamples);
+        remap_func->do_remap(remap_func, out, in, nsamples);
 
-        for (i = 0; i < nsamples * 2; i++) {
-            if (fabsf(stereo[i] - stereo_ref[i]) > 0.0001f) {
+        for (i = 0; i < nsamples * n_oc; i++) {
+            if (fabsf(out[i] - out_ref[i]) > 0.0001f) {
                 pa_log_debug("Correctness test failed: align=%d", align);
-                pa_log_debug("%d: %.24f != %.24f (%.24f)\n", i, stereo[i], stereo_ref[i], mono[i]);
+                pa_log_debug("%d: %.24f != %.24f\n", i,
+                    out[i], out_ref[i]);
                 fail();
             }
         }
@@ -69,45 +76,50 @@ static void run_remap_test_mono_stereo_float(
         pa_log_debug("Testing remap performance with %d sample alignment", align);
 
         PA_RUNTIME_TEST_RUN_START("func", TIMES, TIMES2) {
-            remap_func->do_remap(remap_func, stereo, mono, nsamples);
+            remap_func->do_remap(remap_func, out, in, nsamples);
         } PA_RUNTIME_TEST_RUN_STOP
 
         PA_RUNTIME_TEST_RUN_START("orig", TIMES, TIMES2) {
-            remap_orig->do_remap(remap_orig, stereo_ref, mono, nsamples);
+            remap_orig->do_remap(remap_orig, out_ref, in, nsamples);
         } PA_RUNTIME_TEST_RUN_STOP
     }
 }
 
-static void run_remap_test_mono_stereo_s16(
+static void run_remap_test_s16(
         pa_remap_t *remap_func,
         pa_remap_t *remap_orig,
         int align,
         bool correct,
         bool perf) {
 
-    PA_DECLARE_ALIGNED(8, int16_t, s_ref[SAMPLES*2]) = { 0 };
-    PA_DECLARE_ALIGNED(8, int16_t, s[SAMPLES*2]) = { 0 };
-    PA_DECLARE_ALIGNED(8, int16_t, m[SAMPLES]);
-    int16_t *stereo, *stereo_ref;
-    int16_t *mono;
-    int i, nsamples;
+    PA_DECLARE_ALIGNED(8, int16_t, out_buf_ref[SAMPLES*8]) = { 0 };
+    PA_DECLARE_ALIGNED(8, int16_t, out_buf[SAMPLES*8]) = { 0 };
+    PA_DECLARE_ALIGNED(8, int16_t, in_buf[SAMPLES*8]);
+    int16_t *out, *out_ref;
+    int16_t *in;
+    unsigned n_ic = remap_func->i_ss.channels;
+    unsigned n_oc = remap_func->o_ss.channels;
+    unsigned i, nsamples;
+
+    pa_assert(n_ic >= 1 && n_ic <= 8);
+    pa_assert(n_oc >= 1 && n_oc <= 8);
 
     /* Force sample alignment as requested */
-    stereo = s + (8 - align);
-    stereo_ref = s_ref + (8 - align);
-    mono = m + (8 - align);
+    out = out_buf + (8 - align);
+    out_ref = out_buf_ref + (8 - align);
+    in = in_buf + (8 - align);
     nsamples = SAMPLES - (8 - align);
 
-    pa_random(mono, nsamples * sizeof(int16_t));
+    pa_random(in, nsamples * n_ic * sizeof(int16_t));
 
     if (correct) {
-        remap_orig->do_remap(remap_orig, stereo_ref, mono, nsamples);
-        remap_func->do_remap(remap_func, stereo, mono, nsamples);
+        remap_orig->do_remap(remap_orig, out_ref, in, nsamples);
+        remap_func->do_remap(remap_func, out, in, nsamples);
 
-        for (i = 0; i < nsamples * 2; i++) {
-            if (abs(stereo[i] - stereo_ref[i]) > 1) {
+        for (i = 0; i < nsamples * n_oc; i++) {
+            if (abs(out[i] - out_ref[i]) > 3) {
                 pa_log_debug("Correctness test failed: align=%d", align);
-                pa_log_debug("%d: %d != %d (%d)\n", i, stereo[i], stereo_ref[i], mono[i]);
+                pa_log_debug("%d: %d != %d\n", i, out[i], out_ref[i]);
                 fail();
             }
         }
@@ -117,74 +129,91 @@ static void run_remap_test_mono_stereo_s16(
         pa_log_debug("Testing remap performance with %d sample alignment", align);
 
         PA_RUNTIME_TEST_RUN_START("func", TIMES, TIMES2) {
-            remap_func->do_remap(remap_orig, stereo, mono, nsamples);
+            remap_func->do_remap(remap_func, out, in, nsamples);
         } PA_RUNTIME_TEST_RUN_STOP
 
         PA_RUNTIME_TEST_RUN_START("orig", TIMES, TIMES2) {
-            remap_func->do_remap(remap_func, stereo_ref, mono, nsamples);
+            remap_orig->do_remap(remap_orig, out_ref, in, nsamples);
         } PA_RUNTIME_TEST_RUN_STOP
     }
 }
 
-static void setup_remap_mono_stereo(pa_remap_t *m, pa_sample_format_t f) {
+static void setup_remap_channels(
+    pa_remap_t *m,
+    pa_sample_format_t f,
+    unsigned in_channels,
+    unsigned out_channels) {
+
+    unsigned i, o;
+
     m->format = f;
-    m->i_ss.channels = 1;
-    m->o_ss.channels = 2;
-    m->map_table_f[0][0] = 1.0f;
-    m->map_table_f[1][0] = 1.0f;
-    m->map_table_i[0][0] = 0x10000;
-    m->map_table_i[1][0] = 0x10000;
+    m->i_ss.channels = in_channels;
+    m->o_ss.channels = out_channels;
+
+    if (in_channels == 1) {
+        for (o = 0; o < out_channels; o++) {
+            m->map_table_f[o][0] = 1.0f;
+            m->map_table_i[o][0] = 0x10000;
+        }
+    } else {
+        for (o = 0; o < out_channels; o++) {
+            for (i = 0; i < in_channels; i++) {
+                m->map_table_f[o][i] = 1.0f / in_channels;
+                m->map_table_i[o][i] = 0x10000 / in_channels;
+            }
+        }
+    }
 }
 
-static void remap_test_mono_stereo_float(
-        pa_init_remap_func_t init_func,
-        pa_init_remap_func_t orig_init_func) {
+static void remap_test_channels(
+    pa_remap_t *remap_func, pa_remap_t *remap_orig) {
 
-    pa_remap_t remap_orig, remap_func;
-
-    setup_remap_mono_stereo(&remap_orig, PA_SAMPLE_FLOAT32NE);
-    orig_init_func(&remap_orig);
-    if (!remap_orig.do_remap) {
+    if (!remap_orig->do_remap) {
         pa_log_warn("No reference remapping function, abort test");
         return;
     }
 
-    setup_remap_mono_stereo(&remap_func, PA_SAMPLE_FLOAT32NE);
-    init_func(&remap_func);
-    if (!remap_func.do_remap || remap_func.do_remap == remap_orig.do_remap) {
+    if (!remap_func->do_remap || remap_func->do_remap == remap_orig->do_remap) {
         pa_log_warn("No remapping function, abort test");
         return;
     }
 
-    run_remap_test_mono_stereo_float(&remap_func, &remap_orig, 0, true, false);
-    run_remap_test_mono_stereo_float(&remap_func, &remap_orig, 1, true, false);
-    run_remap_test_mono_stereo_float(&remap_func, &remap_orig, 2, true, false);
-    run_remap_test_mono_stereo_float(&remap_func, &remap_orig, 3, true, true);
+    pa_assert(remap_func->format == remap_orig->format);
+
+    switch (remap_func->format) {
+    case PA_SAMPLE_FLOAT32NE:
+        run_remap_test_float(remap_func, remap_orig, 0, true, false);
+        run_remap_test_float(remap_func, remap_orig, 1, true, false);
+        run_remap_test_float(remap_func, remap_orig, 2, true, false);
+        run_remap_test_float(remap_func, remap_orig, 3, true, true);
+        break;
+    case PA_SAMPLE_S16NE:
+        run_remap_test_s16(remap_func, remap_orig, 0, true, false);
+        run_remap_test_s16(remap_func, remap_orig, 1, true, false);
+        run_remap_test_s16(remap_func, remap_orig, 2, true, false);
+        run_remap_test_s16(remap_func, remap_orig, 3, true, true);
+        break;
+    default:
+        pa_assert_not_reached();
+    }
 }
 
-static void remap_test_mono_stereo_s16(
+static void remap_init_test_channels(
         pa_init_remap_func_t init_func,
-        pa_init_remap_func_t orig_init_func) {
+        pa_init_remap_func_t orig_init_func,
+        pa_sample_format_t f,
+        unsigned in_channels,
+        unsigned out_channels) {
 
     pa_remap_t remap_orig, remap_func;
 
-    setup_remap_mono_stereo(&remap_orig, PA_SAMPLE_S16NE);
+    setup_remap_channels(&remap_orig, f, in_channels, out_channels);
     orig_init_func(&remap_orig);
-    if (!remap_orig.do_remap) {
-        pa_log_warn("No reference remapping function, abort test");
-        return;
-    }
 
+    setup_remap_channels(&remap_func, f, in_channels, out_channels);
     init_func(&remap_func);
-    if (!remap_func.do_remap || remap_func.do_remap == remap_orig.do_remap) {
-        pa_log_warn("No remapping function, abort test");
-        return;
-    }
 
-    run_remap_test_mono_stereo_s16(&remap_func, &remap_orig, 0, true, false);
-    run_remap_test_mono_stereo_s16(&remap_func, &remap_orig, 1, true, false);
-    run_remap_test_mono_stereo_s16(&remap_func, &remap_orig, 2, true, false);
-    run_remap_test_mono_stereo_s16(&remap_func, &remap_orig, 3, true, true);
+    remap_test_channels(&remap_func, &remap_orig);
 }
 
 #if defined (__i386__) || defined (__amd64__)
@@ -202,10 +231,10 @@ START_TEST (remap_mmx_test) {
     orig_init_func = pa_get_init_remap_func();
     pa_remap_func_init_mmx(flags);
     init_func = pa_get_init_remap_func();
-    remap_test_mono_stereo_float(init_func, orig_init_func);
+    remap_init_test_channels(init_func, orig_init_func, PA_SAMPLE_FLOAT32NE, 1, 2);
 
     pa_log_debug("Checking MMX remap (s16, mono->stereo)");
-    remap_test_mono_stereo_s16(init_func, orig_init_func);
+    remap_init_test_channels(init_func, orig_init_func, PA_SAMPLE_S16NE, 1, 2);
 }
 END_TEST
 
@@ -223,10 +252,10 @@ START_TEST (remap_sse2_test) {
     orig_init_func = pa_get_init_remap_func();
     pa_remap_func_init_sse(flags);
     init_func = pa_get_init_remap_func();
-    remap_test_mono_stereo_float(init_func, orig_init_func);
+    remap_init_test_channels(init_func, orig_init_func, PA_SAMPLE_FLOAT32NE, 1, 2);
 
     pa_log_debug("Checking SSE2 remap (s16, mono->stereo)");
-    remap_test_mono_stereo_s16(init_func, orig_init_func);
+    remap_init_test_channels(init_func, orig_init_func, PA_SAMPLE_S16NE, 1, 2);
 }
 END_TEST
 #endif /* defined (__i386__) || defined (__amd64__) */
-- 
1.7.9.5



More information about the pulseaudio-discuss mailing list