Files
dsp/tests/test_mix.cpp
T
jens 8cfd39f245 [Reverb]
- num diffusion steps is template param
- Contructor: use initializer list for delays per diffusion step
- added param for feedback delay min and max
2025-11-09 22:32:20 +01:00

158 lines
3.3 KiB
C++

#include "delay/buffer_multi.hpp"
#include "test_common.hpp"
#include <delay/buffer.hpp>
#include <common/mix.hpp>
#include <reverb/reverb.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;
const int numCh = 5;
{
dsp::Buffer<int> r_buf(5);
dsp::Buffer<int> t_buf{105, 106, 107, 108, 109};
t_buf = {105, 106, 107, 108, 109};
int s_spec[numCh] = {1, 3, 2, 4, 0};
int sbuf[numCh];
Shuffle<int, numCh>::outOfPlace(t_buf.raw(), sbuf, s_spec);
print(r_buf, 5);
}
{
int sbuf[numCh];
int s_spec[numCh] = {-1, 0, -3, 2, -4};
dsp::BufferMulti<int, 5> r_buf(5);
dsp::BufferMulti<int, 5> t_buf{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);
print(t_buf[1], 5);
for (int i=0; i < numCh; i++)
{
Shuffle<int, numCh>::outOfPlace(t_buf[i].raw(), sbuf, s_spec);
print(r_buf[i], 5);
}
}
return 0;
}
int test_mix_2()
{
dsp::BufferMulti<int, 5> r_buf(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);
std::cout << "----------------------------------------------" << std::endl;
}
for (int c=0; c < r_buf.numChannels(); c++)
{
dsp::Buffer<int> v(r_buf[c], c);
print(v, 20);
std::cout << "----------------------------------------------" << std::endl;
}
return 0;
}
int test_mix_3()
{
const int nCh = 5;
dsp::BufferMulti<double, nCh> r_buf(10);
for (int i=0; i < r_buf.capacity(); i++)
{
r_buf = (double)i/10 ;
++r_buf;
}
// r_buf.reset();
double sbuf[nCh];
double qbuf[nCh];
int delays[nCh] = {-2, -10, -4, 3, -3};
r_buf.quer(qbuf, delays);
int s_spec[nCh] = {-1, 0, -3, 2, -4};
Shuffle<double, nCh>::outOfPlace(qbuf, sbuf, s_spec);
for (int i=0; i < nCh; i++)
{
std::cout << sbuf[i] << " ";
}
std::cout << std::endl;
Hadamard<double, nCh>::inPlace(sbuf);
for (int i=0; i < nCh; i++)
{
std::cout << sbuf[i] << " ";
}
std::cout << std::endl;
Householder<double, nCh>::inPlace(sbuf);
for (int i=0; i < nCh; i++)
{
std::cout << sbuf[i] << " ";
}
std::cout << std::endl;
return 0;
}
void test_diffusor()
{
std::cout << "----------------------------------------------" << std::endl;
std::cout << "test_diffusor()" << std::endl;
Diffusor<double, 8> diff(5);
double data_in[10] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7,0.8, 0.9, 1.0};
double data_out[10] = {0, 0, 0, 0, 0, 0, 0,0, 0, 0};
for (int i=0; i < 10; i++)
{
data_out[i] = diff.process(data_in[i]);
}
print(data_out, 10);
}
void test_reverb()
{
std::cout << "----------------------------------------------" << std::endl;
std::cout << "test_reverb()" << std::endl;
Reverb<double, 8, 3> rev({32}, 1, 2);
float data_in[10] = {1, 2, 3, 4, 5, 6, 7,8, 9, 10};
float data_out[10] = {0, 0, 0, 0, 0, 0, 0,0, 0, 0};
rev.process(data_in, data_out, 10);
print(data_out, 10);
}
int test_mix()
{
test_mix_1();
test_mix_2();
test_mix_3();
test_reverb();
test_diffusor();
return 0;
}