Skip to content

Commit

Permalink
Improve AirWindows tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Feb 16, 2024
1 parent af8bae4 commit e908525
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions lib/grit/audio/airwindows/airwindows_test.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
#include <grit/audio/airwindows.hpp>

#include <catch2/catch_approx.hpp>
#include <catch2/catch_get_random_seed.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>

TEMPLATE_TEST_CASE("grit/audio/airwindows: AirWindowsFireAmp", "", float, double)
template<typename Processor>
auto test() -> void
{
using Float = TestType;
using Float = typename Processor::value_type;

auto const sampleRate = GENERATE(Float(44100), Float(48000), Float(88200), Float(96000));

auto proc = grit::AirWindowsFireAmp<Float>{42};
proc.setSampleRate(44100.0F);
REQUIRE(proc(Float(0.125)) != Float(0.0));
REQUIRE(proc(Float(0.111)) != Float(0.0));
REQUIRE(proc(Float(0.113)) != Float(0.0));
auto rng = etl::xoshiro128plusplus{Catch::getSeed()};
auto dist = etl::uniform_real_distribution<Float>{Float(0), Float(1)};
auto proc = Processor{rng()};

if constexpr (requires { proc.setSampleRate(sampleRate); }) {
proc.setSampleRate(sampleRate);
}

SECTION("check for nans")
{
for (auto i{0}; i < 100'000; ++i) {
auto out = proc(dist(rng));
REQUIRE(etl::isfinite(out));
}
}
}

TEMPLATE_TEST_CASE("grit/audio/airwindows: AirWindowsGrindAmp", "", float, double)
TEMPLATE_TEST_CASE("grit/audio/airwindows: AirWindowsFireAmp", "", float, double)
{
using Float = TestType;
test<grit::AirWindowsFireAmp<TestType>>();
}

auto proc = grit::AirWindowsGrindAmp<Float>{42};
proc.setSampleRate(44100.0F);
REQUIRE(proc(Float(0.125)) != Float(0.0));
REQUIRE(proc(Float(0.111)) != Float(0.0));
REQUIRE(proc(Float(0.113)) != Float(0.0));
TEMPLATE_TEST_CASE("grit/audio/airwindows: AirWindowsGrindAmp", "", float, double)
{
test<grit::AirWindowsGrindAmp<TestType>>();
}

TEMPLATE_TEST_CASE("grit/audio/airwindows: AirWindowsVinylDither", "", float, double)
Expand All @@ -35,7 +49,6 @@ TEMPLATE_TEST_CASE("grit/audio/airwindows: AirWindowsVinylDither", "", float, do

proc.setDeRez(Float(0.5));
REQUIRE(proc.getDeRez() == Catch::Approx(Float(0.5)));
REQUIRE(proc(Float(0.125)) != Float(0.0));
REQUIRE(proc(Float(0.111)) != Float(0.0));
REQUIRE(proc(Float(0.113)) != Float(0.0));

test<grit::AirWindowsVinylDither<Float>>();
}

0 comments on commit e908525

Please sign in to comment.