2020-01-25 10:04:31 +01:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
2020-01-25 13:13:07 +01:00
|
|
|
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
|
|
|
|
// license. You should have receive a LICENSE.md file along with the code.
|
|
|
|
|
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
2019-11-30 15:40:13 +01:00
|
|
|
|
2020-01-23 22:17:06 +01:00
|
|
|
#include "sfizz/Synth.h"
|
2020-03-26 00:25:26 +01:00
|
|
|
#include "sfizz/SfzHelpers.h"
|
2019-11-30 15:40:13 +01:00
|
|
|
#include "catch2/catch.hpp"
|
|
|
|
|
using namespace Catch::literals;
|
2020-03-26 00:25:26 +01:00
|
|
|
using namespace sfz::literals;
|
2019-11-30 15:40:13 +01:00
|
|
|
|
|
|
|
|
constexpr int blockSize { 256 };
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Play and check active voices")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
2020-03-06 11:10:56 +01:00
|
|
|
synth.setSamplesPerBlock(blockSize);
|
2019-11-30 15:40:13 +01:00
|
|
|
sfz::AudioBuffer<float> buffer { 2, blockSize };
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/groups_avl.sfz");
|
|
|
|
|
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.noteOn(0, 36, 24);
|
|
|
|
|
synth.noteOn(0, 36, 89);
|
2019-11-30 15:40:13 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2);
|
|
|
|
|
// Render for a while
|
|
|
|
|
for (int i = 0; i < 200; ++i)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-15 23:16:40 +01:00
|
|
|
TEST_CASE("[Synth] All sound off")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/groups_avl.sfz");
|
|
|
|
|
synth.noteOn(0, 36, 24);
|
|
|
|
|
synth.noteOn(0, 36, 89);
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2);
|
|
|
|
|
synth.allSoundOff();
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-30 15:40:13 +01:00
|
|
|
TEST_CASE("[Synth] Change the number of voice while playing")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
2020-03-06 11:10:56 +01:00
|
|
|
synth.setSamplesPerBlock(blockSize);
|
2019-11-30 15:40:13 +01:00
|
|
|
sfz::AudioBuffer<float> buffer { 2, blockSize };
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/groups_avl.sfz");
|
|
|
|
|
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.noteOn(0, 36, 24);
|
|
|
|
|
synth.noteOn(0, 36, 89);
|
2019-11-30 15:40:13 +01:00
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2);
|
|
|
|
|
synth.setNumVoices(8);
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
|
|
|
|
REQUIRE(synth.getNumVoices() == 8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Check that the sample per block and sample rate are actually propagated to all voices even on recreation")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setSamplesPerBlock(256);
|
|
|
|
|
synth.setSampleRate(96000);
|
|
|
|
|
for (int i = 0; i < synth.getNumVoices(); ++i)
|
|
|
|
|
{
|
|
|
|
|
REQUIRE( synth.getVoiceView(i)->getSamplesPerBlock() == 256 );
|
|
|
|
|
REQUIRE( synth.getVoiceView(i)->getSampleRate() == 96000.0f );
|
|
|
|
|
}
|
|
|
|
|
synth.setNumVoices(8);
|
|
|
|
|
for (int i = 0; i < synth.getNumVoices(); ++i)
|
|
|
|
|
{
|
|
|
|
|
REQUIRE( synth.getVoiceView(i)->getSamplesPerBlock() == 256 );
|
|
|
|
|
REQUIRE( synth.getVoiceView(i)->getSampleRate() == 96000.0f );
|
|
|
|
|
}
|
|
|
|
|
synth.setSamplesPerBlock(128);
|
|
|
|
|
synth.setSampleRate(48000);
|
|
|
|
|
for (int i = 0; i < synth.getNumVoices(); ++i)
|
|
|
|
|
{
|
|
|
|
|
REQUIRE( synth.getVoiceView(i)->getSamplesPerBlock() == 128 );
|
|
|
|
|
REQUIRE( synth.getVoiceView(i)->getSampleRate() == 48000.0f );
|
|
|
|
|
}
|
|
|
|
|
synth.setNumVoices(64);
|
|
|
|
|
for (int i = 0; i < synth.getNumVoices(); ++i)
|
|
|
|
|
{
|
|
|
|
|
REQUIRE( synth.getVoiceView(i)->getSamplesPerBlock() == 128 );
|
|
|
|
|
REQUIRE( synth.getVoiceView(i)->getSampleRate() == 48000.0f );
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-02 00:10:21 +01:00
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Check that we can change the size of the preload before and after loading")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setPreloadSize(512);
|
2020-03-05 19:03:08 +01:00
|
|
|
synth.setSamplesPerBlock(blockSize);
|
2019-12-02 00:10:21 +01:00
|
|
|
sfz::AudioBuffer<float> buffer { 2, blockSize };
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/groups_avl.sfz");
|
|
|
|
|
synth.setPreloadSize(1024);
|
|
|
|
|
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.noteOn(0, 36, 24);
|
|
|
|
|
synth.noteOn(0, 36, 89);
|
2019-12-02 00:10:21 +01:00
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
synth.setPreloadSize(2048);
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Check that we can change the oversampling factor before and after loading")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
2019-12-22 23:37:22 +01:00
|
|
|
synth.setOversamplingFactor(sfz::Oversampling::x2);
|
2020-03-05 19:03:08 +01:00
|
|
|
synth.setSamplesPerBlock(blockSize);
|
2019-12-02 00:10:21 +01:00
|
|
|
sfz::AudioBuffer<float> buffer { 2, blockSize };
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/groups_avl.sfz");
|
2019-12-22 23:37:22 +01:00
|
|
|
synth.setOversamplingFactor(sfz::Oversampling::x4);
|
2019-12-02 00:10:21 +01:00
|
|
|
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.noteOn(0, 36, 24);
|
|
|
|
|
synth.noteOn(0, 36, 89);
|
2019-12-02 00:10:21 +01:00
|
|
|
synth.renderBlock(buffer);
|
2019-12-22 23:37:22 +01:00
|
|
|
synth.setOversamplingFactor(sfz::Oversampling::x2);
|
2019-12-02 00:10:21 +01:00
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
}
|
2019-12-17 12:40:25 +01:00
|
|
|
|
|
|
|
|
|
2019-12-23 01:25:20 +01:00
|
|
|
TEST_CASE("[Synth] All notes offs/all sounds off")
|
2019-12-17 23:05:18 +01:00
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setNumVoices(8);
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/sound_off.sfz");
|
|
|
|
|
synth.noteOn(0, 60, 63);
|
|
|
|
|
synth.noteOn(0, 62, 63);
|
2019-12-17 23:05:18 +01:00
|
|
|
REQUIRE( synth.getNumActiveVoices() == 2 );
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.cc(0, 120, 63);
|
2019-12-17 23:05:18 +01:00
|
|
|
REQUIRE( synth.getNumActiveVoices() == 0 );
|
|
|
|
|
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.noteOn(0, 62, 63);
|
|
|
|
|
synth.noteOn(0, 60, 63);
|
2019-12-17 23:05:18 +01:00
|
|
|
REQUIRE( synth.getNumActiveVoices() == 2 );
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.cc(0, 123, 63);
|
2019-12-17 23:05:18 +01:00
|
|
|
REQUIRE( synth.getNumActiveVoices() == 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Reset all controllers")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
2020-04-06 00:29:42 +02:00
|
|
|
const auto& midiState = synth.getResources().midiState;
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.cc(0, 12, 64);
|
2020-04-06 00:29:42 +02:00
|
|
|
REQUIRE(midiState.getCCValue(12) == 64_norm);
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.cc(0, 121, 64);
|
2020-04-06 00:29:42 +02:00
|
|
|
REQUIRE(midiState.getCCValue(12) == 0_norm);
|
2019-12-21 15:32:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Releasing before the EG started smoothing (initial delay) kills the voice")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setSamplesPerBlock(1024);
|
|
|
|
|
synth.setNumVoices(1);
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/delay_release.sfz");
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.noteOn(0, 60, 63);
|
2019-12-21 15:32:38 +01:00
|
|
|
REQUIRE( !synth.getVoiceView(0)->isFree() );
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.noteOff(100, 60, 63);
|
2019-12-21 15:32:38 +01:00
|
|
|
REQUIRE( synth.getVoiceView(0)->isFree() );
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.noteOn(200, 60, 63);
|
2019-12-21 15:32:38 +01:00
|
|
|
REQUIRE( !synth.getVoiceView(0)->isFree() );
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.noteOff(1000, 60, 63);
|
2019-12-21 15:32:38 +01:00
|
|
|
REQUIRE( !synth.getVoiceView(0)->isFree() );
|
|
|
|
|
}
|
2019-12-22 10:45:25 +01:00
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Releasing after the initial and normal mode does not trigger a fast release")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setSamplesPerBlock(1024);
|
|
|
|
|
sfz::AudioBuffer<float> buffer(2, 1024);
|
|
|
|
|
synth.setNumVoices(1);
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/delay_release.sfz");
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.noteOn(200, 60, 63);
|
2019-12-22 10:45:25 +01:00
|
|
|
REQUIRE( !synth.getVoiceView(0)->isFree() );
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
REQUIRE( !synth.getVoiceView(0)->isFree() );
|
2019-12-23 01:25:20 +01:00
|
|
|
synth.noteOff(0, 60, 63);
|
2019-12-22 10:45:25 +01:00
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
REQUIRE( !synth.getVoiceView(0)->isFree() );
|
|
|
|
|
}
|
2020-02-17 20:51:41 +01:00
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Trigger=release and an envelope properly kills the voice at the end of the envelope")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
2020-02-18 14:43:51 +01:00
|
|
|
synth.setSampleRate(48000);
|
|
|
|
|
synth.setSamplesPerBlock(480);
|
|
|
|
|
sfz::AudioBuffer<float> buffer(2, 480);
|
2020-02-17 20:51:41 +01:00
|
|
|
synth.setNumVoices(1);
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/envelope_trigger_release.sfz");
|
2020-02-18 14:43:51 +01:00
|
|
|
synth.noteOn(0, 60, 63);
|
|
|
|
|
synth.noteOff(0, 60, 63);
|
2020-02-17 20:51:41 +01:00
|
|
|
REQUIRE( !synth.getVoiceView(0)->isFree() );
|
2020-02-18 14:43:51 +01:00
|
|
|
synth.renderBlock(buffer); // Attack (0.02)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
synth.renderBlock(buffer); // Decay (0.02)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
synth.renderBlock(buffer); // Release (0.1)
|
2020-05-07 00:49:05 +02:00
|
|
|
REQUIRE(synth.getVoiceView(0)->releasedOrFree());
|
2020-02-18 14:43:51 +01:00
|
|
|
// Release is 0.1s
|
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
REQUIRE( synth.getVoiceView(0)->isFree() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Trigger=release_key and an envelope properly kills the voice at the end of the envelope")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setSampleRate(48000);
|
|
|
|
|
synth.setSamplesPerBlock(480);
|
|
|
|
|
sfz::AudioBuffer<float> buffer(2, 480);
|
|
|
|
|
synth.setNumVoices(1);
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/envelope_trigger_release_key.sfz");
|
|
|
|
|
synth.noteOn(0, 60, 63);
|
|
|
|
|
synth.noteOff(0, 60, 63);
|
|
|
|
|
REQUIRE( !synth.getVoiceView(0)->isFree() );
|
|
|
|
|
synth.renderBlock(buffer); // Attack (0.02)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
synth.renderBlock(buffer); // Decay (0.02)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
synth.renderBlock(buffer); // Release (0.1)
|
2020-05-07 00:49:05 +02:00
|
|
|
REQUIRE(synth.getVoiceView(0)->releasedOrFree());
|
2020-04-01 09:57:59 +02:00
|
|
|
// Release is 0.1s
|
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
REQUIRE( synth.getVoiceView(0)->isFree() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] loopmode=one_shot and an envelope properly kills the voice at the end of the envelope")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setSampleRate(48000);
|
|
|
|
|
synth.setSamplesPerBlock(480);
|
|
|
|
|
sfz::AudioBuffer<float> buffer(2, 480);
|
|
|
|
|
synth.setNumVoices(1);
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/envelope_one_shot.sfz");
|
|
|
|
|
synth.noteOn(0, 60, 63);
|
|
|
|
|
synth.noteOff(0, 60, 63);
|
|
|
|
|
REQUIRE( !synth.getVoiceView(0)->isFree() );
|
|
|
|
|
synth.renderBlock(buffer); // Attack (0.02)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
synth.renderBlock(buffer); // Decay (0.02)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
synth.renderBlock(buffer); // Release (0.1)
|
2020-05-07 00:49:05 +02:00
|
|
|
REQUIRE(synth.getVoiceView(0)->releasedOrFree());
|
2020-02-18 14:43:51 +01:00
|
|
|
// Release is 0.1s
|
2020-02-17 20:51:41 +01:00
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
REQUIRE( synth.getVoiceView(0)->isFree() );
|
|
|
|
|
}
|
2020-03-06 11:10:56 +01:00
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Number of effect buses and resetting behavior")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setSamplesPerBlock(blockSize);
|
|
|
|
|
sfz::AudioBuffer<float> buffer { 2, blockSize };
|
|
|
|
|
|
|
|
|
|
REQUIRE( synth.getEffectBusView(0) == nullptr); // No effects at first
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/base.sfz");
|
|
|
|
|
REQUIRE( synth.getEffectBusView(0) != nullptr); // We have a main bus
|
|
|
|
|
// Check that we can render blocks
|
|
|
|
|
for (int i = 0; i < 100; ++i)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/bitcrusher_2.sfz");
|
|
|
|
|
REQUIRE( synth.getEffectBusView(0) != nullptr); // We have a main bus
|
|
|
|
|
REQUIRE( synth.getEffectBusView(1) != nullptr); // and an FX bus
|
|
|
|
|
// Check that we can render blocks
|
|
|
|
|
for (int i = 0; i < 100; ++i)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/base.sfz");
|
|
|
|
|
REQUIRE( synth.getEffectBusView(0) != nullptr); // We have a main bus
|
|
|
|
|
REQUIRE( synth.getEffectBusView(1) == nullptr); // and no FX bus
|
|
|
|
|
// Check that we can render blocks
|
|
|
|
|
for (int i = 0; i < 100; ++i)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/bitcrusher_3.sfz");
|
|
|
|
|
REQUIRE( synth.getEffectBusView(0) != nullptr); // We have a main bus
|
|
|
|
|
REQUIRE( synth.getEffectBusView(1) == nullptr); // empty/uninitialized fx bus
|
|
|
|
|
REQUIRE( synth.getEffectBusView(2) == nullptr); // empty/uninitialized fx bus
|
|
|
|
|
REQUIRE( synth.getEffectBusView(3) != nullptr); // and an FX bus (because we built up to fx3)
|
|
|
|
|
REQUIRE( synth.getEffectBusView(3)->numEffects() == 1);
|
|
|
|
|
// Check that we can render blocks
|
|
|
|
|
for (int i = 0; i < 100; ++i)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] No effect in the main bus")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/base.sfz");
|
|
|
|
|
auto bus = synth.getEffectBusView(0);
|
|
|
|
|
REQUIRE( bus != nullptr); // We have a main bus
|
|
|
|
|
REQUIRE( bus->numEffects() == 0 );
|
|
|
|
|
REQUIRE( bus->gainToMain() == 1 );
|
|
|
|
|
REQUIRE( bus->gainToMix() == 0 );
|
|
|
|
|
}
|
2020-03-07 21:27:19 +01:00
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] One effect")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/bitcrusher_1.sfz");
|
|
|
|
|
auto bus = synth.getEffectBusView(0);
|
|
|
|
|
REQUIRE( bus != nullptr); // We have a main bus
|
|
|
|
|
REQUIRE( bus->numEffects() == 1 );
|
|
|
|
|
REQUIRE( bus->gainToMain() == 1 );
|
|
|
|
|
REQUIRE( bus->gainToMix() == 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Effect on a second bus")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/bitcrusher_2.sfz");
|
|
|
|
|
auto bus = synth.getEffectBusView(0);
|
|
|
|
|
REQUIRE( bus != nullptr); // We have a main bus
|
|
|
|
|
REQUIRE( bus->numEffects() == 0 );
|
|
|
|
|
REQUIRE( bus->gainToMain() == 0.5 );
|
|
|
|
|
REQUIRE( bus->gainToMix() == 0 );
|
|
|
|
|
bus = synth.getEffectBusView(1);
|
|
|
|
|
REQUIRE( bus != nullptr);
|
|
|
|
|
REQUIRE( bus->numEffects() == 1 );
|
|
|
|
|
REQUIRE( bus->gainToMain() == 0.5 );
|
|
|
|
|
REQUIRE( bus->gainToMix() == 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Effect on a third bus")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/bitcrusher_3.sfz");
|
|
|
|
|
auto bus = synth.getEffectBusView(0);
|
|
|
|
|
REQUIRE( bus != nullptr); // We have a main bus
|
|
|
|
|
REQUIRE( bus->numEffects() == 0 );
|
|
|
|
|
REQUIRE( bus->gainToMain() == 0.5 );
|
|
|
|
|
REQUIRE( bus->gainToMix() == 0 );
|
|
|
|
|
bus = synth.getEffectBusView(3);
|
|
|
|
|
REQUIRE( bus != nullptr);
|
|
|
|
|
REQUIRE( bus->numEffects() == 1 );
|
|
|
|
|
REQUIRE( bus->gainToMain() == 0.5 );
|
|
|
|
|
REQUIRE( bus->gainToMix() == 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Gain to mix")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/to_mix.sfz");
|
|
|
|
|
auto bus = synth.getEffectBusView(0);
|
|
|
|
|
REQUIRE( bus != nullptr); // We have a main bus
|
|
|
|
|
REQUIRE( bus->numEffects() == 0 );
|
|
|
|
|
REQUIRE( bus->gainToMain() == 1 );
|
|
|
|
|
REQUIRE( bus->gainToMix() == 0 );
|
|
|
|
|
bus = synth.getEffectBusView(1);
|
|
|
|
|
REQUIRE( bus != nullptr);
|
|
|
|
|
REQUIRE( bus->numEffects() == 1 );
|
|
|
|
|
REQUIRE( bus->gainToMain() == 0 );
|
|
|
|
|
REQUIRE( bus->gainToMix() == 0.5 );
|
|
|
|
|
}
|
2020-03-29 12:52:34 +02:00
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] group polyphony limits")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/polyphony.sfz");
|
|
|
|
|
synth.noteOn(0, 65, 64);
|
|
|
|
|
synth.noteOn(0, 65, 64);
|
|
|
|
|
synth.noteOn(0, 65, 64);
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2); // group polyphony should block the last note
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Self-masking")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/polyphony.sfz");
|
|
|
|
|
synth.noteOn(0, 64, 63);
|
|
|
|
|
synth.noteOn(0, 64, 62);
|
|
|
|
|
synth.noteOn(0, 64, 64);
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 3); // One of these is releasing
|
|
|
|
|
REQUIRE(synth.getVoiceView(0)->getTriggerValue() == 63_norm);
|
2020-05-05 23:45:06 +02:00
|
|
|
REQUIRE(!synth.getVoiceView(0)->releasedOrFree());
|
2020-03-29 12:52:34 +02:00
|
|
|
REQUIRE(synth.getVoiceView(1)->getTriggerValue() == 62_norm);
|
2020-05-05 23:45:06 +02:00
|
|
|
REQUIRE(synth.getVoiceView(1)->releasedOrFree()); // The lowest velocity voice is the masking candidate
|
2020-03-29 12:52:34 +02:00
|
|
|
REQUIRE(synth.getVoiceView(2)->getTriggerValue() == 64_norm);
|
2020-05-05 23:45:06 +02:00
|
|
|
REQUIRE(!synth.getVoiceView(2)->releasedOrFree());
|
2020-03-29 12:52:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Not self-masking")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/polyphony.sfz");
|
|
|
|
|
synth.noteOn(0, 66, 63);
|
|
|
|
|
synth.noteOn(0, 66, 62);
|
|
|
|
|
synth.noteOn(0, 66, 64);
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 3); // One of these is releasing
|
|
|
|
|
REQUIRE(synth.getVoiceView(0)->getTriggerValue() == 63_norm);
|
2020-05-05 23:45:06 +02:00
|
|
|
REQUIRE(synth.getVoiceView(0)->releasedOrFree()); // The first encountered voice is the masking candidate
|
2020-03-29 12:52:34 +02:00
|
|
|
REQUIRE(synth.getVoiceView(1)->getTriggerValue() == 62_norm);
|
2020-05-05 23:45:06 +02:00
|
|
|
REQUIRE(!synth.getVoiceView(1)->releasedOrFree());
|
2020-03-29 12:52:34 +02:00
|
|
|
REQUIRE(synth.getVoiceView(2)->getTriggerValue() == 64_norm);
|
2020-05-05 23:45:06 +02:00
|
|
|
REQUIRE(!synth.getVoiceView(2)->releasedOrFree());
|
2020-03-29 12:52:34 +02:00
|
|
|
}
|
2020-04-07 16:24:38 +02:00
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Polyphony in master")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/master_polyphony.sfz");
|
|
|
|
|
synth.noteOn(0, 65, 64);
|
|
|
|
|
synth.noteOn(0, 65, 64);
|
|
|
|
|
synth.noteOn(0, 65, 64);
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2); // group polyphony should block the last note
|
|
|
|
|
synth.allSoundOff();
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
|
|
|
|
synth.noteOn(0, 63, 64);
|
|
|
|
|
synth.noteOn(0, 63, 64);
|
|
|
|
|
synth.noteOn(0, 63, 64);
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2); // group polyphony should block the last note
|
|
|
|
|
synth.allSoundOff();
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
|
|
|
|
synth.noteOn(0, 61, 64);
|
|
|
|
|
synth.noteOn(0, 61, 64);
|
|
|
|
|
synth.noteOn(0, 61, 64);
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 3);
|
|
|
|
|
}
|
2020-04-06 00:26:44 +02:00
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Basic curves")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
const auto& curves = synth.getResources().curves;
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/curves.sfz");
|
|
|
|
|
REQUIRE( synth.getNumCurves() == 19 );
|
|
|
|
|
REQUIRE( curves.getCurve(18).evalCC7(127) == 1.0f );
|
|
|
|
|
REQUIRE( curves.getCurve(18).evalCC7(95) == 0.5f );
|
|
|
|
|
REQUIRE( curves.getCurve(17).evalCC7(100) == 1.0f );
|
|
|
|
|
REQUIRE( curves.getCurve(17).evalCC7(95) == 0.5f );
|
|
|
|
|
// Default linear
|
|
|
|
|
REQUIRE( curves.getCurve(16).evalCC7(63) == Approx(63_norm) );
|
|
|
|
|
}
|