mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
channelmix: more improvements
work with the default channel layout remap to default channel layout in fmconvert Pass channel positions in resample format
This commit is contained in:
parent
fef616615e
commit
78b7da608f
5 changed files with 201 additions and 143 deletions
|
|
@ -63,58 +63,58 @@ channelmix_f32_2_4_sse(void *data, int n_dst, void *dst[n_dst],
|
|||
float v = m[0];
|
||||
__m128 vol = _mm_set1_ps(v);
|
||||
__m128 in;
|
||||
float *dFL = d[0], *dFR = d[1], *dRL = d[2], *dRR = d[3];
|
||||
float *sFL = s[0], *sFR = s[1];
|
||||
|
||||
if (v <= VOLUME_MIN) {
|
||||
for (i = 0; i < n_dst; i++)
|
||||
memset(d[i], 0, n_bytes);
|
||||
}
|
||||
else if (v == VOLUME_NORM) {
|
||||
float *d0 = d[0], *d1 = d[1], *d2 = d[2], *d3 = d[3], *s0 = s[0], *s1 = s[1];
|
||||
unrolled = n_samples / 4;
|
||||
remain = n_samples & 3;
|
||||
|
||||
for(n = 0; unrolled--; n += 4) {
|
||||
in = _mm_loadu_ps(&s0[n]);
|
||||
_mm_storeu_ps(&d0[n], in);
|
||||
_mm_storeu_ps(&d2[n], in);
|
||||
in = _mm_loadu_ps(&s1[n]);
|
||||
_mm_storeu_ps(&d1[n], in);
|
||||
_mm_storeu_ps(&d3[n], in);
|
||||
in = _mm_loadu_ps(&sFL[n]);
|
||||
_mm_storeu_ps(&dFL[n], in);
|
||||
_mm_storeu_ps(&dRL[n], in);
|
||||
in = _mm_loadu_ps(&sFR[n]);
|
||||
_mm_storeu_ps(&dFR[n], in);
|
||||
_mm_storeu_ps(&dRR[n], in);
|
||||
}
|
||||
for(; remain--; n++) {
|
||||
in = _mm_load_ss(&s0[n]);
|
||||
_mm_store_ss(&d0[n], in);
|
||||
_mm_store_ss(&d2[n], in);
|
||||
in = _mm_load_ss(&s1[n]);
|
||||
_mm_store_ss(&d1[n], in);
|
||||
_mm_store_ss(&d3[n], in);
|
||||
in = _mm_load_ss(&sFL[n]);
|
||||
_mm_store_ss(&dFL[n], in);
|
||||
_mm_store_ss(&dRL[n], in);
|
||||
in = _mm_load_ss(&sFR[n]);
|
||||
_mm_store_ss(&dFR[n], in);
|
||||
_mm_store_ss(&dRR[n], in);
|
||||
}
|
||||
}
|
||||
else {
|
||||
float *d0 = d[0], *d1 = d[1], *d2 = d[2], *d3 = d[3], *s0 = s[0], *s1 = s[1];
|
||||
unrolled = n_samples / 4;
|
||||
remain = n_samples & 3;
|
||||
|
||||
for(n = 0; unrolled--; n += 4) {
|
||||
in = _mm_mul_ps(_mm_loadu_ps(&s0[n]), vol);
|
||||
_mm_storeu_ps(&d0[n], in);
|
||||
_mm_storeu_ps(&d2[n], in);
|
||||
in = _mm_mul_ps(_mm_loadu_ps(&s1[n]), vol);
|
||||
_mm_storeu_ps(&d1[n], in);
|
||||
_mm_storeu_ps(&d3[n], in);
|
||||
in = _mm_mul_ps(_mm_loadu_ps(&sFL[n]), vol);
|
||||
_mm_storeu_ps(&dFL[n], in);
|
||||
_mm_storeu_ps(&dRL[n], in);
|
||||
in = _mm_mul_ps(_mm_loadu_ps(&sFR[n]), vol);
|
||||
_mm_storeu_ps(&dFR[n], in);
|
||||
_mm_storeu_ps(&dRR[n], in);
|
||||
}
|
||||
for(; remain--; n++) {
|
||||
in = _mm_mul_ss(_mm_load_ss(&s0[n]), vol);
|
||||
_mm_store_ss(&d0[n], in);
|
||||
_mm_store_ss(&d2[n], in);
|
||||
in = _mm_mul_ss(_mm_load_ss(&s1[n]), vol);
|
||||
_mm_store_ss(&d1[n], in);
|
||||
_mm_store_ss(&d3[n], in);
|
||||
in = _mm_mul_ss(_mm_load_ss(&sFL[n]), vol);
|
||||
_mm_store_ss(&dFL[n], in);
|
||||
_mm_store_ss(&dRL[n], in);
|
||||
in = _mm_mul_ss(_mm_load_ss(&sFR[n]), vol);
|
||||
_mm_store_ss(&dFR[n], in);
|
||||
_mm_store_ss(&dRR[n], in);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* FL+FR+RL+RR+FC+LFE -> FL+FR */
|
||||
/* FL+FR+FC+LFE+SL+SR -> FL+FR */
|
||||
static void
|
||||
channelmix_f32_5p1_2_sse(void *data, int n_dst, void *dst[n_dst],
|
||||
int n_src, const void *src[n_src], void *matrix, int n_bytes)
|
||||
|
|
@ -128,76 +128,75 @@ channelmix_f32_5p1_2_sse(void *data, int n_dst, void *dst[n_dst],
|
|||
__m128 slev = _mm_set1_ps(0.7071f);
|
||||
__m128 vol = _mm_set1_ps(v);
|
||||
__m128 in, ctr;
|
||||
float *dFL = d[0], *dFR = d[1];
|
||||
float *sFL = s[0], *sFR = s[1], *sFC = s[2], *sSL = s[4], *sSR = s[5];
|
||||
|
||||
if (v <= VOLUME_MIN) {
|
||||
memset(d[0], 0, n_bytes);
|
||||
memset(d[1], 0, n_bytes);
|
||||
memset(dFL, 0, n_bytes);
|
||||
memset(dFR, 0, n_bytes);
|
||||
}
|
||||
else if (v == VOLUME_NORM) {
|
||||
float *d0 = d[0], *d1 = d[1], *s0 = s[0], *s1 = s[1], *s2 = s[2], *s3 = s[3], *s4 = s[4];
|
||||
|
||||
unrolled = n_samples / 4;
|
||||
remain = n_samples & 3;
|
||||
|
||||
for(n = 0; unrolled--; n += 4) {
|
||||
ctr = _mm_mul_ps(_mm_loadu_ps(&s4[n]), clev);
|
||||
in = _mm_mul_ps(_mm_loadu_ps(&s2[n]), slev);
|
||||
ctr = _mm_mul_ps(_mm_loadu_ps(&sFC[n]), clev);
|
||||
in = _mm_mul_ps(_mm_loadu_ps(&sSL[n]), slev);
|
||||
in = _mm_add_ps(in, ctr);
|
||||
in = _mm_add_ps(in, _mm_loadu_ps(&s0[n]));
|
||||
_mm_storeu_ps(&d0[n], in);
|
||||
in = _mm_mul_ps(_mm_loadu_ps(&s3[n]), slev);
|
||||
in = _mm_add_ps(in, _mm_loadu_ps(&sFL[n]));
|
||||
_mm_storeu_ps(&dFL[n], in);
|
||||
in = _mm_mul_ps(_mm_loadu_ps(&sSR[n]), slev);
|
||||
in = _mm_add_ps(in, ctr);
|
||||
in = _mm_add_ps(in, _mm_loadu_ps(&s1[n]));
|
||||
_mm_storeu_ps(&d1[n], in);
|
||||
in = _mm_add_ps(in, _mm_loadu_ps(&sFR[n]));
|
||||
_mm_storeu_ps(&dFR[n], in);
|
||||
}
|
||||
for(; remain--; n++) {
|
||||
ctr = _mm_mul_ss(_mm_load_ss(&s4[n]), clev);
|
||||
in = _mm_mul_ss(_mm_load_ss(&s2[n]), slev);
|
||||
ctr = _mm_mul_ss(_mm_load_ss(&sFC[n]), clev);
|
||||
in = _mm_mul_ss(_mm_load_ss(&sSL[n]), slev);
|
||||
in = _mm_add_ss(in, ctr);
|
||||
in = _mm_add_ss(in, _mm_load_ss(&s0[n]));
|
||||
_mm_store_ss(&d0[n], in);
|
||||
in = _mm_mul_ss(_mm_load_ss(&s3[n]), slev);
|
||||
in = _mm_add_ss(in, _mm_load_ss(&sFL[n]));
|
||||
_mm_store_ss(&dFL[n], in);
|
||||
in = _mm_mul_ss(_mm_load_ss(&sSR[n]), slev);
|
||||
in = _mm_add_ss(in, ctr);
|
||||
in = _mm_add_ss(in, _mm_load_ss(&s1[n]));
|
||||
_mm_store_ss(&d1[n], in);
|
||||
in = _mm_add_ss(in, _mm_load_ss(&sFR[n]));
|
||||
_mm_store_ss(&dFR[n], in);
|
||||
}
|
||||
}
|
||||
else {
|
||||
float *d0 = d[0], *d1 = d[1], *s0 = s[0], *s1 = s[1], *s2 = s[2], *s3 = s[3], *s4 = s[4];
|
||||
|
||||
unrolled = n_samples / 4;
|
||||
remain = n_samples & 3;
|
||||
|
||||
for(n = 0; unrolled--; n += 4) {
|
||||
ctr = _mm_mul_ps(_mm_loadu_ps(&s4[n]), clev);
|
||||
in = _mm_mul_ps(_mm_loadu_ps(&s2[n]), slev);
|
||||
ctr = _mm_mul_ps(_mm_loadu_ps(&sFC[n]), clev);
|
||||
in = _mm_mul_ps(_mm_loadu_ps(&sSL[n]), slev);
|
||||
in = _mm_add_ps(in, ctr);
|
||||
in = _mm_add_ps(in, _mm_loadu_ps(&s0[n]));
|
||||
in = _mm_add_ps(in, _mm_loadu_ps(&sFL[n]));
|
||||
in = _mm_mul_ps(in, vol);
|
||||
_mm_storeu_ps(&d0[n], in);
|
||||
in = _mm_mul_ps(_mm_loadu_ps(&s3[n]), slev);
|
||||
_mm_storeu_ps(&dFL[n], in);
|
||||
in = _mm_mul_ps(_mm_loadu_ps(&sSR[n]), slev);
|
||||
in = _mm_add_ps(in, ctr);
|
||||
in = _mm_add_ps(in, _mm_loadu_ps(&s1[n]));
|
||||
in = _mm_add_ps(in, _mm_loadu_ps(&sFR[n]));
|
||||
in = _mm_mul_ps(in, vol);
|
||||
_mm_storeu_ps(&d1[n], in);
|
||||
_mm_storeu_ps(&dFR[n], in);
|
||||
}
|
||||
for(; remain--; n++) {
|
||||
ctr = _mm_mul_ss(_mm_load_ss(&s4[n]), clev);
|
||||
in = _mm_mul_ss(_mm_load_ss(&s2[n]), slev);
|
||||
ctr = _mm_mul_ss(_mm_load_ss(&sFC[n]), clev);
|
||||
in = _mm_mul_ss(_mm_load_ss(&sSL[n]), slev);
|
||||
in = _mm_add_ss(in, ctr);
|
||||
in = _mm_add_ss(in, _mm_load_ss(&s0[n]));
|
||||
in = _mm_add_ss(in, _mm_load_ss(&sFL[n]));
|
||||
in = _mm_mul_ss(in, vol);
|
||||
_mm_store_ss(&d0[n], in);
|
||||
in = _mm_mul_ss(_mm_load_ss(&s3[n]), slev);
|
||||
_mm_store_ss(&dFL[n], in);
|
||||
in = _mm_mul_ss(_mm_load_ss(&sSR[n]), slev);
|
||||
in = _mm_add_ss(in, ctr);
|
||||
in = _mm_add_ss(in, _mm_load_ss(&s1[n]));
|
||||
in = _mm_add_ss(in, _mm_load_ss(&sFR[n]));
|
||||
in = _mm_mul_ss(in, vol);
|
||||
_mm_store_ss(&d1[n], in);
|
||||
_mm_store_ss(&dFR[n], in);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* FL+FR+RL+RR+FC+LFE -> FL+FR+RL+RR*/
|
||||
/* FL+FR+FC+LFE+SL+SR -> FL+FR+RL+RR*/
|
||||
static void
|
||||
channelmix_f32_5p1_4_sse(void *data, int n_dst, void *dst[n_dst],
|
||||
int n_src, const void *src[n_src], void *matrix, int n_bytes)
|
||||
|
|
@ -210,53 +209,49 @@ channelmix_f32_5p1_4_sse(void *data, int n_dst, void *dst[n_dst],
|
|||
__m128 clev = _mm_set1_ps(0.7071f);
|
||||
__m128 vol = _mm_set1_ps(v);
|
||||
__m128 ctr;
|
||||
float *dFL = d[0], *dFR = d[1], *dRL = d[2], *dRR = d[3];
|
||||
float *sFL = s[0], *sFR = s[1], *sFC = s[2], *sSL = s[4], *sSR = s[5];
|
||||
|
||||
if (v <= VOLUME_MIN) {
|
||||
for (i = 0; i < n_dst; i++)
|
||||
memset(d[i], 0, n_bytes);
|
||||
}
|
||||
else if (v == VOLUME_NORM) {
|
||||
float *s0 = s[0], *s1 = s[1], *s2 = s[2], *s3 = s[3], *s4 = s[4];
|
||||
float *d0 = d[0], *d1 = d[1], *d2 = d[2], *d3 = d[3];
|
||||
|
||||
unrolled = n_samples / 4;
|
||||
remain = n_samples & 3;
|
||||
|
||||
for(n = 0; unrolled--; n += 4) {
|
||||
ctr = _mm_mul_ps(_mm_loadu_ps(&s4[n]), clev);
|
||||
_mm_storeu_ps(&d0[n], _mm_add_ps(_mm_loadu_ps(&s0[n]), ctr));
|
||||
_mm_storeu_ps(&d1[n], _mm_add_ps(_mm_loadu_ps(&s1[n]), ctr));
|
||||
_mm_storeu_ps(&d2[n], _mm_loadu_ps(&s2[n]));
|
||||
_mm_storeu_ps(&d3[n], _mm_loadu_ps(&s3[n]));
|
||||
ctr = _mm_mul_ps(_mm_loadu_ps(&sFC[n]), clev);
|
||||
_mm_storeu_ps(&dFL[n], _mm_add_ps(_mm_loadu_ps(&sFL[n]), ctr));
|
||||
_mm_storeu_ps(&dFR[n], _mm_add_ps(_mm_loadu_ps(&sFR[n]), ctr));
|
||||
_mm_storeu_ps(&dRL[n], _mm_loadu_ps(&sSL[n]));
|
||||
_mm_storeu_ps(&dRR[n], _mm_loadu_ps(&sSR[n]));
|
||||
}
|
||||
for(; remain--; n++) {
|
||||
ctr = _mm_mul_ss(_mm_load_ss(&s4[n]), clev);
|
||||
_mm_store_ss(&d0[n], _mm_add_ss(_mm_load_ss(&s0[n]), ctr));
|
||||
_mm_store_ss(&d1[n], _mm_add_ss(_mm_load_ss(&s1[n]), ctr));
|
||||
_mm_store_ss(&d2[n], _mm_load_ss(&s2[n]));
|
||||
_mm_store_ss(&d3[n], _mm_load_ss(&s3[n]));
|
||||
ctr = _mm_mul_ss(_mm_load_ss(&sFC[n]), clev);
|
||||
_mm_store_ss(&dFL[n], _mm_add_ss(_mm_load_ss(&sFL[n]), ctr));
|
||||
_mm_store_ss(&dFR[n], _mm_add_ss(_mm_load_ss(&sFR[n]), ctr));
|
||||
_mm_store_ss(&dRL[n], _mm_load_ss(&sSL[n]));
|
||||
_mm_store_ss(&dRR[n], _mm_load_ss(&sSR[n]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
float *s0 = s[0], *s1 = s[1], *s2 = s[2], *s3 = s[3], *s4 = s[4];
|
||||
float *d0 = d[0], *d1 = d[1], *d2 = d[2], *d3 = d[3];
|
||||
|
||||
unrolled = n_samples / 4;
|
||||
remain = n_samples & 3;
|
||||
|
||||
for(n = 0; unrolled--; n += 4) {
|
||||
ctr = _mm_mul_ps(_mm_loadu_ps(&s4[n]), clev);
|
||||
_mm_storeu_ps(&d0[n], _mm_mul_ps(_mm_add_ps(_mm_loadu_ps(&s0[n]), ctr), vol));
|
||||
_mm_storeu_ps(&d1[n], _mm_mul_ps(_mm_add_ps(_mm_loadu_ps(&s1[n]), ctr), vol));
|
||||
_mm_storeu_ps(&d2[n], _mm_mul_ps(_mm_loadu_ps(&s2[n]), vol));
|
||||
_mm_storeu_ps(&d3[n], _mm_mul_ps(_mm_loadu_ps(&s3[n]), vol));
|
||||
ctr = _mm_mul_ps(_mm_loadu_ps(&sFC[n]), clev);
|
||||
_mm_storeu_ps(&dFL[n], _mm_mul_ps(_mm_add_ps(_mm_loadu_ps(&sFL[n]), ctr), vol));
|
||||
_mm_storeu_ps(&dFR[n], _mm_mul_ps(_mm_add_ps(_mm_loadu_ps(&sFR[n]), ctr), vol));
|
||||
_mm_storeu_ps(&dRL[n], _mm_mul_ps(_mm_loadu_ps(&sSL[n]), vol));
|
||||
_mm_storeu_ps(&dRR[n], _mm_mul_ps(_mm_loadu_ps(&sSR[n]), vol));
|
||||
}
|
||||
for(; remain--; n++) {
|
||||
ctr = _mm_mul_ss(_mm_load_ss(&s4[n]), clev);
|
||||
_mm_store_ss(&d0[n], _mm_mul_ss(_mm_add_ss(_mm_load_ss(&s0[n]), ctr), vol));
|
||||
_mm_store_ss(&d1[n], _mm_mul_ss(_mm_add_ss(_mm_load_ss(&s1[n]), ctr), vol));
|
||||
_mm_store_ss(&d2[n], _mm_mul_ss(_mm_load_ss(&s2[n]), vol));
|
||||
_mm_store_ss(&d3[n], _mm_mul_ss(_mm_load_ss(&s3[n]), vol));
|
||||
ctr = _mm_mul_ss(_mm_load_ss(&sFC[n]), clev);
|
||||
_mm_store_ss(&dFL[n], _mm_mul_ss(_mm_add_ss(_mm_load_ss(&sFL[n]), ctr), vol));
|
||||
_mm_store_ss(&dFR[n], _mm_mul_ss(_mm_add_ss(_mm_load_ss(&sFR[n]), ctr), vol));
|
||||
_mm_store_ss(&dRL[n], _mm_mul_ss(_mm_load_ss(&sSL[n]), vol));
|
||||
_mm_store_ss(&dRR[n], _mm_mul_ss(_mm_load_ss(&sSR[n]), vol));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ channelmix_copy(void *data, int n_dst, void *dst[n_dst],
|
|||
}
|
||||
}
|
||||
|
||||
#define _M(ch) (1UL << SPA_AUDIO_CHANNEL_ ## ch)
|
||||
|
||||
static void
|
||||
channelmix_f32_n_m(void *data, int n_dst, void *dst[n_dst],
|
||||
int n_src, const void *src[n_src], void *matrix, int n_bytes)
|
||||
|
|
@ -75,6 +77,9 @@ channelmix_f32_n_m(void *data, int n_dst, void *dst[n_dst],
|
|||
}
|
||||
}
|
||||
|
||||
#define MASK_MONO _M(FC)|_M(MONO)|_M(UNKNOWN)
|
||||
#define MASK_STEREO _M(FL)|_M(FR)|_M(UNKNOWN)
|
||||
|
||||
static void
|
||||
channelmix_f32_1_2(void *data, int n_dst, void *dst[n_dst],
|
||||
int n_src, const void *src[n_src], void *matrix, int n_bytes)
|
||||
|
|
@ -119,6 +124,9 @@ channelmix_f32_2_1(void *data, int n_dst, void *dst[n_dst],
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#define MASK_QUAD _M(FL)|_M(FR)|_M(RL)|_M(RR)|_M(UNKNOWN)
|
||||
|
||||
static void
|
||||
channelmix_f32_2_4(void *data, int n_dst, void *dst[n_dst],
|
||||
int n_src, const void *src[n_src], void *matrix, int n_bytes)
|
||||
|
|
@ -147,6 +155,7 @@ channelmix_f32_2_4(void *data, int n_dst, void *dst[n_dst],
|
|||
}
|
||||
}
|
||||
|
||||
#define MASK_3_1 _M(FL)|_M(FR)|_M(FC)|_M(LFE)
|
||||
static void
|
||||
channelmix_f32_2_3p1(void *data, int n_dst, void *dst[n_dst],
|
||||
int n_src, const void *src[n_src], void *matrix, int n_bytes)
|
||||
|
|
@ -180,6 +189,7 @@ channelmix_f32_2_3p1(void *data, int n_dst, void *dst[n_dst],
|
|||
}
|
||||
}
|
||||
|
||||
#define MASK_5_1 _M(FL)|_M(FR)|_M(FC)|_M(LFE)|_M(SL)|_M(SR)|_M(RL)|_M(RR)
|
||||
static void
|
||||
channelmix_f32_2_5p1(void *data, int n_dst, void *dst[n_dst],
|
||||
int n_src, const void *src[n_src], void *matrix, int n_bytes)
|
||||
|
|
@ -196,24 +206,24 @@ channelmix_f32_2_5p1(void *data, int n_dst, void *dst[n_dst],
|
|||
}
|
||||
else if (v == VOLUME_NORM) {
|
||||
for (n = 0; n < n_samples; n++) {
|
||||
d[0][n] = d[2][n] = s[0][n];
|
||||
d[1][n] = d[3][n] = s[1][n];
|
||||
d[4][n] = (s[0][n] + s[1][n]) * 0.5f;
|
||||
d[5][n] = 0.0f;
|
||||
d[0][n] = d[4][n] = s[0][n];
|
||||
d[1][n] = d[5][n] = s[1][n];
|
||||
d[2][n] = (s[0][n] + s[1][n]) * 0.5f;
|
||||
d[3][n] = 0.0f;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const float f = 0.5f * v;
|
||||
for (n = 0; n < n_samples; n++) {
|
||||
d[0][n] = d[2][n] = s[0][n] * v;
|
||||
d[1][n] = d[3][n] = s[1][n] * v;
|
||||
d[4][n] = (s[0][n] + s[1][n]) * f;
|
||||
d[5][n] = 0.0f;
|
||||
d[0][n] = d[4][n] = s[0][n] * v;
|
||||
d[1][n] = d[5][n] = s[1][n] * v;
|
||||
d[2][n] = (s[0][n] + s[1][n]) * f;
|
||||
d[3][n] = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* FL+FR+RL+RR+FC+LFE -> FL+FR */
|
||||
/* FL+FR+FC+LFE+RL+RR -> FL+FR */
|
||||
static void
|
||||
channelmix_f32_5p1_2(void *data, int n_dst, void *dst[n_dst],
|
||||
int n_src, const void *src[n_src], void *matrix, int n_bytes)
|
||||
|
|
@ -232,21 +242,21 @@ channelmix_f32_5p1_2(void *data, int n_dst, void *dst[n_dst],
|
|||
}
|
||||
else if (v == VOLUME_NORM) {
|
||||
for (n = 0; n < n_samples; n++) {
|
||||
const float ctr = clev * s[4][n];
|
||||
d[0][n] = s[0][n] + ctr + (slev * s[2][n]);
|
||||
d[1][n] = s[1][n] + ctr + (slev * s[3][n]);
|
||||
const float ctr = clev * s[2][n];
|
||||
d[0][n] = s[0][n] + ctr + (slev * s[4][n]);
|
||||
d[1][n] = s[1][n] + ctr + (slev * s[5][n]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (n = 0; n < n_samples; n++) {
|
||||
const float ctr = clev * s[4][n];
|
||||
d[0][n] = (s[0][n] + ctr + (slev * s[2][n])) * v;
|
||||
d[1][n] = (s[1][n] + ctr + (slev * s[3][n])) * v;
|
||||
const float ctr = clev * s[2][n];
|
||||
d[0][n] = (s[0][n] + ctr + (slev * s[4][n])) * v;
|
||||
d[1][n] = (s[1][n] + ctr + (slev * s[5][n])) * v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* FL+FR+RL+RR+FC+LFE -> FL+FR+FC+LFE*/
|
||||
/* FL+FR+FC+LFE+RL+RR -> FL+FR+FC+LFE*/
|
||||
static void
|
||||
channelmix_f32_5p1_3p1(void *data, int n_dst, void *dst[n_dst],
|
||||
int n_src, const void *src[n_src], void *matrix, int n_bytes)
|
||||
|
|
@ -265,15 +275,15 @@ channelmix_f32_5p1_3p1(void *data, int n_dst, void *dst[n_dst],
|
|||
else {
|
||||
const float f1 = 0.5f * v;
|
||||
for (n = 0; n < n_samples; n++) {
|
||||
d[0][n] = (s[0][n] + s[2][n]) * f1;
|
||||
d[1][n] = (s[1][n] + s[3][n]) * f1;
|
||||
d[2][n] = s[4][n] * v;
|
||||
d[3][n] = s[5][n] * v;
|
||||
d[0][n] = (s[0][n] + s[4][n]) * f1;
|
||||
d[1][n] = (s[1][n] + s[5][n]) * f1;
|
||||
d[2][n] = s[2][n] * v;
|
||||
d[3][n] = s[3][n] * v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* FL+FR+RL+RR+FC+LFE -> FL+FR+RL+RR*/
|
||||
/* FL+FR+FC+LFE+RL+RR -> FL+FR+RL+RR*/
|
||||
static void
|
||||
channelmix_f32_5p1_4(void *data, int n_dst, void *dst[n_dst],
|
||||
int n_src, const void *src[n_src], void *matrix, int n_bytes)
|
||||
|
|
@ -291,20 +301,20 @@ channelmix_f32_5p1_4(void *data, int n_dst, void *dst[n_dst],
|
|||
}
|
||||
else if (v == VOLUME_NORM) {
|
||||
for (n = 0; n < n_samples; n++) {
|
||||
float ctr = s[4][n] * 0.7071f;
|
||||
float ctr = s[2][n] * 0.7071f;
|
||||
d[0][n] = s[0][n] + ctr;
|
||||
d[1][n] = s[1][n] + ctr;
|
||||
d[2][n] = s[2][n];
|
||||
d[3][n] = s[3][n];
|
||||
d[2][n] = s[4][n];
|
||||
d[3][n] = s[5][n];
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (n = 0; n < n_samples; n++) {
|
||||
float ctr = s[4][n] * 0.7071f;
|
||||
float ctr = s[2][n] * 0.7071f;
|
||||
d[0][n] = (s[0][n] + ctr) * v;
|
||||
d[1][n] = (s[1][n] + ctr) * v;
|
||||
d[2][n] = s[2][n] * v;
|
||||
d[3][n] = s[3][n] * v;
|
||||
d[2][n] = s[4][n] * v;
|
||||
d[3][n] = s[5][n] * v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -326,43 +336,48 @@ static const struct channelmix_info {
|
|||
} channelmix_table[] =
|
||||
{
|
||||
#if defined (__SSE2__)
|
||||
{ -2, 0, -2, 0, channelmix_copy_sse, 0 },
|
||||
{ -2, 0, -2, 0, channelmix_copy_sse, FEATURE_SSE },
|
||||
#endif
|
||||
{ -2, 0, -2, 0, channelmix_copy, 0 },
|
||||
{ 1, 0, 2, 0, channelmix_f32_1_2, 0 },
|
||||
{ 2, 0, 1, 0, channelmix_f32_2_1, 0 },
|
||||
{ 1, MASK_MONO, 2, MASK_STEREO, channelmix_f32_1_2, 0 },
|
||||
{ 2, MASK_STEREO, 1, MASK_MONO, channelmix_f32_2_1, 0 },
|
||||
#if defined (__SSE2__)
|
||||
{ 2, 0, 4, 0, channelmix_f32_2_4_sse, FEATURE_SSE },
|
||||
{ 2, MASK_STEREO, 4, MASK_QUAD, channelmix_f32_2_4_sse, FEATURE_SSE },
|
||||
#endif
|
||||
{ 2, 0, 4, 0, channelmix_f32_2_4, 0 },
|
||||
{ 2, 0, 4, 0, channelmix_f32_2_3p1, 0 },
|
||||
{ 2, 0, 6, 0, channelmix_f32_2_5p1, 0 },
|
||||
{ 2, MASK_STEREO, 4, MASK_QUAD, channelmix_f32_2_4, 0 },
|
||||
{ 2, MASK_STEREO, 4, MASK_3_1, channelmix_f32_2_3p1, 0 },
|
||||
{ 2, MASK_STEREO, 6, MASK_5_1, channelmix_f32_2_5p1, 0 },
|
||||
#if defined (__SSE2__)
|
||||
{ 6, 0, 2, 0, channelmix_f32_5p1_2_sse, FEATURE_SSE },
|
||||
{ 6, MASK_5_1, 2, MASK_STEREO, channelmix_f32_5p1_2_sse, FEATURE_SSE },
|
||||
#endif
|
||||
{ 6, 0, 2, 0, channelmix_f32_5p1_2, 0 },
|
||||
{ 6, MASK_5_1, 2, MASK_STEREO, channelmix_f32_5p1_2, 0 },
|
||||
#if defined (__SSE2__)
|
||||
{ 6, 0, 4, 0, channelmix_f32_5p1_4_sse, FEATURE_SSE },
|
||||
{ 6, MASK_5_1, 4, MASK_QUAD, channelmix_f32_5p1_4_sse, FEATURE_SSE },
|
||||
#endif
|
||||
{ 6, 0, 4, 0, channelmix_f32_5p1_4, 0 },
|
||||
{ 6, 0, 4, 0, channelmix_f32_5p1_3p1, 0 },
|
||||
{ 6, MASK_5_1, 4, MASK_QUAD, channelmix_f32_5p1_4, 0 },
|
||||
{ 6, MASK_5_1, 4, MASK_3_1, channelmix_f32_5p1_3p1, 0 },
|
||||
{ -1, 0, -1, 0, channelmix_f32_n_m, 0 },
|
||||
};
|
||||
|
||||
#define MATCH_CHAN(a,b) ((a) == -1 || (a) == (b))
|
||||
#define MATCH_CHAN(a,b) ((a) == -1 || (a) == (b))
|
||||
#define MATCH_FEATURES(a,b) ((a) == 0 || ((a) & (b)) != 0)
|
||||
#define MATCH_MASK(a,b) (((a) & (b)) == (b))
|
||||
|
||||
static const struct channelmix_info *find_channelmix_info(uint32_t src_chan, uint64_t src_mask,
|
||||
uint32_t dst_chan, uint64_t dst_mask, uint32_t features)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(channelmix_table); i++) {
|
||||
if (!MATCH_FEATURES(channelmix_table[i].features, features))
|
||||
continue;
|
||||
|
||||
if (src_chan == dst_chan && src_mask == dst_mask)
|
||||
return &channelmix_table[0];
|
||||
if (src_chan == dst_chan && src_mask == dst_mask)
|
||||
return &channelmix_table[i];
|
||||
|
||||
for (i = 1; i < SPA_N_ELEMENTS(channelmix_table); i++) {
|
||||
if (MATCH_CHAN(channelmix_table[i].src_chan, src_chan) &&
|
||||
MATCH_CHAN(channelmix_table[i].dst_chan, dst_chan) &&
|
||||
(channelmix_table[i].features == 0 || (channelmix_table[i].features & features) != 0))
|
||||
MATCH_MASK(channelmix_table[i].src_mask, src_mask) &&
|
||||
MATCH_MASK(channelmix_table[i].dst_mask, dst_mask))
|
||||
return &channelmix_table[i];
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -132,6 +132,8 @@ static int setup_convert(struct impl *this,
|
|||
const struct spa_audio_info *src_info, *dst_info;
|
||||
uint32_t src_chan, dst_chan;
|
||||
const struct channelmix_info *chanmix_info;
|
||||
uint64_t src_mask, dst_mask;
|
||||
int i;
|
||||
|
||||
if (direction == SPA_DIRECTION_INPUT) {
|
||||
src_info = info;
|
||||
|
|
@ -144,19 +146,25 @@ static int setup_convert(struct impl *this,
|
|||
src_chan = src_info->info.raw.channels;
|
||||
dst_chan = dst_info->info.raw.channels;
|
||||
|
||||
spa_log_info(this->log, NAME " %p: %s/%d@%d->%s/%d@%d", this,
|
||||
for (i = 0, src_mask = 0; i < src_chan; i++)
|
||||
src_mask |= 1UL << src_info->info.raw.position[i];
|
||||
for (i = 0, dst_mask = 0; i < dst_chan; i++)
|
||||
dst_mask |= 1UL << dst_info->info.raw.position[i];
|
||||
|
||||
spa_log_info(this->log, NAME " %p: %s/%d@%d->%s/%d@%d %08lx:%08lx", this,
|
||||
spa_debug_type_find_name(spa_type_audio_format, src_info->info.raw.format),
|
||||
src_chan,
|
||||
src_info->info.raw.rate,
|
||||
spa_debug_type_find_name(spa_type_audio_format, dst_info->info.raw.format),
|
||||
dst_chan,
|
||||
dst_info->info.raw.rate);
|
||||
dst_info->info.raw.rate,
|
||||
src_mask, dst_mask);
|
||||
|
||||
if (src_info->info.raw.rate != dst_info->info.raw.rate)
|
||||
return -EINVAL;
|
||||
|
||||
/* find convert function */
|
||||
if ((chanmix_info = find_channelmix_info(src_chan, 0, dst_chan, 0, FEATURE_SSE)) == NULL)
|
||||
if ((chanmix_info = find_channelmix_info(src_chan, src_mask, dst_chan, dst_mask, FEATURE_SSE)) == NULL)
|
||||
return -ENOTSUP;
|
||||
|
||||
spa_log_info(this->log, NAME " %p: got channelmix features %08x", this, chanmix_info->features);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
#include <spa/param/param.h>
|
||||
#include <spa/pod/filter.h>
|
||||
#include <spa/debug/types.h>
|
||||
#include <spa/debug/format.h>
|
||||
|
||||
#define NAME "fmtconvert"
|
||||
|
||||
|
|
@ -113,6 +114,8 @@ struct impl {
|
|||
struct format formats[2];
|
||||
uint32_t n_formats[2];
|
||||
|
||||
uint32_t remap[SPA_AUDIO_MAX_CHANNELS];
|
||||
|
||||
bool started;
|
||||
|
||||
convert_func_t convert;
|
||||
|
|
@ -151,6 +154,7 @@ static int setup_convert(struct impl *this)
|
|||
uint32_t src_fmt, dst_fmt;
|
||||
struct format informat, outformat;
|
||||
const struct conv_info *conv;
|
||||
int i, j;
|
||||
|
||||
if (collect_format(this, SPA_DIRECTION_INPUT, &informat) < 0)
|
||||
return -1;
|
||||
|
|
@ -174,6 +178,18 @@ static int setup_convert(struct impl *this)
|
|||
if (informat.format.info.raw.rate != outformat.format.info.raw.rate)
|
||||
return -EINVAL;
|
||||
|
||||
for (i = 0; i < informat.format.info.raw.channels; i++) {
|
||||
for (j = 0; j < outformat.format.info.raw.channels; j++) {
|
||||
if (informat.format.info.raw.position[i] !=
|
||||
outformat.format.info.raw.position[j])
|
||||
continue;
|
||||
this->remap[i] = j;
|
||||
outformat.format.info.raw.position[j] = -1;
|
||||
spa_log_debug(this->log, NAME " %p: channel %d -> %d", this, i, j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* find fast path */
|
||||
conv = find_conv_info(src_fmt, dst_fmt, FEATURE_SSE);
|
||||
if (conv != NULL) {
|
||||
|
|
@ -405,11 +421,13 @@ static int port_enum_formats(struct spa_node *node,
|
|||
|
||||
other = &this->formats[SPA_DIRECTION_REVERSE(direction)].format;
|
||||
|
||||
spa_log_debug(this->log, NAME " %p: enum %d %p", this, other->info.raw.channels, other);
|
||||
switch (*index) {
|
||||
case 0:
|
||||
if (other->info.raw.channels > 0) {
|
||||
*param = spa_pod_builder_object(builder,
|
||||
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
|
||||
spa_pod_builder_push_object(builder,
|
||||
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat);
|
||||
spa_pod_builder_props(builder,
|
||||
SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio),
|
||||
SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
|
||||
SPA_FORMAT_AUDIO_format, &SPA_POD_CHOICE_ENUM_Id(4,
|
||||
|
|
@ -420,6 +438,10 @@ static int port_enum_formats(struct spa_node *node,
|
|||
SPA_FORMAT_AUDIO_rate, &SPA_POD_Int(other->info.raw.rate),
|
||||
SPA_FORMAT_AUDIO_channels, &SPA_POD_Int(other->info.raw.channels),
|
||||
0);
|
||||
spa_pod_builder_prop(builder, SPA_FORMAT_AUDIO_position, 0);
|
||||
spa_pod_builder_array(builder, sizeof(uint32_t), SPA_TYPE_Id,
|
||||
other->info.raw.channels, other->info.raw.position);
|
||||
*param = spa_pod_builder_pop(builder);
|
||||
} else {
|
||||
*param = spa_pod_builder_object(builder,
|
||||
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
|
||||
|
|
@ -454,6 +476,7 @@ static int port_enum_formats(struct spa_node *node,
|
|||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -626,6 +649,11 @@ static int compatible_format(struct spa_audio_info *info, struct spa_audio_info
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int int32_cmp(const void *v1, const void *v2)
|
||||
{
|
||||
return *(int32_t*)v1 - *(int32_t*)v2;
|
||||
}
|
||||
|
||||
static int port_set_format(struct spa_node *node,
|
||||
enum spa_direction direction,
|
||||
uint32_t port_id,
|
||||
|
|
@ -659,6 +687,12 @@ static int port_set_format(struct spa_node *node,
|
|||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
port->have_format = true;
|
||||
port->format = info;
|
||||
|
||||
qsort(info.info.raw.position, info.info.raw.channels, sizeof(uint32_t), int32_cmp);
|
||||
|
||||
port->stride = calc_width(&info);
|
||||
if (this->n_formats[direction] > 0) {
|
||||
if (compatible_format(&info, &this->formats[direction].format) < 0)
|
||||
return -EINVAL;
|
||||
|
|
@ -669,10 +703,6 @@ static int port_set_format(struct spa_node *node,
|
|||
}
|
||||
this->n_formats[direction]++;
|
||||
|
||||
port->have_format = true;
|
||||
port->format = info;
|
||||
|
||||
port->stride = calc_width(&info);
|
||||
|
||||
if (SPA_AUDIO_FORMAT_IS_PLANAR(info.info.raw.format)) {
|
||||
port->blocks = info.info.raw.channels;
|
||||
|
|
@ -1048,7 +1078,12 @@ static int process_split(struct impl *this)
|
|||
n_src_datas, n_dst_datas, n_bytes, inport->offset, size, inport->stride);
|
||||
|
||||
if (n_dst_datas > 0) {
|
||||
this->convert(this, n_dst_datas, dst_datas, n_src_datas, src_datas, n_bytes);
|
||||
void **remap_datas = alloca(sizeof(void*) * n_dst_datas);
|
||||
|
||||
for (i = 0; i < n_dst_datas; i++)
|
||||
remap_datas[i] = dst_datas[this->remap[i]];
|
||||
|
||||
this->convert(this, n_dst_datas, remap_datas, n_src_datas, src_datas, n_bytes);
|
||||
|
||||
inport->offset += n_bytes;
|
||||
if (inport->offset >= size) {
|
||||
|
|
|
|||
|
|
@ -280,8 +280,9 @@ static int port_enum_formats(struct spa_node *node,
|
|||
switch (*index) {
|
||||
case 0:
|
||||
if (other->have_format) {
|
||||
*param = spa_pod_builder_object(builder,
|
||||
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
|
||||
spa_pod_builder_push_object(builder,
|
||||
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat);
|
||||
spa_pod_builder_props(builder,
|
||||
SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio),
|
||||
SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
|
||||
SPA_FORMAT_AUDIO_format, &SPA_POD_Id(SPA_AUDIO_FORMAT_F32P),
|
||||
|
|
@ -289,6 +290,10 @@ static int port_enum_formats(struct spa_node *node,
|
|||
other->format.info.raw.rate, 1, INT32_MAX),
|
||||
SPA_FORMAT_AUDIO_channels, &SPA_POD_Int(other->format.info.raw.channels),
|
||||
0);
|
||||
spa_pod_builder_prop(builder, SPA_FORMAT_AUDIO_position, 0);
|
||||
spa_pod_builder_array(builder, sizeof(uint32_t), SPA_TYPE_Id,
|
||||
other->format.info.raw.channels, other->format.info.raw.position);
|
||||
*param = spa_pod_builder_pop(builder);
|
||||
} else {
|
||||
*param = spa_pod_builder_object(builder,
|
||||
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue