From 030e0c16ee70bd84e9538cded17f8368568c5572 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 1 Dec 2019 22:57:49 +0100 Subject: [PATCH] Added back the method to empty the file loading queue --- src/sfizz/FilePool.cpp | 19 ++++++++++++++++++- src/sfizz/FilePool.h | 1 + src/sfizz/Region.h | 6 ++---- src/sfizz/Synth.cpp | 3 +-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index f08ea3be..7e9addce 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -187,8 +187,17 @@ void sfz::FilePool::loadingThread() noexcept FilePromisePtr promise; while (!quitThread) { promisesToClean.clear(); + + if (emptyQueue) { + while(promiseQueue.pop()) { + + } + emptyQueue = false; + continue; + } + if (!promiseQueue.try_dequeue(promise)) { - std::this_thread::sleep_for(0.1ms); + std::this_thread::sleep_for(1ms); continue; } @@ -208,6 +217,7 @@ void sfz::FilePool::loadingThread() noexcept void sfz::FilePool::clear() { + emptyFileLoadingQueue(); preloadedFiles.clear(); temporaryFilePromises.clear(); promisesToClean.clear(); @@ -256,3 +266,10 @@ uint32_t sfz::FilePool::getPreloadSize() const noexcept { return preloadSize; } + +void sfz::FilePool::emptyFileLoadingQueue() noexcept +{ + emptyQueue = true; + while (emptyQueue) + std::this_thread::sleep_for(1ms); +} diff --git a/src/sfizz/FilePool.h b/src/sfizz/FilePool.h index 48c3bdac..ec1a05b0 100644 --- a/src/sfizz/FilePool.h +++ b/src/sfizz/FilePool.h @@ -136,6 +136,7 @@ public: uint32_t getPreloadSize() const noexcept; void setOversamplingFactor(Oversampling factor) noexcept; Oversampling getOversamplingFactor() const noexcept; + void emptyFileLoadingQueue() noexcept; private: fs::path rootDirectory; void loadingThread() noexcept; diff --git a/src/sfizz/Region.h b/src/sfizz/Region.h index 3692631b..9a697e15 100644 --- a/src/sfizz/Region.h +++ b/src/sfizz/Region.h @@ -49,8 +49,8 @@ namespace sfz { * */ struct Region { - Region(const MidiState& midiState, Oversampling factor = config::defaultOversamplingFactor) - : midiState(midiState), oversamplingFactor(factor) + Region(const MidiState& midiState) + : midiState(midiState) { ccSwitched.set(); } @@ -327,8 +327,6 @@ private: int activeNotesInRange { -1 }; int sequenceCounter { 0 }; - Oversampling oversamplingFactor { config::defaultOversamplingFactor }; - std::uniform_real_distribution volumeDistribution { -sfz::Default::ampRandom, sfz::Default::ampRandom }; std::uniform_real_distribution delayDistribution { 0, sfz::Default::delayRandom }; std::uniform_int_distribution offsetDistribution { 0, sfz::Default::offsetRandom }; diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index a6fea684..dea38bc3 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -316,9 +316,7 @@ int sfz::Synth::getNumActiveVoices() const noexcept void sfz::Synth::garbageCollect() noexcept { - for (auto& voice : voices) { - } } void sfz::Synth::setSamplesPerBlock(int samplesPerBlock) noexcept @@ -550,6 +548,7 @@ void sfz::Synth::setOversamplingFactor(sfz::Oversampling factor) noexcept for (auto& voice: voices) voice->reset(); + resources.filePool.emptyFileLoadingQueue(); resources.filePool.setOversamplingFactor(factor); oversamplingFactor = factor; }