mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-16 08:56:45 -05:00
channelmix: add option to NORMALIZE volumes
Normalize the complete matrix with the same coefficient
This commit is contained in:
parent
700a0aa35c
commit
f70d0b19af
2 changed files with 10 additions and 4 deletions
|
|
@ -166,6 +166,7 @@ static int make_matrix(struct channelmix *mix)
|
||||||
float clev = SQRT1_2;
|
float clev = SQRT1_2;
|
||||||
float slev = SQRT1_2;
|
float slev = SQRT1_2;
|
||||||
float llev = 0.5f;
|
float llev = 0.5f;
|
||||||
|
float maxsum = 0.0f;
|
||||||
|
|
||||||
spa_log_debug(mix->log, "src-mask:%08"PRIx64" dst-mask:%08"PRIx64,
|
spa_log_debug(mix->log, "src-mask:%08"PRIx64" dst-mask:%08"PRIx64,
|
||||||
src_mask, dst_mask);
|
src_mask, dst_mask);
|
||||||
|
|
@ -355,7 +356,7 @@ static int make_matrix(struct channelmix *mix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done:
|
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;
|
float sum = 0.0f;
|
||||||
if ((dst_mask & (1UL << (i + 2))) == 0)
|
if ((dst_mask & (1UL << (i + 2))) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -365,11 +366,15 @@ done:
|
||||||
mix->matrix_orig[ic][jc++] = matrix[i][j];
|
mix->matrix_orig[ic][jc++] = matrix[i][j];
|
||||||
sum += fabs(matrix[i][j]);
|
sum += fabs(matrix[i][j]);
|
||||||
}
|
}
|
||||||
if (sum > 1.0f)
|
maxsum = SPA_MAX(maxsum, sum);
|
||||||
for (j = 0; j < jc; j++)
|
|
||||||
mix->matrix_orig[ic][j] /= sum;
|
|
||||||
ic++;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ struct channelmix {
|
||||||
uint64_t dst_mask;
|
uint64_t dst_mask;
|
||||||
uint32_t cpu_flags;
|
uint32_t cpu_flags;
|
||||||
#define CHANNELMIX_OPTION_MIX_LFE (1<<0) /**< mix LFE */
|
#define CHANNELMIX_OPTION_MIX_LFE (1<<0) /**< mix LFE */
|
||||||
|
#define CHANNELMIX_OPTION_NORMALIZE (1<<1) /**< normalize volumes */
|
||||||
uint32_t options;
|
uint32_t options;
|
||||||
|
|
||||||
struct spa_log *log;
|
struct spa_log *log;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue