Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small, all zero files are replaced by *silence #831

Merged
merged 1 commit into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/sfizz/FilePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ sfz::FileDataHolder sfz::FilePool::loadFile(const FileId& fileId) noexcept
*fileInformation
});
insertedPair.first->second.status = FileData::Status::Preloaded;
ASSERT(insertedPair.second);
return { &insertedPair.first->second };
}
}
Expand Down
20 changes: 18 additions & 2 deletions src/sfizz/Synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,24 @@ void Synth::Impl::finalizeSfzLoad()
continue;
}

region.hasWavetableSample = fileInformation->wavetable ||
fileInformation->end < config::wavetableMaxFrames;
region.hasWavetableSample = fileInformation->wavetable.has_value();

if (fileInformation->end < config::wavetableMaxFrames) {
auto sample = resources_.filePool.loadFile(*region.sampleId);
bool allZeros = true;
int numChannels = sample->information.numChannels;
for (int i = 0; i < numChannels; ++i) {
allZeros &= allWithin(sample->preloadedData.getConstSpan(i),
-config::virtuallyZero, config::virtuallyZero);
}

if (allZeros) {
region.sampleId.reset(new FileId("*silence"));
region.hasWavetableSample = false;
} else {
region.hasWavetableSample |= true;
}
}
}

if (!region.isOscillator()) {
Expand Down
17 changes: 17 additions & 0 deletions tests/SynthT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1811,3 +1811,20 @@ TEST_CASE("[Keyswitches] Trigger from aftertouch extended CC")
synth.renderBlock(buffer);
REQUIRE(synth.getNumActiveVoices() == 2);
}

TEST_CASE("[Synth] Short empty files are turned into *silence")
{
sfz::Synth synth;
std::vector<std::string> messageList;
sfz::Client client(&messageList);
client.setReceiveCallback(&simpleMessageReceiver);
sfz::AudioBuffer<float> buffer { 2, static_cast<unsigned>(synth.getSamplesPerBlock()) };
synth.loadSfzString(fs::current_path() / "tests/TestFiles/aftertouch_trigger.sfz", R"(
<region> sample=silence.wav
)");
synth.dispatchMessage(client, 0, "/region0/sample", "", nullptr);
std::vector<std::string> expected {
"/region0/sample,s : { *silence }",
};
REQUIRE(messageList == expected);
}
Binary file modified tests/TestFiles/root_key_38.flac
Binary file not shown.
Binary file modified tests/TestFiles/root_key_38.wav
Binary file not shown.
Binary file modified tests/TestFiles/root_key_62.flac
Binary file not shown.
Binary file modified tests/TestFiles/root_key_62.wav
Binary file not shown.
Binary file added tests/TestFiles/silence.wav
Binary file not shown.