Added tests for the dynamic voice settings
This commit is contained in:
parent
4bce1dc0d9
commit
bd5f491fb3
5 changed files with 201 additions and 76 deletions
|
|
@ -486,10 +486,17 @@ int sfz::Synth::getNumCurves() const noexcept
|
|||
{
|
||||
return numCurves;
|
||||
}
|
||||
|
||||
const sfz::Region* sfz::Synth::getRegionView(int idx) const noexcept
|
||||
{
|
||||
return (size_t)idx < regions.size() ? regions[idx].get() : nullptr;
|
||||
}
|
||||
|
||||
const sfz::Voice* sfz::Synth::getVoiceView(int idx) const noexcept
|
||||
{
|
||||
return (size_t)idx < voices.size() ? voices[idx].get() : nullptr;
|
||||
}
|
||||
|
||||
std::set<absl::string_view> sfz::Synth::getUnknownOpcodes() const noexcept
|
||||
{
|
||||
return unknownOpcodes;
|
||||
|
|
|
|||
|
|
@ -130,6 +130,14 @@ public:
|
|||
* @return const Region*
|
||||
*/
|
||||
const Region* getRegionView(int idx) const noexcept;
|
||||
/**
|
||||
* @brief Get a raw view into a specific voice. This is mostly used
|
||||
* for testing.
|
||||
*
|
||||
* @param idx
|
||||
* @return const Region*
|
||||
*/
|
||||
const Voice* getVoiceView(int idx) const noexcept;
|
||||
/**
|
||||
* @brief Get a list of unknown opcodes. The lifetime of the
|
||||
* string views in the code are linked to the currently loaded
|
||||
|
|
|
|||
|
|
@ -73,6 +73,18 @@ public:
|
|||
* @param samplesPerBlock
|
||||
*/
|
||||
void setSamplesPerBlock(int samplesPerBlock) noexcept;
|
||||
/**
|
||||
* @brief Get the sample rate of the voice.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
float getSampleRate() const noexcept { return sampleRate; }
|
||||
/**
|
||||
* @brief Get the expected block size.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int getSamplesPerBlock() const noexcept { return samplesPerBlock; }
|
||||
|
||||
/**
|
||||
* @brief Start playing a region after a short delay for different triggers (note on, off, cc)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ set(SFIZZ_TEST_SOURCES
|
|||
ADSREnvelopeT.cpp
|
||||
LinearEnvelopeT.cpp
|
||||
MainT.cpp
|
||||
SynthT.cpp
|
||||
RegionTriggersT.cpp
|
||||
)
|
||||
|
||||
|
|
|
|||
97
tests/SynthT.cpp
Normal file
97
tests/SynthT.cpp
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
// 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.
|
||||
|
||||
#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 );
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Synth] Check that the sample rate and sample per block is changed when changing the number of voices")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue