mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
tests: add unit test for n_m matrix
This commit is contained in:
parent
25cf4d0a31
commit
8a4091f578
1 changed files with 88 additions and 2 deletions
|
|
@ -22,6 +22,8 @@
|
|||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -32,18 +34,22 @@
|
|||
#include <spa/support/log-impl.h>
|
||||
#include <spa/debug/mem.h>
|
||||
|
||||
static uint32_t cpu_flags;
|
||||
|
||||
SPA_LOG_IMPL(logger);
|
||||
|
||||
#define MATRIX(...) (float[]) { __VA_ARGS__ }
|
||||
|
||||
#include "test-helper.h"
|
||||
#include "channelmix-ops.c"
|
||||
|
||||
static void dump_matrix(struct channelmix *mix, float *coeff)
|
||||
{
|
||||
uint32_t i, j;
|
||||
|
||||
for (i = 0; i < mix->dst_chan; i++) {
|
||||
for (j = 0; j < mix->src_chan; j++) {
|
||||
float v = mix->matrix_orig[i][j];
|
||||
float v = mix->matrix[i][j];
|
||||
spa_log_debug(mix->log, "%d %d: %f <-> %f", i, j, v, *coeff);
|
||||
spa_assert_se(fabs(v - *coeff) < 0.000001);
|
||||
coeff++;
|
||||
|
|
@ -65,7 +71,8 @@ static void test_mix(uint32_t src_chan, uint32_t src_mask, uint32_t dst_chan, ui
|
|||
mix.dst_mask = dst_mask;
|
||||
mix.log = &logger.log;
|
||||
|
||||
channelmix_init(&mix);
|
||||
spa_assert(channelmix_init(&mix) == 0);
|
||||
channelmix_set_volume(&mix, 1.0f, false, 0, NULL);
|
||||
dump_matrix(&mix, coeff);
|
||||
}
|
||||
|
||||
|
|
@ -220,10 +227,87 @@ static void test_7p1_N(void)
|
|||
0.0, 1.0, 0.707107, 0.0, 0.0, 0.707107, 0.0, 0.707107));
|
||||
}
|
||||
|
||||
static void run_n_m_impl(struct channelmix *mix, const void **src, uint32_t n_samples)
|
||||
{
|
||||
uint32_t dst_chan = mix->dst_chan, i, j;
|
||||
float dst_c_data[dst_chan][n_samples];
|
||||
float dst_x_data[dst_chan][n_samples];
|
||||
void *dst_c[dst_chan], *dst_x[dst_chan];
|
||||
|
||||
for (i = 0; i < dst_chan; i++) {
|
||||
dst_c[i] = dst_c_data[i];
|
||||
dst_x[i] = dst_x_data[i];
|
||||
}
|
||||
|
||||
channelmix_f32_n_m_c(mix, dst_c, src, n_samples);
|
||||
|
||||
#if defined(HAVE_SSE)
|
||||
if (cpu_flags & SPA_CPU_FLAG_SSE) {
|
||||
channelmix_f32_n_m_sse(mix, dst_x, src, n_samples);
|
||||
for (i = 0; i < mix->dst_chan; i++) {
|
||||
for (j = 0; j < n_samples; j++) {
|
||||
spa_assert(dst_c_data[i][j] == dst_x_data[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_n_m_impl(void)
|
||||
{
|
||||
struct channelmix mix;
|
||||
unsigned int i, j;
|
||||
#define N_SAMPLES 251
|
||||
float src_data[16][N_SAMPLES], *src[16];
|
||||
|
||||
spa_log_debug(&logger.log, "start");
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
for (j = 0; j < N_SAMPLES; j++)
|
||||
src_data[i][j] = (drand48() - 0.5f) * 2.5f;
|
||||
src[i] = src_data[i];
|
||||
}
|
||||
|
||||
spa_zero(mix);
|
||||
mix.src_chan = 16;
|
||||
mix.dst_chan = 12;
|
||||
mix.log = &logger.log;
|
||||
mix.cpu_flags = cpu_flags;
|
||||
spa_assert(channelmix_init(&mix) == 0);
|
||||
channelmix_set_volume(&mix, 1.0f, false, 0, NULL);
|
||||
|
||||
/* identity matrix */
|
||||
run_n_m_impl(&mix, (const void**)src, N_SAMPLES);
|
||||
|
||||
/* some zero destination */
|
||||
mix.matrix_orig[2][2] = 0.0f;
|
||||
mix.matrix_orig[7][7] = 0.0f;
|
||||
channelmix_set_volume(&mix, 1.0f, false, 0, NULL);
|
||||
run_n_m_impl(&mix, (const void**)src, N_SAMPLES);
|
||||
|
||||
/* random matrix */
|
||||
for (i = 0; i < mix.dst_chan; i++) {
|
||||
for (j = 0; j < mix.src_chan; j++) {
|
||||
mix.matrix_orig[i][j] = drand48() - 0.5f;
|
||||
}
|
||||
}
|
||||
channelmix_set_volume(&mix, 1.0f, false, 0, NULL);
|
||||
|
||||
run_n_m_impl(&mix, (const void**)src, N_SAMPLES);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
srand48(SPA_TIMESPEC_TO_NSEC(&ts));
|
||||
|
||||
logger.log.level = SPA_LOG_LEVEL_TRACE;
|
||||
|
||||
cpu_flags = get_cpu_flags();
|
||||
printf("got CPU flags %d\n", cpu_flags);
|
||||
|
||||
test_1_N_MONO();
|
||||
test_1_N_FC();
|
||||
test_N_1();
|
||||
|
|
@ -232,5 +316,7 @@ int main(int argc, char *argv[])
|
|||
test_5p1_N();
|
||||
test_7p1_N();
|
||||
|
||||
test_n_m_impl();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue