2019-11-30 15:40:13 +01:00
|
|
|
// Copyright (c) 2019, Paul Ferrand
|
|
|
|
|
// All rights reserved.
|
|
|
|
|
|
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
// list of conditions and the following disclaimer.
|
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
2019-12-02 00:10:21 +01:00
|
|
|
#include "Config.h"
|
2019-11-30 15:40:13 +01:00
|
|
|
#include "sfizz.hpp"
|
|
|
|
|
#include "catch2/catch.hpp"
|
|
|
|
|
using namespace Catch::literals;
|
|
|
|
|
|
|
|
|
|
constexpr int blockSize { 256 };
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Play and check active voices")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setSamplesPerBlock(256);
|
|
|
|
|
sfz::AudioBuffer<float> buffer { 2, blockSize };
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/groups_avl.sfz");
|
|
|
|
|
|
|
|
|
|
synth.noteOn(0, 1, 36, 24);
|
|
|
|
|
synth.noteOn(0, 1, 36, 89);
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2);
|
|
|
|
|
// Render for a while
|
|
|
|
|
for (int i = 0; i < 200; ++i)
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Change the number of voice while playing")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setSamplesPerBlock(256);
|
|
|
|
|
sfz::AudioBuffer<float> buffer { 2, blockSize };
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/groups_avl.sfz");
|
|
|
|
|
|
|
|
|
|
synth.noteOn(0, 1, 36, 24);
|
|
|
|
|
synth.noteOn(0, 1, 36, 89);
|
|
|
|
|
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);
|
|
|
|
|
sfz::AudioBuffer<float> buffer { 2, blockSize };
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/groups_avl.sfz");
|
|
|
|
|
synth.setPreloadSize(1024);
|
|
|
|
|
|
|
|
|
|
synth.noteOn(0, 1, 36, 24);
|
|
|
|
|
synth.noteOn(0, 1, 36, 89);
|
|
|
|
|
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;
|
|
|
|
|
synth.setOversamplingFactor(sfz::x2);
|
|
|
|
|
sfz::AudioBuffer<float> buffer { 2, blockSize };
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/groups_avl.sfz");
|
|
|
|
|
synth.setOversamplingFactor(sfz::x4);
|
|
|
|
|
|
|
|
|
|
synth.noteOn(0, 1, 36, 24);
|
|
|
|
|
synth.noteOn(0, 1, 36, 89);
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
synth.setOversamplingFactor(sfz::x2);
|
|
|
|
|
synth.renderBlock(buffer);
|
|
|
|
|
}
|
2019-12-17 12:40:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Testing channel 1")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setNumVoices(1);
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/midi_channels.sfz");
|
|
|
|
|
synth.noteOn(0, 0, 60, 63);
|
|
|
|
|
const auto* region = synth.getVoiceView(0)->getRegion();
|
|
|
|
|
REQUIRE( region != nullptr );
|
|
|
|
|
REQUIRE( region->sample == "dummy1.wav" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Testing channel 2")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setNumVoices(1);
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/midi_channels.sfz");
|
|
|
|
|
synth.noteOn(0, 1, 60, 63);
|
|
|
|
|
const auto* region = synth.getVoiceView(0)->getRegion();
|
|
|
|
|
REQUIRE( region != nullptr );
|
|
|
|
|
REQUIRE( region->sample == "dummy2.wav" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Testing channel 16")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setNumVoices(1);
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/midi_channels.sfz");
|
|
|
|
|
synth.noteOn(0, 15, 60, 63);
|
|
|
|
|
const auto* region = synth.getVoiceView(0)->getRegion();
|
|
|
|
|
REQUIRE( region != nullptr );
|
|
|
|
|
REQUIRE( region->sample == "dummy16.wav" );
|
2019-12-17 23:05:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] All notes offs/all sounds off (single channel)")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setNumVoices(8);
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/midi_channels.sfz");
|
|
|
|
|
synth.noteOn(0, 0, 60, 63);
|
|
|
|
|
synth.noteOn(1, 0, 60, 63);
|
|
|
|
|
REQUIRE( synth.getNumActiveVoices() == 2 );
|
|
|
|
|
synth.cc(0, 0, 120, 63);
|
|
|
|
|
REQUIRE( synth.getNumActiveVoices() == 0 );
|
|
|
|
|
|
|
|
|
|
synth.noteOn(0, 0, 60, 63);
|
|
|
|
|
synth.noteOn(1, 0, 60, 63);
|
|
|
|
|
REQUIRE( synth.getNumActiveVoices() == 2 );
|
|
|
|
|
synth.cc(0, 0, 123, 63);
|
|
|
|
|
REQUIRE( synth.getNumActiveVoices() == 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] All notes offs/all sounds off (multi channel)")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.setNumVoices(8);
|
|
|
|
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/midi_channels.sfz");
|
|
|
|
|
synth.noteOn(0, 0, 60, 63);
|
|
|
|
|
synth.noteOn(1, 1, 60, 63);
|
|
|
|
|
REQUIRE( synth.getNumActiveVoices() == 2 );
|
|
|
|
|
synth.cc(0, 0, 120, 63);
|
|
|
|
|
REQUIRE( synth.getNumActiveVoices() == 1 );
|
|
|
|
|
|
|
|
|
|
synth.noteOn(0, 0, 60, 63);
|
|
|
|
|
REQUIRE( synth.getNumActiveVoices() == 2 );
|
|
|
|
|
synth.cc(0, 0, 123, 63);
|
|
|
|
|
REQUIRE( synth.getNumActiveVoices() == 1 );
|
|
|
|
|
synth.cc(0, 1, 123, 63);
|
|
|
|
|
REQUIRE( synth.getNumActiveVoices() == 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Synth] Reset all controllers")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.cc(0, 0, 12, 64);
|
|
|
|
|
synth.cc(0, 1, 12, 64);
|
|
|
|
|
REQUIRE( synth.getMidiState().getCCValue(0, 12) == 64 );
|
|
|
|
|
synth.cc(0, 0, 121, 64);
|
|
|
|
|
REQUIRE( synth.getMidiState().getCCValue(0, 12) == 0 );
|
|
|
|
|
REQUIRE( synth.getMidiState().getCCValue(1, 12) == 64 );
|
2019-12-17 12:40:25 +01:00
|
|
|
}
|