Skip to content

Commit

Permalink
WIP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfd committed Mar 6, 2020
1 parent eaf0bc9 commit 7fd1966
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
53 changes: 51 additions & 2 deletions tests/SynthT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ constexpr int blockSize { 256 };
TEST_CASE("[Synth] Play and check active voices")
{
sfz::Synth synth;
synth.setSamplesPerBlock(256);
synth.setSamplesPerBlock(blockSize);
sfz::AudioBuffer<float> buffer { 2, blockSize };
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/groups_avl.sfz");

Expand All @@ -29,7 +29,7 @@ TEST_CASE("[Synth] Play and check active voices")
TEST_CASE("[Synth] Change the number of voice while playing")
{
sfz::Synth synth;
synth.setSamplesPerBlock(256);
synth.setSamplesPerBlock(blockSize);
sfz::AudioBuffer<float> buffer { 2, blockSize };
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/groups_avl.sfz");

Expand Down Expand Up @@ -210,3 +210,52 @@ TEST_CASE("[Synth] Trigger=release_key and an envelope properly kills the voice
synth.renderBlock(buffer);
REQUIRE( synth.getVoiceView(0)->isFree() );
}

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 );
}
4 changes: 4 additions & 0 deletions tests/TestFiles/Effects/base.sfz
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<region>
lokey=0
hikey=127
sample=*sine
9 changes: 9 additions & 0 deletions tests/TestFiles/Effects/bitcrusher_1.sfz
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<region>
lokey=0
hikey=127
sample=*sine

<effect>
type=lofi
bitred=90
decim=10
13 changes: 13 additions & 0 deletions tests/TestFiles/Effects/bitcrusher_2.sfz
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<region>
lokey=0
hikey=127
sample=*sine
effect1=100

<effect>
directtomain=50
fx1tomain=50
type=lofi
bus=fx1
bitred=90
decim=10
13 changes: 13 additions & 0 deletions tests/TestFiles/Effects/bitcrusher_3.sfz
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<region>
lokey=0
hikey=127
sample=*sine
effect1=100

<effect>
directtomain=50
fx3tomain=50
type=lofi
bus=fx3
bitred=90
decim=10

0 comments on commit 7fd1966

Please sign in to comment.