Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes an issue that caused stuck notes and Fixes an issue that caused a crash when using a loop. #1252

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/sfizz/ADSREnvelope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,18 @@ void ADSREnvelope::getBlockInternal(absl::Span<Float> output) noexcept
if (releaseDelay > 0) {
// prevent computing the segment further than release point
size = std::min<size_t>(size, releaseDelay);
} else if (releaseDelay == 0 && delay < 0) {
} else if (releaseDelay == 0 && delay <= 0) {
if (delay < 0) {
// release takes effect this frame
currentState = State::Release;
} else {
// release takes effect the next frame
size = 1;
}
releaseDelay = -1;
} else if (releaseDelay == -1 && currentState < State::Release && delay <= 0) {
// release takes effect this frame
currentState = State::Release;
releaseDelay = -1;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sfizz/Voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ void Voice::Impl::fillWithData(AudioSpan<float> buffer) noexcept
unsigned i = 0;
while (i < numSamples) {
int wrappedIndex = (*indices)[i] - loop.size * blockRestarts;
if (wrappedIndex > loop.end) {
while (wrappedIndex > loop.end) {
wrappedIndex -= loop.size;
blockRestarts += 1;
loop_.restarts += 1;
Expand Down
43 changes: 43 additions & 0 deletions tests/SynthT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2160,3 +2160,46 @@ TEST_CASE("[Synth] Reuse offed voices in the last case scenario for new notes")
REQUIRE( notes == std::vector<int> { i - 1, i } );
}
}

TEST_CASE("[Synth] Note on and off at the maximum delay")
{
sfz::Synth synth;
synth.setSampleRate(12800);
synth.setSamplesPerBlock(128);
sfz::AudioBuffer<float> buffer { 2, static_cast<unsigned>(synth.getSamplesPerBlock()) };
synth.loadSfzString(fs::current_path() / "tests/TestFiles/noteonoff.sfz", R"(
<region> loop_start=4 loop_end=124 ampeg_release=0.5 sample=looped_flute.wav
)");
synth.setNumVoices(128);
synth.noteOn(127, 64, 64);
CHECK(synth.getNumActiveVoices() == 1);
synth.noteOff(127, 64, 0);
CHECK(synth.getNumActiveVoices() == 1);
// Render for a while
for (int i = 0; i < 100; ++i)
synth.renderBlock(buffer);
CHECK(synth.getNumActiveVoices() == 0);
}

TEST_CASE("[Synth] Note on and off with delay")
{
sfz::Synth synth;
synth.setSampleRate(12800);
synth.setSamplesPerBlock(128);
sfz::AudioBuffer<float> buffer { 2, static_cast<unsigned>(synth.getSamplesPerBlock()) };
synth.loadSfzString(fs::current_path() / "tests/TestFiles/noteonoff.sfz", R"(
<region> loop_start=4 loop_end=124 ampeg_release=0.5 sample=looped_flute.wav
)");
synth.setNumVoices(128);

int i;
for (i = 0; i < 127; ++i) {
synth.noteOn(i, i, 64);
synth.noteOff(i+1, i, 0);
}
CHECK(synth.getNumActiveVoices() == 127);
// Render for a while
for (int i = 0; i < 100; ++i)
synth.renderBlock(buffer);
CHECK(synth.getNumActiveVoices() == 0);
}
Loading