From da942c9244ef1ae8038e92f0a89a99609076d7f8 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Mon, 28 Jun 2021 10:27:24 +0200 Subject: [PATCH] Store files to load and their offset and defer loading Better behavior when using a file multiple times with different offsets. --- src/sfizz/Synth.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 1e200b58..d02271c5 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -581,6 +581,8 @@ void Synth::Impl::finalizeSfzLoad() size_t currentRegionIndex = 0; size_t currentRegionCount = layers_.size(); + absl::flat_hash_map filesToLoad; + auto removeCurrentRegion = [this, ¤tRegionIndex, ¤tRegionCount]() { const Region& region = layers_[currentRegionIndex]->getRegion(); DBG("Removing the region with sample " << *region.sampleId); @@ -679,10 +681,8 @@ void Synth::Impl::finalizeSfzLoad() return Default::offsetMod.bounds.clamp(sumOffsetCC); }(); - if (!filePool.preloadFile(*region.sampleId, maxOffset)) { - removeCurrentRegion(); - continue; - } + auto& toLoad = filesToLoad[*region.sampleId]; + toLoad = max(toLoad, maxOffset); } else if (!region.isGenerator()) { if (!wavePool.createFileWave(filePool, std::string(region.sampleId->filename()))) { @@ -763,6 +763,11 @@ void Synth::Impl::finalizeSfzLoad() ++currentRegionIndex; } + + for (const auto& toLoad: filesToLoad) { + filePool.preloadFile(toLoad.first, toLoad.second); + } + if (currentRegionCount < layers_.size()) { DBG("Removing " << (layers_.size() - currentRegionCount) << " out of " << layers_.size() << " regions");