Skip to content

Commit

Permalink
Enable the <sample> test
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfd committed Aug 7, 2023
1 parent 1e771a4 commit 09c9256
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 43 deletions.
51 changes: 47 additions & 4 deletions tests/AudioFilesT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ struct CompareOutputOpts

/**
* @brief Compare the outputs of 2 sfz files with a given set of options, for a single note pressed.
*
* @param lFile
* @param rFile
* @param opts
*
* @param lFile
* @param rFile
* @param opts
*/
void compareOutputs(const std::string& lFile, const std::string& rFile, CompareOutputOpts opts)
{
Expand Down Expand Up @@ -143,3 +143,46 @@ TEST_CASE("[AudioFiles] Flac file (resampled)")
opts.sampleRate = 48000.0f;
compareOutputs(lFile, rFile, opts);
}

TEST_CASE("[Files] Embedded sample data")
{
sfz::Synth synth1;
sfz::Synth synth2;

synth1.enableFreeWheeling();
synth2.enableFreeWheeling();

synth1.setSamplesPerBlock(256);
synth2.setSamplesPerBlock(256);

synth1.loadSfzFile(fs::current_path() / "tests/TestFiles/kick.sfz");
synth2.loadSfzFile(fs::current_path() / "tests/TestFiles/kick_embedded.sfz");

REQUIRE(synth1.getNumPreloadedSamples() == 1);
REQUIRE(synth2.getNumPreloadedSamples() == 1);

sfz::AudioBuffer<float> buffer1 { 2, 256 };
sfz::AudioBuffer<float> buffer2 { 2, 256 };
std::vector<float> tmp1 (buffer1.getNumFrames());
std::vector<float> tmp2 (buffer2.getNumFrames());

synth1.noteOn(0, 60, 100);
synth2.noteOn(0, 60, 100);

for (unsigned i = 0; i < 100; ++i) {
synth1.renderBlock(buffer1);
synth2.renderBlock(buffer2);

const auto left1 = buffer1.getConstSpan(0);
const auto left2 = buffer2.getConstSpan(0);
std::copy(left1.begin(), left1.end(), tmp1.begin());
std::copy(left2.begin(), left2.end(), tmp2.begin());
REQUIRE(tmp1 == tmp2);

const auto right1 = buffer1.getConstSpan(0);
const auto right2 = buffer2.getConstSpan(0);
std::copy(right1.begin(), right1.end(), tmp1.begin());
std::copy(right2.begin(), right2.end(), tmp2.begin());
REQUIRE(tmp1 == tmp2);
}
}
39 changes: 0 additions & 39 deletions tests/FilesT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,45 +779,6 @@ TEST_CASE("[Files] Unused samples are cleared on reloading")
REQUIRE(synth.getNumPreloadedSamples() == 0);
}

// FIXME:
// this breaks on Github win32/win64/linux CI "sometimes"
// but I can't reproduce it reliably.
#if !defined(_WIN32) && !defined(_WIN64) && !defined(__APPLE__)
TEST_CASE("[Files] Embedded sample data")
{
sfz::Synth synth1;
sfz::Synth synth2;
synth1.loadSfzFile(fs::current_path() / "tests/TestFiles/kick.sfz");
synth2.loadSfzFile(fs::current_path() / "tests/TestFiles/kick_embedded.sfz");
REQUIRE(synth1.getNumPreloadedSamples() == 1);
REQUIRE(synth2.getNumPreloadedSamples() == 1);

AudioBuffer<float> buffer1 { 2, 256 };
AudioBuffer<float> buffer2 { 2, 256 };
std::vector<float> tmp1 (buffer1.getNumFrames());
std::vector<float> tmp2 (buffer2.getNumFrames());

synth1.noteOn(0, 60, 100);
synth2.noteOn(0, 60, 100);

for (unsigned i = 0; i < 100; ++i) {
synth1.renderBlock(buffer1);
synth2.renderBlock(buffer2);

const auto left1 = buffer1.getConstSpan(0);
const auto left2 = buffer2.getConstSpan(0);
std::copy(left1.begin(), left1.end(), tmp1.begin());
std::copy(left2.begin(), left2.end(), tmp2.begin());
REQUIRE(tmp1 == tmp2);

const auto right1 = buffer1.getConstSpan(0);
const auto right2 = buffer2.getConstSpan(0);
std::copy(right1.begin(), right1.end(), tmp1.begin());
std::copy(right2.begin(), right2.end(), tmp2.begin());
REQUIRE(tmp1 == tmp2);
}
}
#endif
TEST_CASE("[Files] Key center from audio file, with embedded sample data")
{
sfz::Synth synth;
Expand Down

0 comments on commit 09c9256

Please sign in to comment.