mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-05-19 21:37:36 -04:00
channelmix: Convert matrices to float arrays
Convert matrix_orig and matrix to float arrays and use variable size 2d arrays to access the elements of the matrices. This removes the need for storing pointers to matrix rows.
This commit is contained in:
parent
7cfcb46fbf
commit
a7994882b9
6 changed files with 161 additions and 134 deletions
|
|
@ -196,6 +196,7 @@ static bool match_mix(struct channelmix *mix,
|
|||
|
||||
static void impl_channelmix_reconfigure(struct channelmix *mix)
|
||||
{
|
||||
CHANNELMIX_DEF_MATRIX(matrix_orig, mix, matrix_orig);
|
||||
float matrix[MAX_CHANNELS][MAX_CHANNELS] = {{ 0.0f }};
|
||||
uint64_t src_mask = mix->src_mask, src_paired;
|
||||
uint64_t dst_mask = mix->dst_mask, dst_paired;
|
||||
|
|
@ -749,7 +750,7 @@ done:
|
|||
src_mask == 0 ? "UNK" :
|
||||
spa_debug_type_find_short_name(spa_type_audio_channel, j + _SH));
|
||||
|
||||
mix->matrix_orig[ic][jc++] = matrix[i][j];
|
||||
matrix_orig[ic][jc++] = matrix[i][j];
|
||||
sum += fabsf(matrix[i][j]);
|
||||
|
||||
if (matrix[i][j] == 0.0f)
|
||||
|
|
@ -782,13 +783,15 @@ done:
|
|||
spa_log_info(mix->log, "normalize %f", maxsum);
|
||||
for (i = 0; i < dst_chan; i++)
|
||||
for (j = 0; j < src_chan; j++)
|
||||
mix->matrix_orig[i][j] /= maxsum;
|
||||
matrix_orig[i][j] /= maxsum;
|
||||
}
|
||||
}
|
||||
|
||||
static void impl_channelmix_set_volume(struct channelmix *mix, float volume, bool mute,
|
||||
uint32_t n_channel_volumes, float *channel_volumes)
|
||||
{
|
||||
CHANNELMIX_DEF_MATRIX(matrix_orig, mix, matrix_orig);
|
||||
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
|
||||
float volumes[MAX_CHANNELS];
|
||||
float vol = mute ? 0.0f : volume, t;
|
||||
uint32_t i, j;
|
||||
|
|
@ -807,19 +810,19 @@ static void impl_channelmix_set_volume(struct channelmix *mix, float volume, boo
|
|||
if (n_channel_volumes == src_chan) {
|
||||
for (i = 0; i < dst_chan; i++) {
|
||||
for (j = 0; j < src_chan; j++) {
|
||||
mix->matrix[i][j] = mix->matrix_orig[i][j] * volumes[j];
|
||||
matrix[i][j] = matrix_orig[i][j] * volumes[j];
|
||||
}
|
||||
}
|
||||
} else if (n_channel_volumes == dst_chan) {
|
||||
for (i = 0; i < dst_chan; i++) {
|
||||
for (j = 0; j < src_chan; j++) {
|
||||
mix->matrix[i][j] = mix->matrix_orig[i][j] * volumes[i];
|
||||
matrix[i][j] = matrix_orig[i][j] * volumes[i];
|
||||
}
|
||||
}
|
||||
} else if (n_channel_volumes == 0) {
|
||||
for (i = 0; i < dst_chan; i++) {
|
||||
for (j = 0; j < src_chan; j++) {
|
||||
mix->matrix[i][j] = mix->matrix_orig[i][j] * vol;
|
||||
matrix[i][j] = matrix_orig[i][j] * vol;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -831,7 +834,7 @@ static void impl_channelmix_set_volume(struct channelmix *mix, float volume, boo
|
|||
t = 0.0;
|
||||
for (i = 0; i < dst_chan; i++) {
|
||||
for (j = 0; j < src_chan; j++) {
|
||||
float v = mix->matrix[i][j];
|
||||
float v = matrix[i][j];
|
||||
if (i == 0 && j == 0)
|
||||
t = v;
|
||||
else if (t != v)
|
||||
|
|
@ -854,7 +857,7 @@ static void impl_channelmix_set_volume(struct channelmix *mix, float volume, boo
|
|||
for (i = 0; i < dst_chan; i++) {
|
||||
spa_strbuf_init(&sb1, str1, sizeof(str1));
|
||||
for (j = 0; j < src_chan; j++) {
|
||||
float v = mix->matrix[i][j];
|
||||
float v = matrix[i][j];
|
||||
if (i == 0)
|
||||
spa_strbuf_append(&sb2, " %03d ", j);
|
||||
if (v == 0.0f)
|
||||
|
|
@ -899,8 +902,7 @@ int channelmix_init(struct channelmix *mix)
|
|||
{
|
||||
const struct channelmix_info *info;
|
||||
void *d, *b[2];
|
||||
size_t taps_size, buffer_size, alloc_size, dstptr_size, matrow_size, matrix_size, lr4_size;
|
||||
uint32_t i;
|
||||
size_t taps_size, buffer_size, alloc_size, matrix_size, lr4_size;
|
||||
|
||||
if (mix->src_chan > MAX_CHANNELS ||
|
||||
mix->dst_chan > MAX_CHANNELS)
|
||||
|
|
@ -932,12 +934,10 @@ int channelmix_init(struct channelmix *mix)
|
|||
|
||||
taps_size = SPA_ROUND_UP(mix->n_taps * sizeof(float), CHANNELMIX_OPS_MAX_ALIGN);
|
||||
buffer_size = SPA_ROUND_UP(mix->buffer_size*2 * sizeof(float), CHANNELMIX_OPS_MAX_ALIGN);
|
||||
dstptr_size = SPA_ROUND_UP(mix->dst_chan * sizeof(void*), CHANNELMIX_OPS_MAX_ALIGN);
|
||||
matrow_size = SPA_ROUND_UP(mix->src_chan * sizeof(float), CHANNELMIX_OPS_MAX_ALIGN);
|
||||
matrix_size = SPA_ROUND_UP(mix->dst_chan * matrow_size, CHANNELMIX_OPS_MAX_ALIGN);
|
||||
matrix_size = SPA_ROUND_UP(mix->src_chan * mix->dst_chan * sizeof(float), CHANNELMIX_OPS_MAX_ALIGN);
|
||||
lr4_size = SPA_ROUND_UP(mix->dst_chan * sizeof(struct lr4), CHANNELMIX_OPS_MAX_ALIGN);
|
||||
|
||||
alloc_size = taps_size + buffer_size*2 + dstptr_size*2 + lr4_size + matrix_size*2 + CHANNELMIX_OPS_MAX_ALIGN;
|
||||
alloc_size = taps_size + buffer_size*2 + lr4_size + matrix_size*2 + CHANNELMIX_OPS_MAX_ALIGN;
|
||||
d = calloc(1, alloc_size);
|
||||
if (d == NULL)
|
||||
return -errno;
|
||||
|
|
@ -946,18 +946,13 @@ int channelmix_init(struct channelmix *mix)
|
|||
mix->taps = SPA_PTR_ALIGN(d, CHANNELMIX_OPS_MAX_ALIGN, float);
|
||||
mix->buffer[0] = SPA_PTROFF_ALIGN(mix->taps, taps_size, CHANNELMIX_OPS_MAX_ALIGN, float);
|
||||
mix->buffer[1] = SPA_PTROFF_ALIGN(mix->buffer[0], buffer_size, CHANNELMIX_OPS_MAX_ALIGN, float);
|
||||
mix->matrix = SPA_PTROFF_ALIGN(mix->buffer[1], buffer_size, CHANNELMIX_OPS_MAX_ALIGN, float*);
|
||||
mix->matrix_orig = SPA_PTROFF_ALIGN(mix->matrix, dstptr_size, CHANNELMIX_OPS_MAX_ALIGN, float*);
|
||||
mix->lr4 = SPA_PTROFF_ALIGN(mix->matrix_orig, dstptr_size, CHANNELMIX_OPS_MAX_ALIGN, struct lr4);
|
||||
mix->matrix = SPA_PTROFF_ALIGN(mix->buffer[1], buffer_size, CHANNELMIX_OPS_MAX_ALIGN, float);
|
||||
mix->matrix_orig = SPA_PTROFF_ALIGN(mix->matrix, matrix_size, CHANNELMIX_OPS_MAX_ALIGN, float);
|
||||
mix->lr4 = SPA_PTROFF_ALIGN(mix->matrix_orig, matrix_size, CHANNELMIX_OPS_MAX_ALIGN, struct lr4);
|
||||
|
||||
b[0] = SPA_PTROFF_ALIGN(mix->lr4, lr4_size, CHANNELMIX_OPS_MAX_ALIGN, float);
|
||||
b[1] = SPA_PTROFF_ALIGN(b[0], matrix_size, CHANNELMIX_OPS_MAX_ALIGN, float);
|
||||
|
||||
for (i = 0; i < mix->dst_chan; i++) {
|
||||
mix->matrix[i] = SPA_PTROFF_ALIGN(b[0], matrow_size * i, CHANNELMIX_OPS_MAX_ALIGN, float);
|
||||
mix->matrix_orig[i] = SPA_PTROFF_ALIGN(b[1], matrow_size * i, CHANNELMIX_OPS_MAX_ALIGN, float);
|
||||
}
|
||||
|
||||
if (mix->hilbert_taps > 0) {
|
||||
blackman_window(mix->taps, mix->n_taps);
|
||||
hilbert_generate(mix->taps, mix->n_taps);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue