From 97d9f4c5dd9aa44fdc7bd7e5919b55c285a19f53 Mon Sep 17 00:00:00 2001
From: Peter Meerwald
Date: Tue, 29 Jul 2014 17:59:57 +0200
Subject: [PATCH] remap: Add 4-channel to mono channel rearrangement
Signed-off-by: Peter Meerwald
---
src/pulsecore/remap.c | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/src/pulsecore/remap.c b/src/pulsecore/remap.c
index 37213d5de..09d4837aa 100644
--- a/src/pulsecore/remap.c
+++ b/src/pulsecore/remap.c
@@ -239,9 +239,12 @@ static void remap_channels_matrix_float32ne_c(pa_remap_t *m, float *dst, const f
}
}
+/* Produce an array containing input channel indices to map to output channels.
+ * If the output channel is empty, the array element is -1. */
bool pa_setup_remap_arrange(const pa_remap_t *m, int8_t arrange[PA_CHANNELS_MAX]) {
unsigned ic, oc;
unsigned n_ic, n_oc;
+ unsigned count_output = 0;
pa_assert(m);
@@ -262,10 +265,22 @@ bool pa_setup_remap_arrange(const pa_remap_t *m, int8_t arrange[PA_CHANNELS_MAX]
return false;
arrange[oc] = ic;
+ count_output++;
}
}
- return true;
+ return count_output > 0;
+}
+
+static void remap_arrange_mono_s16ne_c(pa_remap_t *m, int16_t *dst, const int16_t *src, unsigned n) {
+ const unsigned n_ic = m->i_ss.channels;
+ const int8_t *arrange = m->state;
+
+ src += arrange[0];
+ for (; n > 0; n--) {
+ *dst++ = *src;
+ src += n_ic;
+ }
}
static void remap_arrange_stereo_s16ne_c(pa_remap_t *m, int16_t *dst, const int16_t *src, unsigned n) {
@@ -295,6 +310,17 @@ static void remap_arrange_ch4_s16ne_c(pa_remap_t *m, int16_t *dst, const int16_t
}
}
+static void remap_arrange_mono_float32ne_c(pa_remap_t *m, float *dst, const float *src, unsigned n) {
+ const unsigned n_ic = m->i_ss.channels;
+ const int8_t *arrange = m->state;
+
+ src += arrange[0];
+ for (; n > 0; n--) {
+ *dst++ = *src;
+ src += n_ic;
+ }
+}
+
static void remap_arrange_stereo_float32ne_c(pa_remap_t *m, float *dst, const float *src, unsigned n) {
const unsigned n_ic = m->i_ss.channels;
const int8_t *arrange = m->state;
@@ -370,6 +396,14 @@ static void init_remap_c(pa_remap_t *m) {
pa_log_info("Using 4-channel to mono remapping");
pa_set_remap_func(m, (pa_do_remap_func_t) remap_ch4_to_mono_s16ne_c,
(pa_do_remap_func_t) remap_ch4_to_mono_float32ne_c);
+ } else if (pa_setup_remap_arrange(m, arrange) && n_oc == 1) {
+
+ pa_log_info("Using mono arrange remapping");
+ pa_set_remap_func(m, (pa_do_remap_func_t) remap_arrange_mono_s16ne_c,
+ (pa_do_remap_func_t) remap_arrange_mono_float32ne_c);
+
+ /* setup state */
+ m->state = pa_xnewdup(int8_t, arrange, PA_CHANNELS_MAX);
} else if (pa_setup_remap_arrange(m, arrange) && n_oc == 2) {
pa_log_info("Using stereo arrange remapping");