Skip to content

Commit f086d74

Browse files
committed
Add a SimpleLFO Boudned test
1 parent cb20541 commit f086d74

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/modulator_tests.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include "catch2.hpp"
2828
#include "sst/basic-blocks/simd/setup.h"
2929
#include "sst/basic-blocks/modulators/FXModControl.h"
30+
#include "sst/basic-blocks/modulators/SimpleLFO.h"
31+
32+
#include <iostream>
3033

3134
namespace smod = sst::basic_blocks::modulators;
3235

@@ -53,4 +56,47 @@ TEST_CASE("Mod LFO Is Well Behaved", "[mod]")
5356
}
5457
}
5558
}
59+
}
60+
61+
static constexpr int bs{8};
62+
static constexpr double tbs{1.0 / bs};
63+
64+
struct SRProvider
65+
{
66+
static constexpr double sampleRate{48000};
67+
static constexpr double samplerate{48000};
68+
static constexpr double sampleRateInv{1.0 / sampleRate};
69+
float envelope_rate_linear_nowrap(float f) const { return tbs * sampleRateInv * pow(2.f, -f); }
70+
};
71+
72+
TEST_CASE("SimpleLFO is Bounded")
73+
{
74+
SRProvider sr;
75+
using slfo_t = sst::basic_blocks::modulators::SimpleLFO<SRProvider, bs>;
76+
77+
sst::basic_blocks::dsp::RNG urng;
78+
for (auto s = (int)slfo_t::SINE; s <= (int)slfo_t::RANDOM_TRIGGER; ++s)
79+
{
80+
DYNAMIC_SECTION("Test shape " << s)
81+
{
82+
for (auto tries = 0; tries < 500; ++tries)
83+
{
84+
urng.reseed(urng.unifU32());
85+
auto def = urng.unifPM1() * 0.95;
86+
auto rt = urng.unif01() * 6 - 2;
87+
88+
auto lfo = slfo_t(&sr, urng);
89+
lfo.attack((slfo_t::Shape)s);
90+
for (int i = 0; i < 500; ++i)
91+
{
92+
lfo.process_block(rt, def, (slfo_t::Shape)s);
93+
for (int j = 0; j < bs; ++j)
94+
{
95+
REQUIRE(lfo.outputBlock[j] - 1.0 <= 1e-5);
96+
REQUIRE(lfo.outputBlock[j] + 1.0 >= -1e-5);
97+
}
98+
}
99+
}
100+
}
101+
}
56102
}

0 commit comments

Comments
 (0)