channelmix: add option to NORMALIZE volumes

Normalize the complete matrix with the same coefficient
This commit is contained in:
Wim Taymans 2020-09-29 12:00:46 +02:00
parent 700a0aa35c
commit f70d0b19af
2 changed files with 10 additions and 4 deletions

View file

@ -166,6 +166,7 @@ static int make_matrix(struct channelmix *mix)
float clev = SQRT1_2;
float slev = SQRT1_2;
float llev = 0.5f;
float maxsum = 0.0f;
spa_log_debug(mix->log, "src-mask:%08"PRIx64" dst-mask:%08"PRIx64,
src_mask, dst_mask);
@ -355,7 +356,7 @@ static int make_matrix(struct channelmix *mix)
}
}
done:
for (ic = 0, i = 0; i < NUM_CHAN; i++) {
for (jc = 0, ic = 0, i = 0; i < NUM_CHAN; i++) {
float sum = 0.0f;
if ((dst_mask & (1UL << (i + 2))) == 0)
continue;
@ -365,11 +366,15 @@ done:
mix->matrix_orig[ic][jc++] = matrix[i][j];
sum += fabs(matrix[i][j]);
}
if (sum > 1.0f)
for (j = 0; j < jc; j++)
mix->matrix_orig[ic][j] /= sum;
maxsum = SPA_MAX(maxsum, sum);
ic++;
}
if (SPA_FLAG_IS_SET(mix->options, CHANNELMIX_OPTION_NORMALIZE) &&
maxsum > 1.0f) {
for (i = 0; i < ic; i++)
for (j = 0; j < jc; j++)
mix->matrix_orig[i][j] /= maxsum;
}
return 0;
}

View file

@ -47,6 +47,7 @@ struct channelmix {
uint64_t dst_mask;
uint32_t cpu_flags;
#define CHANNELMIX_OPTION_MIX_LFE (1<<0) /**< mix LFE */
#define CHANNELMIX_OPTION_NORMALIZE (1<<1) /**< normalize volumes */
uint32_t options;
struct spa_log *log;