From 5dc4434dc74298b026c724d028a0ea858c0a31ad Mon Sep 17 00:00:00 2001 From: Ole Salscheider Date: Sat, 11 Jun 2022 20:19:23 +0200 Subject: [PATCH] channelmix: Implement PSD upmixing for stereo -> quad Fixes #2436. --- spa/plugins/audioconvert/channelmix-ops-c.c | 24 +++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/spa/plugins/audioconvert/channelmix-ops-c.c b/spa/plugins/audioconvert/channelmix-ops-c.c index 1a6ff6265..305c78d0a 100644 --- a/spa/plugins/audioconvert/channelmix-ops-c.c +++ b/spa/plugins/audioconvert/channelmix-ops-c.c @@ -177,6 +177,7 @@ void channelmix_f32_2_4_c(struct channelmix *mix, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], uint32_t n_samples) { + uint32_t i, n_dst = mix->dst_chan; float **d = (float **)dst; const float **s = (const float **)src; const float v0 = mix->matrix[0][0]; @@ -184,10 +185,25 @@ channelmix_f32_2_4_c(struct channelmix *mix, void * SPA_RESTRICT dst[], const float v2 = mix->matrix[2][0]; const float v3 = mix->matrix[3][1]; - vol_c(d[0], s[0], v0, n_samples); - vol_c(d[1], s[1], v1, n_samples); - vol_c(d[2], s[0], v2, n_samples); - vol_c(d[3], s[1], v3, n_samples); + if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) { + for (i = 0; i < n_dst; i++) + clear_c(d[i], n_samples); + } + else { + vol_c(d[0], s[0], v0, n_samples); + vol_c(d[1], s[1], v1, n_samples); + if (mix->upmix != CHANNELMIX_UPMIX_PSD) { + vol_c(d[2], s[0], v2, n_samples); + vol_c(d[3], s[1], v3, n_samples); + } else { + sub_c(d[2], s[0], s[1], n_samples); + + delay_convolve_run(mix->buffer[1], &mix->pos[1], BUFFER_SIZE, mix->delay, + mix->taps, mix->n_taps, d[3], d[2], -v3, n_samples); + delay_convolve_run(mix->buffer[0], &mix->pos[0], BUFFER_SIZE, mix->delay, + mix->taps, mix->n_taps, d[2], d[2], v2, n_samples); + } + } } #define MASK_3_1 _M(FL)|_M(FR)|_M(FC)|_M(LFE)