Merge pull request #458 from jpcima/flex-eg-transition
FlexEG zero-delay transition
This commit is contained in:
commit
1212dbfbe9
2 changed files with 30 additions and 0 deletions
|
|
@ -144,6 +144,9 @@ void FlexEnvelope::Impl::process(absl::Span<float> out)
|
|||
const bool isReleased = isReleased_;
|
||||
while ((!stageSustained_ && currentTime_ >= stageTime_) ||
|
||||
(stageSustained_ && isReleased)) {
|
||||
// If stage is of zero duration, immediate transition to level
|
||||
if (!stageSustained_ && stageTime_ == 0)
|
||||
currentLevel_ = stageTargetLevel_;
|
||||
if (!advanceToNextStage()) {
|
||||
out.remove_prefix(frameIndex);
|
||||
fill(out, 0.0f);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "sfizz/FlexEnvelope.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include "TestHelpers.h"
|
||||
#include <array>
|
||||
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<float>(output, expected, 0.01f) );
|
||||
}
|
||||
|
||||
TEST_CASE("[FlexEG] Zero delay transitions")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
|
||||
synth.loadSfzString(fs::current_path(), R"(
|
||||
<region> 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<float, 2> 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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue