Skip to content

Commit

Permalink
Add sample quality tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcima committed Jun 13, 2020
1 parent 97be028 commit 4dfbf54
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/sfizz/Voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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);
Expand Down Expand Up @@ -506,8 +512,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:
Expand Down
7 changes: 7 additions & 0 deletions src/sfizz/Voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ class Voice {
*/
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.
*
Expand Down
54 changes: 54 additions & 0 deletions tests/SynthT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,57 @@ TEST_CASE("[Synth] velcurve")
REQUIRE( synth.getRegionView(1)->velocityCurve(96_norm) == Approx(0.5f).margin(1e-2) );
REQUIRE( synth.getRegionView(1)->velocityCurve(127_norm) == 0.0_a );
}

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();
}

0 comments on commit 4dfbf54

Please sign in to comment.