channelmix: normalize volumes

Normalize the volumes.
Don't mix in LFE by default but add an option
Move some booleans to flags
Improve some checks for fastpaths.
This commit is contained in:
Wim Taymans 2020-09-03 13:20:36 +02:00
parent 289a8e86ca
commit f7d8fef070
5 changed files with 89 additions and 81 deletions

View file

@ -32,11 +32,11 @@ channelmix_copy_c(struct channelmix *mix, uint32_t n_dst, void * SPA_RESTRICT ds
float **d = (float **)dst;
const float **s = (const float **)src;
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
memset(d[i], 0, n_samples * sizeof(float));
}
else if (mix->identity) {
else if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_IDENTITY)) {
for (i = 0; i < n_dst; i++)
spa_memcpy(d[i], s[i], n_samples * sizeof(float));
}
@ -81,19 +81,18 @@ channelmix_f32_1_2_c(struct channelmix *mix, uint32_t n_dst, void * SPA_RESTRICT
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[1][0];
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
memset(d[0], 0, n_samples * sizeof(float));
memset(d[1], 0, n_samples * sizeof(float));
}
else if (mix->norm) {
for (n = 0; n < n_samples; n++)
d[0][n] = d[1][n] = s[0][n];
}
else if (mix->equal) {
for (n = 0; n < n_samples; n++)
d[0][n] = d[1][n] = s[0][n] * v0;
}
else {
} else if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_EQUAL)) {
if (v0 == 1.0f) {
for (n = 0; n < n_samples; n++)
d[0][n] = d[1][n] = s[0][n];
} else {
for (n = 0; n < n_samples; n++)
d[0][n] = d[1][n] = s[0][n] * v0;
}
} else {
for (n = 0; n < n_samples; n++) {
d[0][n] = s[0][n] * v0;
d[1][n] = s[0][n] * v1;
@ -111,10 +110,9 @@ channelmix_f32_2_1_c(struct channelmix *mix, uint32_t n_dst, void * SPA_RESTRICT
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[0][1];
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
memset(d[0], 0, n_samples * sizeof(float));
}
else if (mix->equal) {
} else if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_EQUAL)) {
for (n = 0; n < n_samples; n++)
d[0][n] = (s[0][n] + s[1][n]) * v0;
}
@ -136,10 +134,10 @@ channelmix_f32_4_1_c(struct channelmix *mix, uint32_t n_dst, void * SPA_RESTRICT
const float v2 = mix->matrix[0][2];
const float v3 = mix->matrix[0][3];
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
memset(d[0], 0, n_samples * sizeof(float));
}
else if (mix->equal) {
else if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_EQUAL)) {
for (n = 0; n < n_samples; n++)
d[0][n] = (s[0][n] + s[1][n] + s[2][n] + s[3][n]) * v0;
}
@ -161,10 +159,10 @@ channelmix_f32_3p1_1_c(struct channelmix *mix, uint32_t n_dst, void * SPA_RESTRI
const float v1 = mix->matrix[0][1];
const float v2 = mix->matrix[0][2];
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
memset(d[0], 0, n_samples * sizeof(float));
}
else if (mix->equal) {
else if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_EQUAL)) {
for (n = 0; n < n_samples; n++)
d[0][n] = (s[0][n] + s[1][n] + s[2][n] + s[3][n]) * v0;
}
@ -189,20 +187,21 @@ channelmix_f32_2_4_c(struct channelmix *mix, uint32_t n_dst, void * SPA_RESTRICT
const float v2 = mix->matrix[2][0];
const float v3 = mix->matrix[3][1];
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
memset(d[i], 0, n_samples * sizeof(float));
}
else if (mix->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];
}
}
else if (v0 == v2 && v1 == v3) {
for (n = 0; n < n_samples; n++) {
d[0][n] = d[2][n] = s[0][n] * v0;
d[1][n] = d[3][n] = s[1][n] * v1;
if (v0 == 1.0f && v1 == 1.0f) {
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];
}
} else {
for (n = 0; n < n_samples; n++) {
d[0][n] = d[2][n] = s[0][n] * v0;
d[1][n] = d[3][n] = s[1][n] * v1;
}
}
}
else {
@ -226,11 +225,11 @@ channelmix_f32_2_3p1_c(struct channelmix *mix, uint32_t n_dst, void * SPA_RESTRI
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[1][1];
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
memset(d[i], 0, n_samples * sizeof(float));
}
else if (mix->norm) {
else if (v0 == 1.0f && v1 == 1.0f) {
for (n = 0; n < n_samples; n++) {
d[0][n] = s[0][n];
d[1][n] = s[1][n];
@ -261,11 +260,11 @@ channelmix_f32_2_5p1_c(struct channelmix *mix, uint32_t n_dst, void * SPA_RESTRI
const float v4 = mix->matrix[4][0];
const float v5 = mix->matrix[5][1];
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
memset(d[i], 0, n_samples * sizeof(float));
}
else if (mix->norm) {
else if (v0 == 1.0f && v1 == 1.0f && v4 == 1.0f && v5 == 1.0f) {
for (n = 0; n < n_samples; n++) {
d[0][n] = d[4][n] = s[0][n];
d[1][n] = d[5][n] = s[1][n];
@ -300,7 +299,7 @@ channelmix_f32_5p1_2_c(struct channelmix *mix, uint32_t n_dst, void * SPA_RESTRI
const float slev0 = mix->matrix[0][4];
const float slev1 = mix->matrix[1][5];
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
memset(d[0], 0, n_samples * sizeof(float));
memset(d[1], 0, n_samples * sizeof(float));
}
@ -328,7 +327,7 @@ channelmix_f32_5p1_3p1_c(struct channelmix *mix, uint32_t n_dst, void * SPA_REST
const float v4 = mix->matrix[0][4];
const float v5 = mix->matrix[1][5];
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
memset(d[i], 0, n_samples * sizeof(float));
}
@ -357,7 +356,7 @@ channelmix_f32_5p1_4_c(struct channelmix *mix, uint32_t n_dst, void * SPA_RESTRI
const float v4 = mix->matrix[2][4];
const float v5 = mix->matrix[3][5];
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
memset(d[i], 0, n_samples * sizeof(float));
}
@ -391,7 +390,7 @@ channelmix_f32_7p1_2_c(struct channelmix *mix, uint32_t n_dst, void * SPA_RESTRI
const float rlev0 = mix->matrix[0][6];
const float rlev1 = mix->matrix[1][7];
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
memset(d[0], 0, n_samples * sizeof(float));
memset(d[1], 0, n_samples * sizeof(float));
}
@ -419,7 +418,7 @@ channelmix_f32_7p1_3p1_c(struct channelmix *mix, uint32_t n_dst, void * SPA_REST
const float v4 = (mix->matrix[0][4] + mix->matrix[0][6]) * 0.5f;
const float v5 = (mix->matrix[1][5] + mix->matrix[1][6]) * 0.5f;
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
memset(d[i], 0, n_samples * sizeof(float));
}
@ -450,7 +449,7 @@ channelmix_f32_7p1_4_c(struct channelmix *mix, uint32_t n_dst, void * SPA_RESTRI
const float rlev0 = mix->matrix[0][6];
const float rlev1 = mix->matrix[1][7];
if (mix->zero) {
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
memset(d[i], 0, n_samples * sizeof(float));
}