[pulseaudio-discuss] [PATCH v2 04/12] remap: Make resampler's remap structure more self-contained

Peter Meerwald pmeerw at pmeerw.net
Sun Apr 27 14:26:21 PDT 2014


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

Initialization of the remap structure now happens in one place

Rename calc_map_table() to setup_remap(), copy sample format and
channel specs; the remap structure is initialized when we know the
work sample format of the resampler

Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
 src/pulsecore/remap.c     | 12 ++++++------
 src/pulsecore/remap.h     |  4 ++--
 src/pulsecore/remap_mmx.c |  6 +++---
 src/pulsecore/remap_sse.c |  6 +++---
 src/pulsecore/resampler.c | 23 ++++++++++++-----------
 src/tests/cpu-test.c      | 22 ++++++----------------
 6 files changed, 32 insertions(+), 41 deletions(-)

diff --git a/src/pulsecore/remap.c b/src/pulsecore/remap.c
index 653ee7e..136e31d 100644
--- a/src/pulsecore/remap.c
+++ b/src/pulsecore/remap.c
@@ -36,7 +36,7 @@
 static void remap_mono_to_stereo_c(pa_remap_t *m, void *dst, const void *src, unsigned n) {
     unsigned i;
 
-    switch (*m->format) {
+    switch (m->format) {
         case PA_SAMPLE_FLOAT32NE:
         {
             float *d, *s;
@@ -90,10 +90,10 @@ static void remap_channels_matrix_c(pa_remap_t *m, void *dst, const void *src, u
     unsigned oc, ic, i;
     unsigned n_ic, n_oc;
 
-    n_ic = m->i_ss->channels;
-    n_oc = m->o_ss->channels;
+    n_ic = m->i_ss.channels;
+    n_oc = m->o_ss.channels;
 
-    switch (*m->format) {
+    switch (m->format) {
         case PA_SAMPLE_FLOAT32NE:
         {
             float *d, *s;
@@ -164,8 +164,8 @@ static void remap_channels_matrix_c(pa_remap_t *m, void *dst, const void *src, u
 static void init_remap_c(pa_remap_t *m) {
     unsigned n_oc, n_ic;
 
-    n_oc = m->o_ss->channels;
-    n_ic = m->i_ss->channels;
+    n_oc = m->o_ss.channels;
+    n_ic = m->i_ss.channels;
 
     /* find some common channel remappings, fall back to full matrix operation. */
     if (n_ic == 1 && n_oc == 2 &&
diff --git a/src/pulsecore/remap.h b/src/pulsecore/remap.h
index 6411a46..fcfe682 100644
--- a/src/pulsecore/remap.h
+++ b/src/pulsecore/remap.h
@@ -30,8 +30,8 @@ typedef struct pa_remap pa_remap_t;
 typedef void (*pa_do_remap_func_t) (pa_remap_t *m, void *d, const void *s, unsigned n);
 
 struct pa_remap {
-    pa_sample_format_t *format;
-    pa_sample_spec *i_ss, *o_ss;
+    pa_sample_format_t format;
+    pa_sample_spec i_ss, o_ss;
     float map_table_f[PA_CHANNELS_MAX][PA_CHANNELS_MAX];
     int32_t map_table_i[PA_CHANNELS_MAX][PA_CHANNELS_MAX];
     pa_do_remap_func_t do_remap;
diff --git a/src/pulsecore/remap_mmx.c b/src/pulsecore/remap_mmx.c
index bf611a1..3d49045 100644
--- a/src/pulsecore/remap_mmx.c
+++ b/src/pulsecore/remap_mmx.c
@@ -105,7 +105,7 @@
 static void remap_mono_to_stereo_mmx(pa_remap_t *m, void *dst, const void *src, unsigned n) {
     pa_reg_x86 temp, temp2;
 
-    switch (*m->format) {
+    switch (m->format) {
         case PA_SAMPLE_FLOAT32NE:
         {
             __asm__ __volatile__ (
@@ -135,8 +135,8 @@ static void remap_mono_to_stereo_mmx(pa_remap_t *m, void *dst, const void *src,
 static void init_remap_mmx(pa_remap_t *m) {
     unsigned n_oc, n_ic;
 
-    n_oc = m->o_ss->channels;
-    n_ic = m->i_ss->channels;
+    n_oc = m->o_ss.channels;
+    n_ic = m->i_ss.channels;
 
     /* find some common channel remappings, fall back to full matrix operation. */
     if (n_ic == 1 && n_oc == 2 &&
diff --git a/src/pulsecore/remap_sse.c b/src/pulsecore/remap_sse.c
index f43ecb7..be6d3b0 100644
--- a/src/pulsecore/remap_sse.c
+++ b/src/pulsecore/remap_sse.c
@@ -104,7 +104,7 @@
 static void remap_mono_to_stereo_sse2(pa_remap_t *m, void *dst, const void *src, unsigned n) {
     pa_reg_x86 temp, temp2;
 
-    switch (*m->format) {
+    switch (m->format) {
         case PA_SAMPLE_FLOAT32NE:
         {
             __asm__ __volatile__ (
@@ -134,8 +134,8 @@ static void remap_mono_to_stereo_sse2(pa_remap_t *m, void *dst, const void *src,
 static void init_remap_sse2(pa_remap_t *m) {
     unsigned n_oc, n_ic;
 
-    n_oc = m->o_ss->channels;
-    n_ic = m->i_ss->channels;
+    n_oc = m->o_ss.channels;
+    n_ic = m->i_ss.channels;
 
     /* find some common channel remappings, fall back to full matrix operation. */
     if (n_ic == 1 && n_oc == 2 &&
diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 989d6b2..3cbd68c 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -115,7 +115,7 @@ static int peaks_init(pa_resampler*r);
 static int libsamplerate_init(pa_resampler*r);
 #endif
 
-static void calc_map_table(const pa_resampler *r, pa_remap_t *m);
+static void setup_remap(const pa_resampler *r, pa_remap_t *m);
 
 static int (* const init_table[])(pa_resampler*r) = {
 #ifdef HAVE_LIBSAMPLERATE
@@ -379,11 +379,6 @@ pa_resampler* pa_resampler_new(
     r->i_ss = *a;
     r->o_ss = *b;
 
-    /* set up the remap structure */
-    r->remap.i_ss = &r->i_ss;
-    r->remap.o_ss = &r->o_ss;
-    r->remap.format = &r->work_format;
-
     if (am)
         r->i_cm = *am;
     else if (!pa_channel_map_init_auto(&r->i_cm, r->i_ss.channels, PA_CHANNEL_MAP_DEFAULT))
@@ -397,10 +392,8 @@ pa_resampler* pa_resampler_new(
     r->i_fz = pa_frame_size(a);
     r->o_fz = pa_frame_size(b);
 
-    /* compute channel remap table if needed */
-    if ((r->map_required = (r->i_ss.channels != r->o_ss.channels || (!(r->flags & PA_RESAMPLER_NO_REMAP) &&
-        !pa_channel_map_equal(&r->i_cm, &r->o_cm)))))
-        calc_map_table(r, &r->remap);
+    r->map_required = (r->i_ss.channels != r->o_ss.channels || (!(r->flags & PA_RESAMPLER_NO_REMAP) &&
+        !pa_channel_map_equal(&r->i_cm, &r->o_cm)));
 
     r->work_format = pa_resampler_choose_work_format(method, a->format, b->format, r->map_required);
     r->w_sz = pa_sample_size_of_format(r->work_format);
@@ -452,6 +445,10 @@ pa_resampler* pa_resampler_new(
                  pa_sample_format_to_string(b->format), pa_sample_format_to_string(r->work_format));
     pa_log_debug("  channels %d -> %d (resampling %d)", a->channels, b->channels, r->work_channels);
 
+    /* set up the remap structure */
+    if (r->map_required)
+        setup_remap(r, &r->remap);
+
     /* initialize implementation */
     if (init_table[method](r) < 0)
         goto fail;
@@ -789,7 +786,7 @@ static int front_rear_side(pa_channel_position_t p) {
     return ON_OTHER;
 }
 
-static void calc_map_table(const pa_resampler *r, pa_remap_t *m) {
+static void setup_remap(const pa_resampler *r, pa_remap_t *m) {
     unsigned oc, ic;
     unsigned n_oc, n_ic;
     bool ic_connected[PA_CHANNELS_MAX];
@@ -803,6 +800,10 @@ static void calc_map_table(const pa_resampler *r, pa_remap_t *m) {
     n_oc = r->o_ss.channels;
     n_ic = r->i_ss.channels;
 
+    m->format = r->work_format;
+    m->i_ss = r->i_ss;
+    m->o_ss = r->o_ss;
+
     memset(m->map_table_f, 0, sizeof(m->map_table_f));
     memset(m->map_table_i, 0, sizeof(m->map_table_i));
 
diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c
index c57a375..96137c7 100644
--- a/src/tests/cpu-test.c
+++ b/src/tests/cpu-test.c
@@ -549,17 +549,12 @@ static void remap_test_mono_stereo_float(
         pa_init_remap_func_t init_func,
         pa_init_remap_func_t orig_init_func) {
 
-    pa_sample_format_t sf;
     pa_remap_t remap;
-    pa_sample_spec iss, oss;
     pa_do_remap_func_t orig_func, func;
 
-    iss.format = oss.format = sf = PA_SAMPLE_FLOAT32NE;
-    iss.channels = 1;
-    oss.channels = 2;
-    remap.format = &sf;
-    remap.i_ss = &iss;
-    remap.o_ss = &oss;
+    remap.format = PA_SAMPLE_FLOAT32NE;
+    remap.i_ss.channels = 1;
+    remap.o_ss.channels = 2;
     remap.map_table_f[0][0] = 1.0;
     remap.map_table_f[1][0] = 1.0;
     remap.map_table_i[0][0] = 0x10000;
@@ -588,17 +583,12 @@ static void remap_test_mono_stereo_s16(
         pa_init_remap_func_t init_func,
         pa_init_remap_func_t orig_init_func) {
 
-    pa_sample_format_t sf;
     pa_remap_t remap;
-    pa_sample_spec iss, oss;
     pa_do_remap_func_t orig_func, func;
 
-    iss.format = oss.format = sf = PA_SAMPLE_S16NE;
-    iss.channels = 1;
-    oss.channels = 2;
-    remap.format = &sf;
-    remap.i_ss = &iss;
-    remap.o_ss = &oss;
+    remap.format = PA_SAMPLE_S16NE;
+    remap.i_ss.channels = 1;
+    remap.o_ss.channels = 2;
     remap.map_table_f[0][0] = 1.0;
     remap.map_table_f[1][0] = 1.0;
     remap.map_table_i[0][0] = 0x10000;
-- 
1.9.1



More information about the pulseaudio-discuss mailing list