Add tests
This commit is contained in:
parent
92f741687e
commit
c411d0ed61
3 changed files with 57 additions and 0 deletions
|
|
@ -528,3 +528,45 @@ TEST_CASE("[Polyphony] Bi-directional choking (with note_polyphony)")
|
||||||
synth.renderBlock(buffer);
|
synth.renderBlock(buffer);
|
||||||
REQUIRE( playingSamples(synth) == std::vector<std::string> { "kick.wav" } );
|
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 );
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
const std::vector<std::string> playingSamples(const sfz::Synth& synth)
|
||||||
{
|
{
|
||||||
std::vector<std::string> samples;
|
std::vector<std::string> samples;
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,14 @@ const std::vector<const sfz::Voice*> getPlayingVoices(const sfz::Synth& synth);
|
||||||
*/
|
*/
|
||||||
unsigned numPlayingVoices(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
|
* @brief Get the playing samples
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue