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:
Jonas Holmberg 2026-05-12 14:47:57 +02:00
parent 7cfcb46fbf
commit a7994882b9
6 changed files with 161 additions and 134 deletions

View file

@ -59,11 +59,12 @@ void
channelmix_copy_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t i, n_dst = mix->dst_chan;
float **d = (float **)dst;
const float **s = (const float **)src;
for (i = 0; i < n_dst; i++)
vol_c(d[i], s[i], mix->matrix[i][i], n_samples);
vol_c(d[i], s[i], matrix[i][i], n_samples);
}
static void lr4_process_c(struct lr4 *lr4, float *dst, const float *src, const float vol, int samples)
@ -139,6 +140,7 @@ void
channelmix_f32_n_m_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t i, j, n_dst = mix->dst_chan, n_src = mix->src_chan;
float **d = (float **) dst;
const float **s = (const float **) src;
@ -162,9 +164,9 @@ channelmix_f32_n_m_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
uint32_t n_j = 0;
for (j = 0; j < n_src; j++) {
if (mix->matrix[i][j] == 0.0f)
if (matrix[i][j] == 0.0f)
continue;
mj[n_j] = mix->matrix[i][j];
mj[n_j] = matrix[i][j];
sj[n_j++] = s[j];
}
if (n_j == 0) {
@ -186,10 +188,11 @@ void
channelmix_f32_1_2_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
float **d = (float **)dst;
const float **s = (const float **)src;
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[1][0];
const float v0 = matrix[0][0];
const float v1 = matrix[1][0];
vol_c(d[0], s[0], v0, n_samples);
vol_c(d[1], s[0], v1, n_samples);
@ -199,11 +202,12 @@ void
channelmix_f32_2_1_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t n;
float **d = (float **)dst;
const float **s = (const float **)src;
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[0][1];
const float v0 = matrix[0][0];
const float v1 = matrix[0][1];
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
clear_c(d[0], n_samples);
@ -221,13 +225,14 @@ void
channelmix_f32_4_1_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t n;
float **d = (float **)dst;
const float **s = (const float **)src;
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[0][1];
const float v2 = mix->matrix[0][2];
const float v3 = mix->matrix[0][3];
const float v0 = matrix[0][0];
const float v1 = matrix[0][1];
const float v2 = matrix[0][2];
const float v3 = matrix[0][3];
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
clear_c(d[0], n_samples);
@ -249,13 +254,14 @@ void
channelmix_f32_2_4_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t i, n_dst = mix->dst_chan;
float **d = (float **)dst;
const float **s = (const float **)src;
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[1][1];
const float v2 = mix->matrix[2][0];
const float v3 = mix->matrix[3][1];
const float v0 = matrix[0][0];
const float v1 = matrix[1][1];
const float v2 = matrix[2][0];
const float v3 = matrix[3][1];
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
@ -283,13 +289,14 @@ void
channelmix_f32_2_3p1_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t i, n, n_dst = mix->dst_chan;
float **d = (float **)dst;
const float **s = (const float **)src;
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[1][1];
const float v2 = (mix->matrix[2][0] + mix->matrix[2][1]) * 0.5f;
const float v3 = (mix->matrix[3][0] + mix->matrix[3][1]) * 0.5f;
const float v0 = matrix[0][0];
const float v1 = matrix[1][1];
const float v2 = (matrix[2][0] + matrix[2][1]) * 0.5f;
const float v3 = (matrix[3][0] + matrix[3][1]) * 0.5f;
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
@ -319,11 +326,12 @@ void
channelmix_f32_2_5p1_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t i, n_dst = mix->dst_chan;
float **d = (float **)dst;
const float **s = (const float **)src;
const float v4 = mix->matrix[4][0];
const float v5 = mix->matrix[5][1];
const float v4 = matrix[4][0];
const float v5 = matrix[5][1];
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
@ -350,13 +358,14 @@ void
channelmix_f32_2_7p1_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t i, n_dst = mix->dst_chan;
float **d = (float **)dst;
const float **s = (const float **)src;
const float v4 = mix->matrix[4][0];
const float v5 = mix->matrix[5][1];
const float v6 = mix->matrix[6][0];
const float v7 = mix->matrix[7][1];
const float v4 = matrix[4][0];
const float v5 = matrix[5][1];
const float v6 = matrix[6][0];
const float v7 = matrix[7][1];
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
@ -387,13 +396,14 @@ void
channelmix_f32_3p1_2_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t n;
float **d = (float **) dst;
const float **s = (const float **) src;
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[1][1];
const float clev = (mix->matrix[0][2] + mix->matrix[1][2]) * 0.5f;
const float llev = (mix->matrix[0][3] + mix->matrix[1][3]) * 0.5f;
const float v0 = matrix[0][0];
const float v1 = matrix[1][1];
const float clev = (matrix[0][2] + matrix[1][2]) * 0.5f;
const float llev = (matrix[0][3] + matrix[1][3]) * 0.5f;
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
clear_c(d[0], n_samples);
@ -413,15 +423,16 @@ void
channelmix_f32_5p1_2_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t n;
float **d = (float **) dst;
const float **s = (const float **) src;
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[1][1];
const float clev = (mix->matrix[0][2] + mix->matrix[1][2]) * 0.5f;
const float llev = (mix->matrix[0][3] + mix->matrix[1][3]) * 0.5f;
const float slev0 = mix->matrix[0][4];
const float slev1 = mix->matrix[1][5];
const float v0 = matrix[0][0];
const float v1 = matrix[1][1];
const float clev = (matrix[0][2] + matrix[1][2]) * 0.5f;
const float llev = (matrix[0][3] + matrix[1][3]) * 0.5f;
const float slev0 = matrix[0][4];
const float slev1 = matrix[1][5];
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
clear_c(d[0], n_samples);
@ -441,15 +452,16 @@ void
channelmix_f32_5p1_3p1_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t i, n, n_dst = mix->dst_chan;
float **d = (float **) dst;
const float **s = (const float **) src;
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[1][1];
const float v2 = mix->matrix[2][2];
const float v3 = mix->matrix[3][3];
const float v4 = mix->matrix[0][4];
const float v5 = mix->matrix[1][5];
const float v0 = matrix[0][0];
const float v1 = matrix[1][1];
const float v2 = matrix[2][2];
const float v3 = matrix[3][3];
const float v4 = matrix[0][4];
const float v5 = matrix[1][5];
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
@ -470,11 +482,12 @@ void
channelmix_f32_5p1_4_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t i, n_dst = mix->dst_chan;
float **d = (float **) dst;
const float **s = (const float **) src;
const float v4 = mix->matrix[2][4];
const float v5 = mix->matrix[3][5];
const float v4 = matrix[2][4];
const float v5 = matrix[3][5];
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
@ -495,17 +508,18 @@ void
channelmix_f32_7p1_2_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t n;
float **d = (float **) dst;
const float **s = (const float **) src;
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[1][1];
const float clev = (mix->matrix[0][2] + mix->matrix[1][2]) * 0.5f;
const float llev = (mix->matrix[0][3] + mix->matrix[1][3]) * 0.5f;
const float slev0 = mix->matrix[0][4];
const float slev1 = mix->matrix[1][5];
const float rlev0 = mix->matrix[0][6];
const float rlev1 = mix->matrix[1][7];
const float v0 = matrix[0][0];
const float v1 = matrix[1][1];
const float clev = (matrix[0][2] + matrix[1][2]) * 0.5f;
const float llev = (matrix[0][3] + matrix[1][3]) * 0.5f;
const float slev0 = matrix[0][4];
const float slev1 = matrix[1][5];
const float rlev0 = matrix[0][6];
const float rlev1 = matrix[1][7];
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
clear_c(d[0], n_samples);
@ -525,15 +539,16 @@ void
channelmix_f32_7p1_3p1_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t i, n, n_dst = mix->dst_chan;
float **d = (float **) dst;
const float **s = (const float **) src;
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[1][1];
const float v2 = mix->matrix[2][2];
const float v3 = mix->matrix[3][3];
const float v4 = (mix->matrix[0][4] + mix->matrix[0][6]) * 0.5f;
const float v5 = (mix->matrix[1][5] + mix->matrix[1][7]) * 0.5f;
const float v0 = matrix[0][0];
const float v1 = matrix[1][1];
const float v2 = matrix[2][2];
const float v3 = matrix[3][3];
const float v4 = (matrix[0][4] + matrix[0][6]) * 0.5f;
const float v5 = (matrix[1][5] + matrix[1][7]) * 0.5f;
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)
@ -554,17 +569,18 @@ void
channelmix_f32_7p1_4_c(struct channelmix *mix, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples)
{
CHANNELMIX_DEF_MATRIX(matrix, mix, matrix);
uint32_t i, n, n_dst = mix->dst_chan;
float **d = (float **) dst;
const float **s = (const float **) src;
const float v0 = mix->matrix[0][0];
const float v1 = mix->matrix[1][1];
const float clev = (mix->matrix[0][2] + mix->matrix[1][2]) * 0.5f;
const float llev = (mix->matrix[0][3] + mix->matrix[1][3]) * 0.5f;
const float slev0 = mix->matrix[2][4];
const float slev1 = mix->matrix[3][5];
const float rlev0 = mix->matrix[2][6];
const float rlev1 = mix->matrix[3][7];
const float v0 = matrix[0][0];
const float v1 = matrix[1][1];
const float clev = (matrix[0][2] + matrix[1][2]) * 0.5f;
const float llev = (matrix[0][3] + matrix[1][3]) * 0.5f;
const float slev0 = matrix[2][4];
const float slev1 = matrix[3][5];
const float rlev0 = matrix[2][6];
const float rlev1 = matrix[3][7];
if (SPA_FLAG_IS_SET(mix->flags, CHANNELMIX_FLAG_ZERO)) {
for (i = 0; i < n_dst; i++)