diff --git a/tests/SynthT.cpp b/tests/SynthT.cpp index 4411d12b..e0f754ba 100644 --- a/tests/SynthT.cpp +++ b/tests/SynthT.cpp @@ -332,3 +332,45 @@ TEST_CASE("[Synth] Gain to mix") REQUIRE( bus->gainToMain() == 0 ); REQUIRE( bus->gainToMix() == 0.5 ); } + +TEST_CASE("[Synth] group polyphony limits") +{ + sfz::Synth synth; + synth.loadSfzFile(fs::current_path() / "tests/TestFiles/polyphony.sfz"); + synth.noteOn(0, 65, 64); + synth.noteOn(0, 65, 64); + synth.noteOn(0, 65, 64); + REQUIRE(synth.getNumActiveVoices() == 2); // group polyphony should block the last note +} + +TEST_CASE("[Synth] Self-masking") +{ + sfz::Synth synth; + synth.loadSfzFile(fs::current_path() / "tests/TestFiles/polyphony.sfz"); + synth.noteOn(0, 64, 63); + synth.noteOn(0, 64, 62); + synth.noteOn(0, 64, 64); + REQUIRE(synth.getNumActiveVoices() == 3); // One of these is releasing + REQUIRE(synth.getVoiceView(0)->getTriggerValue() == 63_norm); + REQUIRE(!synth.getVoiceView(0)->canBeStolen()); + REQUIRE(synth.getVoiceView(1)->getTriggerValue() == 62_norm); + REQUIRE(synth.getVoiceView(1)->canBeStolen()); // The lowest velocity voice is the masking candidate + REQUIRE(synth.getVoiceView(2)->getTriggerValue() == 64_norm); + REQUIRE(!synth.getVoiceView(2)->canBeStolen()); +} + +TEST_CASE("[Synth] Not self-masking") +{ + sfz::Synth synth; + synth.loadSfzFile(fs::current_path() / "tests/TestFiles/polyphony.sfz"); + synth.noteOn(0, 66, 63); + synth.noteOn(0, 66, 62); + synth.noteOn(0, 66, 64); + REQUIRE(synth.getNumActiveVoices() == 3); // One of these is releasing + REQUIRE(synth.getVoiceView(0)->getTriggerValue() == 63_norm); + REQUIRE(synth.getVoiceView(0)->canBeStolen()); // The first encountered voice is the masking candidate + REQUIRE(synth.getVoiceView(1)->getTriggerValue() == 62_norm); + REQUIRE(!synth.getVoiceView(1)->canBeStolen()); + REQUIRE(synth.getVoiceView(2)->getTriggerValue() == 64_norm); + REQUIRE(!synth.getVoiceView(2)->canBeStolen()); +} diff --git a/tests/TestFiles/polyphony.sfz b/tests/TestFiles/polyphony.sfz new file mode 100644 index 00000000..32aed2e9 --- /dev/null +++ b/tests/TestFiles/polyphony.sfz @@ -0,0 +1,5 @@ + sample=*sine key=63 + sample=*sine key=64 note_polyphony=2 + sample=*sine key=66 note_polyphony=2 note_selfmask=off + group=1 polyphony=2 + sample=*sine key=65