From b65dd18224be2236271de78c48c4971c1a3d7767 Mon Sep 17 00:00:00 2001 From: nmzik Date: Fri, 30 Oct 2026 01:27:00 +0100 Subject: [PATCH] ngs2: let CLEAR reopen a closed waveform block list Co-authored-by: Phr3d13 --- src/libs/ngs2.cpp | 3 ++- tests/Ngs2SamplerTests.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libs/ngs2.cpp b/src/libs/ngs2.cpp index eb09457d7..efa26fe1e 100644 --- a/src/libs/ngs2.cpp +++ b/src/libs/ngs2.cpp @@ -713,10 +713,11 @@ struct Ngs2VoiceInternal { if (count > capacity) { return NGS2_ERROR_INVALID_NUM_WAVEFORM_BLOCKS; } - EXIT_NOT_IMPLEMENTED(!accepts_blocks || (flags & ~0x17u) != 0); const bool clear = (flags & 4u) != 0; const bool only_data = (flags & 2u) != 0; const bool join = only_data && (flags & 0x10u) == 0; + // CLEAR reopens a list that the previous addition closed. + EXIT_NOT_IMPLEMENTED((!accepts_blocks && !clear) || (flags & ~0x17u) != 0); const auto retained = clear ? 0 : blocks.size(); Block tail = retained == 0 ? Block {} : blocks.back(); std::vector pending; diff --git a/tests/Ngs2SamplerTests.cpp b/tests/Ngs2SamplerTests.cpp index de0dec4ff..8c86034f2 100644 --- a/tests/Ngs2SamplerTests.cpp +++ b/tests/Ngs2SamplerTests.cpp @@ -1210,6 +1210,15 @@ void TestDeferredSamplerSetup() { "sampler did not play after deferred stream setup"); } +void TestClearReopensClosedList() { + Fixture f(48000); + const int16_t first = 8192, second = -16384; + f.Queue(&first, 1, 0); + f.Queue(&second, 1, 4); + f.Render(1); + Check(f.voice.samples[0] == -0.5f, "CLEAR did not reopen a closed waveform list"); +} + void TestSetupQuery() { Fixture f(48000, 2); uint32_t info[2] = {99, 99}; @@ -1965,6 +1974,7 @@ int main() { TestDefaultMatrix(); TestMatrixOutputChannels(); TestCustomPcmStillPlays(); + TestClearReopensClosedList(); TestSetupQuery(); TestPortInfo(); TestPlayStateBeforeRender();