remap: Add 4-channel to mono channel rearrangement

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
This commit is contained in:
Peter Meerwald 2014-07-29 17:59:57 +02:00 committed by Peter Meerwald
parent 6fdddf45f7
commit 97d9f4c5dd

View file

@ -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]) { bool pa_setup_remap_arrange(const pa_remap_t *m, int8_t arrange[PA_CHANNELS_MAX]) {
unsigned ic, oc; unsigned ic, oc;
unsigned n_ic, n_oc; unsigned n_ic, n_oc;
unsigned count_output = 0;
pa_assert(m); 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; return false;
arrange[oc] = ic; 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) { 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) { 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 unsigned n_ic = m->i_ss.channels;
const int8_t *arrange = m->state; 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_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_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); (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) { } else if (pa_setup_remap_arrange(m, arrange) && n_oc == 2) {
pa_log_info("Using stereo arrange remapping"); pa_log_info("Using stereo arrange remapping");