Move the "synth" tests mostly to inline files

Easier to read
This commit is contained in:
Paul Ferrand 2020-06-14 17:55:38 +02:00
parent 97b4335209
commit 96fd3d9c67
14 changed files with 84 additions and 207 deletions

View file

@ -124,7 +124,10 @@ TEST_CASE("[Synth] All notes offs/all sounds off")
{
sfz::Synth synth;
synth.setNumVoices(8);
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/sound_off.sfz");
synth.loadSfzString(fs::current_path(), R"(
<region> key=60 sample=*noise
<region> key=62 sample=*noise
)");
synth.noteOn(0, 60, 63);
synth.noteOn(0, 62, 63);
REQUIRE( synth.getNumActiveVoices() == 2 );
@ -152,15 +155,20 @@ TEST_CASE("[Synth] Releasing before the EG started smoothing (initial delay) kil
{
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");
synth.loadSfzString(fs::current_path(), R"(
<region> ampeg_delay=0.005 ampeg_release=1 sample=*noise
)");
synth.noteOn(0, 60, 63);
REQUIRE( !synth.getVoiceView(0)->isFree() );
synth.noteOff(100, 60, 63);
synth.renderBlock(buffer);
REQUIRE( synth.getVoiceView(0)->isFree() );
synth.noteOn(200, 60, 63);
REQUIRE( !synth.getVoiceView(0)->isFree() );
synth.noteOff(1000, 60, 63);
synth.renderBlock(buffer);
REQUIRE( !synth.getVoiceView(0)->isFree() );
}
@ -170,7 +178,9 @@ TEST_CASE("[Synth] Releasing after the initial and normal mode does not trigger
synth.setSamplesPerBlock(1024);
sfz::AudioBuffer<float> buffer(2, 1024);
synth.setNumVoices(1);
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/delay_release.sfz");
synth.loadSfzString(fs::current_path(), R"(
<region> ampeg_delay=0.005 ampeg_release=1 sample=*noise
)");
synth.noteOn(200, 60, 63);
REQUIRE( !synth.getVoiceView(0)->isFree() );
synth.renderBlock(buffer);
@ -187,7 +197,11 @@ TEST_CASE("[Synth] Trigger=release and an envelope properly kills the voice at t
synth.setSamplesPerBlock(480);
sfz::AudioBuffer<float> buffer(2, 480);
synth.setNumVoices(1);
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/envelope_trigger_release.sfz");
synth.loadSfzString(fs::current_path(), R"(
<group> lovel=0 hivel=127
<region> trigger=release sample=*noise loop_mode=one_shot
ampeg_attack=0.02 ampeg_decay=0.02 ampeg_release=0.1 ampeg_sustain=0
)");
synth.noteOn(0, 60, 63);
synth.noteOff(0, 60, 63);
REQUIRE( !synth.getVoiceView(0)->isFree() );
@ -210,7 +224,11 @@ TEST_CASE("[Synth] Trigger=release_key and an envelope properly kills the voice
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.loadSfzString(fs::current_path(), R"(
<group> lovel=0 hivel=127
<region> trigger=release_key sample=*noise loop_mode=one_shot
ampeg_attack=0.02 ampeg_decay=0.02 ampeg_release=0.1 ampeg_sustain=0
)");
synth.noteOn(0, 60, 63);
synth.noteOff(0, 60, 63);
REQUIRE( !synth.getVoiceView(0)->isFree() );
@ -233,7 +251,11 @@ TEST_CASE("[Synth] loopmode=one_shot and an envelope properly kills the voice at
synth.setSamplesPerBlock(480);
sfz::AudioBuffer<float> buffer(2, 480);
synth.setNumVoices(1);
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/envelope_one_shot.sfz");
synth.loadSfzString(fs::current_path(), R"(
<group> lovel=0 hivel=127
<region> sample=*noise loop_mode=one_shot
ampeg_attack=0.02 ampeg_decay=0.02 ampeg_release=0.1 ampeg_sustain=0
)");
synth.noteOn(0, 60, 63);
synth.noteOff(0, 60, 63);
REQUIRE( !synth.getVoiceView(0)->isFree() );
@ -256,27 +278,37 @@ TEST_CASE("[Synth] Number of effect buses and resetting behavior")
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");
synth.loadSfzString(fs::current_path(), R"(
<region> lokey=0 hikey=127 sample=*sine
)");
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");
synth.loadSfzString(fs::current_path(), R"(
<region> lokey=0 hikey=127 sample=*sine effect1=100
<effect> directtomain=50 fx1tomain=50 type=lofi bus=fx1 bitred=90 decim=10
)");
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");
synth.loadSfzString(fs::current_path(), R"(
<region> lokey=0 hikey=127 sample=*sine
)");
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");
synth.loadSfzString(fs::current_path(), R"(
<region> lokey=0 hikey=127 sample=*sine effect1=100
<effect> directtomain=50 fx3tomain=50 type=lofi bus=fx3 bitred=90 decim=10
)");
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
@ -290,7 +322,9 @@ TEST_CASE("[Synth] Number of effect buses and resetting behavior")
TEST_CASE("[Synth] No effect in the main bus")
{
sfz::Synth synth;
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/base.sfz");
synth.loadSfzString(fs::current_path(), R"(
<region> lokey=0 hikey=127 sample=*sine
)");
auto bus = synth.getEffectBusView(0);
REQUIRE( bus != nullptr); // We have a main bus
REQUIRE( bus->numEffects() == 0 );
@ -301,7 +335,10 @@ TEST_CASE("[Synth] No effect in the main bus")
TEST_CASE("[Synth] One effect")
{
sfz::Synth synth;
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/bitcrusher_1.sfz");
synth.loadSfzString(fs::current_path(), R"(
<region> lokey=0 hikey=127 sample=*sine
<effect> type=lofi bitred=90 decim=10
)");
auto bus = synth.getEffectBusView(0);
REQUIRE( bus != nullptr); // We have a main bus
REQUIRE( bus->numEffects() == 1 );
@ -312,7 +349,10 @@ TEST_CASE("[Synth] One effect")
TEST_CASE("[Synth] Effect on a second bus")
{
sfz::Synth synth;
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/bitcrusher_2.sfz");
synth.loadSfzString(fs::current_path(), R"(
<region> lokey=0 hikey=127 sample=*sine effect1=100
<effect> directtomain=50 fx1tomain=50 type=lofi bus=fx1 bitred=90 decim=10
)");
auto bus = synth.getEffectBusView(0);
REQUIRE( bus != nullptr); // We have a main bus
REQUIRE( bus->numEffects() == 0 );
@ -329,7 +369,10 @@ TEST_CASE("[Synth] Effect on a second bus")
TEST_CASE("[Synth] Effect on a third bus")
{
sfz::Synth synth;
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/bitcrusher_3.sfz");
synth.loadSfzString(fs::current_path(), R"(
<region> lokey=0 hikey=127 sample=*sine effect1=100
<effect> directtomain=50 fx3tomain=50 type=lofi bus=fx3 bitred=90 decim=10
)");
auto bus = synth.getEffectBusView(0);
REQUIRE( bus != nullptr); // We have a main bus
REQUIRE( bus->numEffects() == 0 );
@ -345,7 +388,10 @@ TEST_CASE("[Synth] Effect on a third bus")
TEST_CASE("[Synth] Gain to mix")
{
sfz::Synth synth;
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Effects/to_mix.sfz");
synth.loadSfzString(fs::current_path(), R"(
<region> lokey=0 hikey=127 sample=*sine effect1=100
<effect> fx1tomix=50 bus=fx1 type=lofi bitred=90 decim=10
)");
auto bus = synth.getEffectBusView(0);
REQUIRE( bus != nullptr); // We have a main bus
REQUIRE( bus->numEffects() == 0 );
@ -358,75 +404,15 @@ TEST_CASE("[Synth] Gain to mix")
REQUIRE( bus->gainToMix() == 0.5 );
}
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);
REQUIRE(!synth.getVoiceView(0)->releasedOrFree());
REQUIRE(synth.getVoiceView(1)->getTriggerValue() == 62_norm);
REQUIRE(synth.getVoiceView(1)->releasedOrFree()); // The lowest velocity voice is the masking candidate
REQUIRE(synth.getVoiceView(2)->getTriggerValue() == 64_norm);
REQUIRE(!synth.getVoiceView(2)->releasedOrFree());
}
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);
REQUIRE(synth.getVoiceView(0)->releasedOrFree()); // The first encountered voice is the masking candidate
REQUIRE(synth.getVoiceView(1)->getTriggerValue() == 62_norm);
REQUIRE(!synth.getVoiceView(1)->releasedOrFree());
REQUIRE(synth.getVoiceView(2)->getTriggerValue() == 64_norm);
REQUIRE(!synth.getVoiceView(2)->releasedOrFree());
}
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);
}
TEST_CASE("[Synth] Basic curves")
{
sfz::Synth synth;
const auto& curves = synth.getResources().curves;
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/curves.sfz");
synth.loadSfzString(fs::current_path(), R"(
<region> sample=*sine
<curve>curve_index=18 v000=0 v095=0.5 v127=1
<curve>curve_index=17 v000=0 v095=0.5 v100=1
)");
REQUIRE( synth.getNumCurves() == 19 );
REQUIRE( curves.getCurve(18).evalCC7(127) == 1.0f );
REQUIRE( curves.getCurve(18).evalCC7(95) == 0.5f );
@ -439,7 +425,10 @@ TEST_CASE("[Synth] Basic curves")
TEST_CASE("[Synth] Velocity points")
{
sfz::Synth synth;
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/velocity_endpoints.sfz");
synth.loadSfzString(fs::current_path(), R"(
<region> amp_velcurve_064=1 sample=*sine
<region> amp_velcurve_064=1 amp_veltrack=-100 sample=*sine
)");
REQUIRE( !synth.getRegionView(0)->velocityPoints.empty());
REQUIRE( synth.getRegionView(0)->velocityPoints[0].first == 64 );
REQUIRE( synth.getRegionView(0)->velocityPoints[0].second == 1.0_a );
@ -451,7 +440,10 @@ TEST_CASE("[Synth] Velocity points")
TEST_CASE("[Synth] velcurve")
{
sfz::Synth synth;
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/velocity_endpoints.sfz");
synth.loadSfzString(fs::current_path(), R"(
<region> amp_velcurve_064=1 sample=*sine
<region> amp_velcurve_064=1 amp_veltrack=-100 sample=*sine
)");
REQUIRE( synth.getRegionView(0)->velocityCurve(0_norm) == 0.0_a );
REQUIRE( synth.getRegionView(0)->velocityCurve(32_norm) == Approx(0.5f).margin(1e-2) );
REQUIRE( synth.getRegionView(0)->velocityCurve(64_norm) == 1.0_a );
@ -468,13 +460,13 @@ TEST_CASE("[Synth] Region by identifier")
{
sfz::Synth synth;
synth.loadSfzString("regionByIdentifier.sfz", R"(
<region>sample=*sine
<region>sample=*sine
<region>sample=doesNotExist.wav
<region>sample=*sine
<region>sample=doesNotExist.wav
<region>sample=*sine
)");
<region>sample=*sine
<region>sample=*sine
<region>sample=doesNotExist.wav
<region>sample=*sine
<region>sample=doesNotExist.wav
<region>sample=*sine
)");
REQUIRE(synth.getNumRegions() == 4);
REQUIRE(synth.getRegionView(0) == synth.getRegionById(NumericId<sfz::Region>{0}));
@ -492,9 +484,9 @@ 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
)");
<region> sample=kick.wav key=60
<region> sample=kick.wav key=61 sample_quality=5
)");
// default sample quality
synth.noteOn(0, 60, 100);

View file

@ -1,4 +0,0 @@
<region>
lokey=0
hikey=127
sample=*sine

View file

@ -1,9 +0,0 @@
<region>
lokey=0
hikey=127
sample=*sine
<effect>
type=lofi
bitred=90
decim=10

View file

@ -1,13 +0,0 @@
<region>
lokey=0
hikey=127
sample=*sine
effect1=100
<effect>
directtomain=50
fx1tomain=50
type=lofi
bus=fx1
bitred=90
decim=10

View file

@ -1,13 +0,0 @@
<region>
lokey=0
hikey=127
sample=*sine
effect1=100
<effect>
directtomain=50
fx3tomain=50
type=lofi
bus=fx3
bitred=90
decim=10

View file

@ -1,12 +0,0 @@
<region>
lokey=0
hikey=127
sample=*sine
effect1=100
<effect>
fx1tomix=50
bus=fx1
type=lofi
bitred=90
decim=10

View file

@ -1,10 +0,0 @@
<region> sample=*sine
<curve>curve_index=18
v000=0
v095=0.5
v127=1
<curve>curve_index=17
v000=0
v095=0.5
v100=1

View file

@ -1,12 +0,0 @@
<group>
lovel=0
hivel=127
<region>
sample=*noise
loop_mode=one_shot
ampeg_attack=0.02
ampeg_decay=0.02
ampeg_release=0.1
ampeg_sustain=0

View file

@ -1,13 +0,0 @@
<group>
lovel=0
hivel=127
<region>
trigger=release
sample=*noise
loop_mode=one_shot
ampeg_attack=0.02
ampeg_decay=0.02
ampeg_release=0.1
ampeg_sustain=0

View file

@ -1,13 +0,0 @@
<group>
lovel=0
hivel=127
<region>
trigger=release_key
sample=*noise
loop_mode=one_shot
ampeg_attack=0.02
ampeg_decay=0.02
ampeg_release=0.1
ampeg_sustain=0

View file

@ -1,7 +0,0 @@
<master> polyphony=2
<group> group=2
<region> sample=*sine key=65
<group> group=3
<region> sample=*sine key=63
<master> // Empty master resets the polyphony
<region> sample=*sine key=61

View file

@ -1,5 +0,0 @@
<region> sample=*sine key=63
<region> sample=*sine key=64 note_polyphony=2
<region> sample=*sine key=66 note_polyphony=2 note_selfmask=off
<group> group=1 polyphony=2
<region> sample=*sine key=65

View file

@ -1,2 +0,0 @@
<region> key=60 sample=dummy1.wav
<region> key=62 sample=dummy2.wav

View file

@ -1,2 +0,0 @@
<region> amp_velcurve_064=1 sample=*sine
<region> amp_velcurve_064=1 amp_veltrack=-100 sample=*sine