Add tests

This commit is contained in:
Paul Fd 2021-06-25 19:44:04 +02:00
parent 92f741687e
commit c411d0ed61
3 changed files with 57 additions and 0 deletions

View file

@ -528,3 +528,45 @@ TEST_CASE("[Polyphony] Bi-directional choking (with note_polyphony)")
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "kick.wav" } );
}
TEST_CASE("[Polyphony] Choke long release tails")
{
sfz::Synth synth;
sfz::AudioBuffer<float> buffer { 2, static_cast<unsigned>(synth.getSamplesPerBlock()) };
synth.loadSfzString(fs::current_path() / "tests/TestFiles/polyphony.sfz", R"(
<region> sample=*saw ampeg_attack=0.1 ampeg_release=10 polyphony=1
)");
int attackBlocks = static_cast<int>(0.1f / synth.getSamplesPerBlock() * 48000.0f) + 1;
synth.noteOn(0, 60, 63 );
for (int i = 0; i < attackBlocks; ++i)
synth.renderBlock(buffer);
synth.noteOff(10, 60, 63 );
synth.renderBlock(buffer);
REQUIRE( numPlayingVoices(synth) == 0 ); // Released
REQUIRE( numActiveVoices(synth) == 1 );
synth.noteOn(0, 60, 63 );
synth.renderBlock(buffer);
REQUIRE( numPlayingVoices(synth) == 1 ); // Not released, attack phase
REQUIRE( numActiveVoices(synth) == 1 );
}
TEST_CASE("[Polyphony] Choke long release tails with note_polyphony")
{
sfz::Synth synth;
sfz::AudioBuffer<float> buffer { 2, static_cast<unsigned>(synth.getSamplesPerBlock()) };
synth.loadSfzString(fs::current_path() / "tests/TestFiles/polyphony.sfz", R"(
<region> sample=*saw ampeg_attack=0.1 ampeg_release=10 note_polyphony=1
)");
int attackBlocks = static_cast<int>(0.1f / synth.getSamplesPerBlock() * 48000.0f) + 1;
synth.noteOn(0, 60, 63 );
for (int i = 0; i < attackBlocks; ++i)
synth.renderBlock(buffer);
synth.noteOff(10, 60, 63 );
synth.renderBlock(buffer);
REQUIRE( numPlayingVoices(synth) == 0 ); // Released
REQUIRE( numActiveVoices(synth) == 1 );
synth.noteOn(0, 60, 63 );
synth.renderBlock(buffer);
REQUIRE( numPlayingVoices(synth) == 1 ); // Not released, attack phase
REQUIRE( numActiveVoices(synth) == 1 );
}

View file

@ -82,6 +82,13 @@ unsigned numPlayingVoices(const sfz::Synth& synth)
});
}
unsigned numActiveVoices(const sfz::Synth& synth)
{
return absl::c_count_if(getActiveVoices(synth), [](const sfz::Voice* v) {
return !v->offedOrFree();
});
}
const std::vector<std::string> playingSamples(const sfz::Synth& synth)
{
std::vector<std::string> samples;

View file

@ -78,6 +78,14 @@ const std::vector<const sfz::Voice*> getPlayingVoices(const sfz::Synth& synth);
*/
unsigned numPlayingVoices(const sfz::Synth& synth);
/**
* @brief Count the number of active (not free or offed) voices from the synth
*
* @param synth
* @return unsigned
*/
unsigned numActiveVoices(const sfz::Synth& synth);
/**
* @brief Get the playing samples
*