Corrected a bug in the release logic

The correct check was that the remaining delay is strictly more than 0, and added a max for good measure.
This commit is contained in:
Paul Ferrand 2019-12-22 10:45:25 +01:00
parent ca7c4f2939
commit d6c49ef827
3 changed files with 18 additions and 2 deletions

View file

@ -135,7 +135,7 @@ void sfz::Voice::release(int delay, bool fastRelease) noexcept
if (state != State::playing)
return;
if (egEnvelope.getRemainingDelay() >= (delay - initialDelay)) {
if (egEnvelope.getRemainingDelay() > std::max(0, delay - initialDelay)) {
reset();
} else {
state = State::release;

View file

@ -220,3 +220,19 @@ TEST_CASE("[Synth] Releasing before the EG started smoothing (initial delay) kil
synth.noteOff(1000, 1, 60, 63);
REQUIRE( !synth.getVoiceView(0)->isFree() );
}
TEST_CASE("[Synth] Releasing after the initial and normal mode does not trigger a fast release")
{
sfz::Synth synth;
synth.setSamplesPerBlock(1024);
sfz::AudioBuffer<float> buffer(2, 1024);
synth.setNumVoices(1);
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/delay_release.sfz");
synth.noteOn(200, 1, 60, 63);
REQUIRE( !synth.getVoiceView(0)->isFree() );
synth.renderBlock(buffer);
REQUIRE( !synth.getVoiceView(0)->isFree() );
synth.noteOff(0, 1, 60, 63);
synth.renderBlock(buffer);
REQUIRE( !synth.getVoiceView(0)->isFree() );
}

View file

@ -1 +1 @@
<region> delay=0.005 sample=dummy1.wav
<region> ampeg_delay=0.005 ampeg_release=1 sample=dummy1.wav