Add sample quality tests

This commit is contained in:
Jean Pierre Cimalando 2020-06-13 22:58:57 +02:00
parent 90d556a985
commit b144ec0cb8
3 changed files with 68 additions and 2 deletions

View file

@ -122,6 +122,12 @@ void sfz::Voice::startVoice(Region* region, int delay, int number, float value,
egEnvelope.reset(region->amplitudeEG, *region, resources.midiState, delay, value, sampleRate);
}
int sfz::Voice::getCurrentSampleQuality() const noexcept
{
return (region && region->sampleQuality) ?
*region->sampleQuality : resources.synthConfig.currentSampleQuality();
}
bool sfz::Voice::isFree() const noexcept
{
return (state == State::idle);
@ -511,8 +517,7 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
}
}
const int quality = region->sampleQuality ?
*region->sampleQuality : resources.synthConfig.currentSampleQuality();
const int quality = getCurrentSampleQuality();
switch (quality) {
default:

View file

@ -107,6 +107,13 @@ public:
*/
void startVoice(Region* region, int delay, int number, float value, TriggerType triggerType) noexcept;
/**
* @brief Get the sample quality determined by the active region.
*
* @return int
*/
int getCurrentSampleQuality() const noexcept;
/**
* @brief Register a note-off event; this may trigger a release.
*

View file

@ -486,3 +486,57 @@ TEST_CASE("[Synth] Region by identifier")
REQUIRE(nullptr == synth.getRegionById(NumericId<sfz::Region>{6}));
REQUIRE(nullptr == synth.getRegionById(NumericId<sfz::Region>{}));
}
TEST_CASE("[Synth] sample quality")
{
sfz::Synth synth;
synth.loadSfzString("tests/TestFiles/sampleQuality.sfz", R"(
<region> sample=kick.wav key=60
<region> sample=kick.wav key=61 sample_quality=5
)");
// default sample quality
synth.noteOn(0, 60, 100);
REQUIRE(synth.getNumActiveVoices() == 1);
REQUIRE(synth.getVoiceView(0)->getCurrentSampleQuality() == sfz::Default::sampleQuality);
synth.allSoundOff();
// default sample quality, freewheeling
synth.enableFreeWheeling();
synth.noteOn(0, 60, 100);
REQUIRE(synth.getNumActiveVoices() == 1);
REQUIRE(synth.getVoiceView(0)->getCurrentSampleQuality() == sfz::Default::sampleQualityInFreewheelingMode);
synth.allSoundOff();
synth.disableFreeWheeling();
// user-defined sample quality
synth.setSampleQuality(sfz::Synth::ProcessLive, 3);
synth.noteOn(0, 60, 100);
REQUIRE(synth.getNumActiveVoices() == 1);
REQUIRE(synth.getVoiceView(0)->getCurrentSampleQuality() == 3);
synth.allSoundOff();
// user-defined sample quality, freewheeling
synth.enableFreeWheeling();
synth.setSampleQuality(sfz::Synth::ProcessFreewheeling, 8);
synth.noteOn(0, 60, 100);
REQUIRE(synth.getNumActiveVoices() == 1);
REQUIRE(synth.getVoiceView(0)->getCurrentSampleQuality() == 8);
synth.allSoundOff();
synth.disableFreeWheeling();
// region sample quality
synth.noteOn(0, 61, 100);
REQUIRE(synth.getNumActiveVoices() == 1);
REQUIRE(synth.getVoiceView(0)->getCurrentSampleQuality() == 5);
synth.allSoundOff();
// region sample quality, freewheeling
synth.enableFreeWheeling();
synth.noteOn(0, 61, 100);
REQUIRE(synth.getNumActiveVoices() == 1);
REQUIRE(synth.getVoiceView(0)->getCurrentSampleQuality() == 5);
synth.allSoundOff();
synth.disableFreeWheeling();
}