[pulseaudio-discuss] [PATCH 5/6] core: add stereo to mono special case remapping
Peter Meerwald
pmeerw at pmeerw.net
Wed Feb 22 03:45:06 PST 2012
From: Peter Meerwald <p.meerwald at bct-electronic.com>
add special-case C code for stereo-to-mone remapping
compiled with Ubuntu/Linaro gcc 4.6.1:
arm-linux-gnueabi-gcc-O2 -mcpu=cortex-a8 -mfloat-abi=softfp -mfpu=neon
runtime on beagle-xm, 800 MHz (ref is the special-case C impl, generic
is the catch-all matrix implementation):
checking NEON remap_mono_to_stereo(float)
NEON: 29999 usec.
ref: 41078 usec.
generic: 713206 usec.
checking NEON remap_stereo_to_mono(float)
NEON: 29114 usec.
ref: 237216 usec.
generic: 823254 usec.
checking NEON remap_mono_to_stereo(s16)
NEON: 15136 usec.
ref: 37690 usec.
generic: 128878 usec.
checking NEON remap_stereo_to_mono(s16)
NEON: 12024 usec.
ref: 49104 usec.
generic: 122439 usec.
---
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.4.1
More information about the pulseaudio-discuss
mailing list