From b144ec0cb8825d3b0e7082af52bfc1ba54c52d60 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Sat, 13 Jun 2020 22:58:57 +0200 Subject: [PATCH] Add sample quality tests --- src/sfizz/Voice.cpp | 9 ++++++-- src/sfizz/Voice.h | 7 ++++++ tests/SynthT.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index f95394d2..768be01b 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -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 buffer) noexcept } } - const int quality = region->sampleQuality ? - *region->sampleQuality : resources.synthConfig.currentSampleQuality(); + const int quality = getCurrentSampleQuality(); switch (quality) { default: diff --git a/src/sfizz/Voice.h b/src/sfizz/Voice.h index 515feb12..0dd5557a 100644 --- a/src/sfizz/Voice.h +++ b/src/sfizz/Voice.h @@ -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. * diff --git a/tests/SynthT.cpp b/tests/SynthT.cpp index 112acb0d..08112bef 100644 --- a/tests/SynthT.cpp +++ b/tests/SynthT.cpp @@ -486,3 +486,57 @@ TEST_CASE("[Synth] Region by identifier") REQUIRE(nullptr == synth.getRegionById(NumericId{6})); REQUIRE(nullptr == synth.getRegionById(NumericId{})); } + +TEST_CASE("[Synth] sample quality") +{ + sfz::Synth synth; + + synth.loadSfzString("tests/TestFiles/sampleQuality.sfz", R"( + sample=kick.wav key=60 + 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(); +}