Added tests for stereo/mono samples, as well as sw_default
This commit is contained in:
parent
a8b2c9dfa8
commit
49d869cd1f
8 changed files with 79 additions and 61 deletions
|
|
@ -32,6 +32,7 @@ std::optional<sfz::FilePool::FileInformation> sfz::FilePool::getFileInformation(
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInformation returnedValue;
|
FileInformation returnedValue;
|
||||||
|
returnedValue.numChannels = sndFile.channels();
|
||||||
returnedValue.end = static_cast<uint32_t>(sndFile.frames());
|
returnedValue.end = static_cast<uint32_t>(sndFile.frames());
|
||||||
returnedValue.sampleRate = static_cast<double>(sndFile.samplerate());
|
returnedValue.sampleRate = static_cast<double>(sndFile.samplerate());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ public:
|
||||||
size_t getNumPreloadedSamples() const noexcept { return preloadedData.size(); }
|
size_t getNumPreloadedSamples() const noexcept { return preloadedData.size(); }
|
||||||
|
|
||||||
struct FileInformation {
|
struct FileInformation {
|
||||||
|
int numChannels { 1 };
|
||||||
uint32_t end { Default::sampleEndRange.getEnd() };
|
uint32_t end { Default::sampleEndRange.getEnd() };
|
||||||
uint32_t loopBegin { Default::loopRange.getStart() };
|
uint32_t loopBegin { Default::loopRange.getStart() };
|
||||||
uint32_t loopEnd { Default::loopRange.getEnd() };
|
uint32_t loopEnd { Default::loopRange.getEnd() };
|
||||||
|
|
|
||||||
|
|
@ -408,7 +408,7 @@ bool sfz::Region::isSwitchedOn() const noexcept
|
||||||
return keySwitched && previousKeySwitched && sequenceSwitched && pitchSwitched && bpmSwitched && aftertouchSwitched && allCCSwitched;
|
return keySwitched && previousKeySwitched && sequenceSwitched && pitchSwitched && bpmSwitched && aftertouchSwitched && allCCSwitched;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity, float randValue) noexcept
|
bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity, float randValue) noexcept
|
||||||
{
|
{
|
||||||
const bool chanOk = channelRange.containsWithEnd(channel);
|
const bool chanOk = channelRange.containsWithEnd(channel);
|
||||||
if (!chanOk)
|
if (!chanOk)
|
||||||
|
|
@ -586,4 +586,9 @@ bool sfz::Region::canUsePreloadedData() const noexcept
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return trueSampleEnd() < static_cast<uint32_t>(preloadedData->getNumFrames());
|
return trueSampleEnd() < static_cast<uint32_t>(preloadedData->getNumFrames());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sfz::Region::isStereo() const noexcept
|
||||||
|
{
|
||||||
|
return this->numChannels == 2;
|
||||||
}
|
}
|
||||||
|
|
@ -87,8 +87,11 @@ void sfz::Synth::clear()
|
||||||
void sfz::Synth::handleGlobalOpcodes(const std::vector<Opcode>& members)
|
void sfz::Synth::handleGlobalOpcodes(const std::vector<Opcode>& members)
|
||||||
{
|
{
|
||||||
for (auto& member : members) {
|
for (auto& member : members) {
|
||||||
if (member.opcode == "sw_default")
|
switch (hash(member.opcode)) {
|
||||||
|
case hash("sw_default"):
|
||||||
setValueFromOpcode(member, defaultSwitch, Default::keyRange);
|
setValueFromOpcode(member, defaultSwitch, Default::keyRange);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,24 +135,22 @@ bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename)
|
||||||
while (currentRegion <= lastRegion) {
|
while (currentRegion <= lastRegion) {
|
||||||
auto region = currentRegion->get();
|
auto region = currentRegion->get();
|
||||||
|
|
||||||
if (region->isGenerator()) {
|
if (!region->isGenerator()) {
|
||||||
currentRegion++;
|
auto fileInformation = filePool.getFileInformation(region->sample);
|
||||||
continue;
|
if (!fileInformation) {
|
||||||
}
|
DBG("Removing the region with sample " << region->sample);
|
||||||
|
std::iter_swap(currentRegion, lastRegion);
|
||||||
|
lastRegion--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
auto fileInformation = filePool.getFileInformation(region->sample);
|
region->numChannels = fileInformation->numChannels;
|
||||||
if (!fileInformation) {
|
region->sampleEnd = std::min(region->sampleEnd, fileInformation->end);
|
||||||
DBG("Removing the region with sample " << region->sample);
|
region->loopRange.shrinkIfSmaller(fileInformation->loopBegin, fileInformation->loopEnd);
|
||||||
std::iter_swap(currentRegion, lastRegion);
|
region->preloadedData = fileInformation->preloadedData;
|
||||||
lastRegion--;
|
region->sampleRate = fileInformation->sampleRate;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
region->sampleEnd = std::min(region->sampleEnd, fileInformation->end);
|
|
||||||
region->loopRange.shrinkIfSmaller(fileInformation->loopBegin, fileInformation->loopEnd);
|
|
||||||
region->preloadedData = fileInformation->preloadedData;
|
|
||||||
region->sampleRate = fileInformation->sampleRate;
|
|
||||||
|
|
||||||
for (auto note = region->keyRange.getStart(); note <= region->keyRange.getEnd(); note++)
|
for (auto note = region->keyRange.getStart(); note <= region->keyRange.getEnd(); note++)
|
||||||
noteActivationLists[note].push_back(region);
|
noteActivationLists[note].push_back(region);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ TEST_CASE("[Files] Single region (regions_one.sfz)")
|
||||||
REQUIRE(synth.getRegionView(0)->sample == "dummy.wav");
|
REQUIRE(synth.getRegionView(0)->sample == "dummy.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("[Files] Multiple regions (regions_many.sfz)")
|
TEST_CASE("[Files] Multiple regions (regions_many.sfz)")
|
||||||
{
|
{
|
||||||
sfz::Synth synth;
|
sfz::Synth synth;
|
||||||
|
|
@ -227,48 +228,55 @@ TEST_CASE("[Files] Pizz basic")
|
||||||
REQUIRE(synth.getRegionView(3)->sample == R"(../Samples/pizz/a0_vl4_rr4.wav)");
|
REQUIRE(synth.getRegionView(3)->sample == R"(../Samples/pizz/a0_vl4_rr4.wav)");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST_CASE("[Files] sw_default")
|
TEST_CASE("[Files] Channels (channels.sfz)")
|
||||||
// {
|
{
|
||||||
// const double sampleRate { 48000 };
|
sfz::Synth synth;
|
||||||
// const int blockSize { 256 };
|
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/channels.sfz");
|
||||||
// sfz::Synth synth;
|
REQUIRE(synth.getNumRegions() == 2);
|
||||||
// synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/sw_default.sfz");
|
REQUIRE(synth.getRegionView(0)->sample == "mono_sample.wav");
|
||||||
// REQUIRE( synth.getNumRegions() == 4 );
|
REQUIRE(synth.getRegionView(0)->numChannels == 1);
|
||||||
// REQUIRE( !synth.getRegionView(0)->isSwitchedOn() );
|
REQUIRE(!synth.getRegionView(0)->isStereo());
|
||||||
// REQUIRE( synth.getRegionView(1)->isSwitchedOn() );
|
REQUIRE(synth.getRegionView(1)->sample == "stereo_sample.wav");
|
||||||
// REQUIRE( !synth.getRegionView(2)->isSwitchedOn() );
|
REQUIRE(synth.getRegionView(1)->numChannels == 2);
|
||||||
// REQUIRE( synth.getRegionView(3)->isSwitchedOn() );
|
REQUIRE(synth.getRegionView(1)->isStereo());
|
||||||
// }
|
}
|
||||||
|
|
||||||
// TEST_CASE("[Files] sw_default and playing with switches")
|
TEST_CASE("[Files] sw_default")
|
||||||
// {
|
{
|
||||||
// const double sampleRate { 48000 };
|
sfz::Synth synth;
|
||||||
// const int blockSize { 256 };
|
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/sw_default.sfz");
|
||||||
// sfz::Synth synth;
|
REQUIRE( synth.getNumRegions() == 4 );
|
||||||
// synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/sw_default.sfz");
|
REQUIRE( !synth.getRegionView(0)->isSwitchedOn() );
|
||||||
// REQUIRE( synth.getNumRegions() == 4 );
|
REQUIRE( synth.getRegionView(1)->isSwitchedOn() );
|
||||||
// REQUIRE( !synth.getRegionView(0)->isSwitchedOn() );
|
REQUIRE( !synth.getRegionView(2)->isSwitchedOn() );
|
||||||
// REQUIRE( synth.getRegionView(1)->isSwitchedOn() );
|
REQUIRE( synth.getRegionView(3)->isSwitchedOn() );
|
||||||
// REQUIRE( !synth.getRegionView(2)->isSwitchedOn() );
|
}
|
||||||
// REQUIRE( synth.getRegionView(3)->isSwitchedOn() );
|
|
||||||
// AudioBuffer<float> buffer { 2, blockSize };
|
TEST_CASE("[Files] sw_default and playing with switches")
|
||||||
// synth.prepareToPlay(sampleRate, blockSize);
|
{
|
||||||
// buffer.clear();
|
sfz::Synth synth;
|
||||||
// synth.registerNoteOn(1, 41, 64, 0);
|
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/sw_default.sfz");
|
||||||
// REQUIRE( synth.getRegionView(0)->isSwitchedOn() );
|
REQUIRE( synth.getNumRegions() == 4 );
|
||||||
// REQUIRE( !synth.getRegionView(1)->isSwitchedOn() );
|
REQUIRE( !synth.getRegionView(0)->isSwitchedOn() );
|
||||||
// REQUIRE( synth.getRegionView(2)->isSwitchedOn() );
|
REQUIRE( synth.getRegionView(1)->isSwitchedOn() );
|
||||||
// REQUIRE( !synth.getRegionView(3)->isSwitchedOn() );
|
REQUIRE( !synth.getRegionView(2)->isSwitchedOn() );
|
||||||
// synth.registerNoteOff(1, 41, 0, 0);
|
REQUIRE( synth.getRegionView(3)->isSwitchedOn() );
|
||||||
// synth.registerNoteOn(1, 42, 64, 0);
|
synth.noteOn(0, 1, 41, 64);
|
||||||
// REQUIRE( !synth.getRegionView(0)->isSwitchedOn() );
|
synth.noteOff(0, 1, 41, 0);
|
||||||
// REQUIRE( !synth.getRegionView(1)->isSwitchedOn() );
|
REQUIRE( synth.getRegionView(0)->isSwitchedOn() );
|
||||||
// REQUIRE( !synth.getRegionView(2)->isSwitchedOn() );
|
REQUIRE( !synth.getRegionView(1)->isSwitchedOn() );
|
||||||
// REQUIRE( !synth.getRegionView(3)->isSwitchedOn() );
|
REQUIRE( synth.getRegionView(2)->isSwitchedOn() );
|
||||||
// synth.registerNoteOff(1, 42, 0, 0);
|
REQUIRE( !synth.getRegionView(3)->isSwitchedOn() );
|
||||||
// synth.registerNoteOn(1, 40, 64, 0);
|
synth.noteOn(0, 1, 42, 64);
|
||||||
// REQUIRE( !synth.getRegionView(0)->isSwitchedOn() );
|
synth.noteOff(0, 1, 42, 0);
|
||||||
// REQUIRE( synth.getRegionView(1)->isSwitchedOn() );
|
REQUIRE( !synth.getRegionView(0)->isSwitchedOn() );
|
||||||
// REQUIRE( !synth.getRegionView(2)->isSwitchedOn() );
|
REQUIRE( !synth.getRegionView(1)->isSwitchedOn() );
|
||||||
// REQUIRE( synth.getRegionView(3)->isSwitchedOn() );
|
REQUIRE( !synth.getRegionView(2)->isSwitchedOn() );
|
||||||
// }
|
REQUIRE( !synth.getRegionView(3)->isSwitchedOn() );
|
||||||
|
synth.noteOn(0, 1, 40, 64);
|
||||||
|
synth.noteOff(0, 1, 40, 64);
|
||||||
|
REQUIRE( !synth.getRegionView(0)->isSwitchedOn() );
|
||||||
|
REQUIRE( synth.getRegionView(1)->isSwitchedOn() );
|
||||||
|
REQUIRE( !synth.getRegionView(2)->isSwitchedOn() );
|
||||||
|
REQUIRE( synth.getRegionView(3)->isSwitchedOn() );
|
||||||
|
}
|
||||||
2
tests/TestFiles/channels.sfz
Normal file
2
tests/TestFiles/channels.sfz
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
<region> key=60 sample=mono_sample.wav
|
||||||
|
<region> key=61 sample=stereo_sample.wav
|
||||||
BIN
tests/TestFiles/mono_sample.wav
Executable file
BIN
tests/TestFiles/mono_sample.wav
Executable file
Binary file not shown.
BIN
tests/TestFiles/stereo_sample.wav
Executable file
BIN
tests/TestFiles/stereo_sample.wav
Executable file
Binary file not shown.
Loading…
Add table
Reference in a new issue