Files
dsp/delay/tests/test_mix.cpp
T
2025-11-08 16:22:30 +01:00

121 lines
2.5 KiB
C++

#include "delay/buffer_multi.hpp"
#include "test_common.hpp"
#include <delay/buffer.hpp>
#include <mix.hpp>
#include <cstdio>
#include <iostream>
#include <ostream>
int test_mix_1()
{
std::cout << "----------------------------------------------" << std::endl;
std::cout << "Start test_mix_1::shuffle" << std::endl;
std::cout << "----------------------------------------------" << std::endl;
{
dsp::Buffer<int> r_buf(5);
dsp::Buffer<int> t_buf{105, 106, 107, 108, 109};
t_buf = {105, 106, 107, 108, 109};
dsp::Buffer<int> s_spec = {1, 3, 2, 4, 0};
Shuffle<int>::outOfPlace(t_buf, r_buf, s_spec);
print(r_buf, 5, "r-buf");
}
{
dsp::BufferMulti<int> r_buf(5, 5);
dsp::BufferMulti<int> t_buf{5, 5};
t_buf[0] = {105, 106, 107, 108, 109};
t_buf[1] = {205, 206, 207, 208, 209};
t_buf[2] = {305, 306, 307, 308, 309};
t_buf[3] = {405, 406, 407, 408, 409};
t_buf[4] = {505, 506, 507, 508, 509};
print(t_buf[0], 5, "t-buf 0");
print(t_buf[1], 5, "t-buf 1");
dsp::Buffer<int> s_spec = {-1, 0, -3, 2, -4};
Shuffle<int>::outOfPlace(t_buf, r_buf, s_spec);
print(r_buf[0], 5, "r-buf 0");
print(r_buf[1], 5, "r-buf 1");
print(r_buf[2], 5, "r-buf 2");
print(r_buf[3], 5, "r-buf 3");
print(r_buf[4], 5, "r-buf 4");
}
return 0;
}
int test_mix_2()
{
dsp::BufferMulti<int> r_buf(5, 20);
for (int i=0; i < 20; i++)
{
r_buf = 100 +i ;
++r_buf;
}
r_buf.reset();
for (int c=0; c < r_buf.numChannels(); c++)
{
print(r_buf[c], 20, "r-buf");
std::cout << "----------------------------------------------" << std::endl;
}
for (int c=0; c < r_buf.numChannels(); c++)
{
dsp::Buffer<int> v(r_buf[c], c);
print(v, 20, "v-buf");
std::cout << "----------------------------------------------" << std::endl;
}
return 0;
}
int test_mix_3()
{
const int nCh = 5;
dsp::BufferMulti<double> r_buf(nCh, 10);
for (int i=0; i < r_buf.capacity(); i++)
{
r_buf = (double)i/10 ;
++r_buf;
}
// r_buf.reset();
dsp::Buffer<double> qbuf(r_buf.quer({-2, -10, -4, 3, -3}));
dsp::Buffer<double> sbuf(nCh);
dsp::Buffer<double> s_spec = {-1, 0, -3, 2, -4};
Shuffle<double>::outOfPlace(qbuf, sbuf, s_spec);
double *q = sbuf.raw();
for (int i=0; i < nCh; i++)
{
std::cout << q[i] << " ";
}
std::cout << std::endl;
Hadamard<double, nCh>::inPlace(q);
for (int i=0; i < nCh; i++)
{
std::cout << q[i] << " ";
}
std::cout << std::endl;
Householder<double, nCh>::inPlace(q);
for (int i=0; i < nCh; i++)
{
std::cout << q[i] << " ";
}
std::cout << std::endl;
return 0;
}
int test_mix()
{
test_mix_1();
test_mix_2();
test_mix_3();
return 0;
}