From: Peter Meerwald <p.meerwald@xxxxxxxxxxxxxxxxxx> add special-case C code for stereo-to-mone remapping Signed-off-by: Peter Meerwald <p.meerwald at bct-electronic.com> --- src/pulsecore/remap.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 49 insertions(+), 1 deletions(-) diff --git a/src/pulsecore/remap.c b/src/pulsecore/remap.c index b831f78..09257ab 100644 --- a/src/pulsecore/remap.c +++ b/src/pulsecore/remap.c @@ -85,6 +85,51 @@ 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]; + d[1] = s[2] + s[3]; + d[2] = s[4] + s[5]; + d[3] = s[6] + s[7]; + s += 8; + d += 4; + } + for (i = n & 3; i; i--) { + d[0] = s[0] + s[1]; + 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++ += s[0] + s[1]; + *d++ += s[2] + s[3]; + *d++ += s[4] + s[5]; + *d++ += s[6] + s[7]; + s += 8; + } + for (i = n & 3; i; i--) { + *d++ += s[0] + s[1]; + s += 2; + } + 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; @@ -171,13 +216,16 @@ static void init_remap_c(pa_remap_t *m) { m->map_table_f[0][0] >= 1.0 && m->map_table_f[1][0] >= 1.0) { 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_f[0][0] >= 1.0 && m->map_table_f[0][1] >= 1.0) { + 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.5.4