From 6694e8b85e45ff9cdc4a8639990f6e27b1d3d38e Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Mon, 28 Sep 2020 14:43:58 +0200 Subject: [PATCH] Add test --- tests/FlexEGT.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/FlexEGT.cpp b/tests/FlexEGT.cpp index db16f93c..229bee47 100644 --- a/tests/FlexEGT.cpp +++ b/tests/FlexEGT.cpp @@ -9,6 +9,7 @@ #include "sfizz/FlexEnvelope.h" #include "catch2/catch.hpp" #include "TestHelpers.h" +#include using namespace Catch::literals; using namespace sfz::literals; @@ -261,3 +262,29 @@ TEST_CASE("[FlexEG] Detailed numerical envelope test (with shapes)") envelope.process(absl::MakeSpan(output)); REQUIRE( approxEqual(output, expected, 0.01f) ); } + +TEST_CASE("[FlexEG] Zero delay transitions") +{ + sfz::Synth synth; + + synth.loadSfzString(fs::current_path(), R"( + sample=*sine + eg1_time1=0 eg1_level1=1 + eg1_time2=1 eg1_level2=0 + eg1_time3=1 eg1_level3=.5 eg1_sustain=3 + eg1_time4=1 eg1_level4=1 + )"); + sfz::FlexEnvelope envelope; + REQUIRE(synth.getNumRegions() == 1); + REQUIRE(synth.getRegionView(0)->flexEGs.size() == 1); + envelope.configure(&synth.getRegionView(0)->flexEGs[0]); + envelope.setSampleRate(10); + envelope.start(1); + + std::array output; + envelope.process(absl::MakeSpan(output)); + REQUIRE(output[0] == 0.0f); + REQUIRE(output[1] == Approx(0.9f).margin(0.01f)); + // Note(jpc): 0.9 is because EG pre-increments the time counter, slope is + // 1 frame off into the future +}