diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index 200bb285..9ff3dfcf 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -174,3 +174,10 @@ void sfz::FilePool::clear() // Pop the queue } } + +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 d90ffc54..e9dee38c 100644 --- a/src/sfizz/FilePool.h +++ b/src/sfizz/FilePool.h @@ -113,8 +113,13 @@ public: * */ void clear(); - void emptyFileLoadingQueue() noexcept { emptyQueue = true; } - bool shouldEmptyQueue() const noexcept { return emptyQueue; } + /** + * @brief Empty the file loading queue. This function will lock and wait + * for the background thread to finish its business, so don't call it from + * the audio thread. + * + */ + void emptyFileLoadingQueue() noexcept; private: fs::path rootDirectory; struct FileLoadingInformation { diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 4be10b24..8a57bf96 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -533,12 +533,7 @@ void sfz::Synth::resetVoices(int numVoices) std::this_thread::sleep_for(1ms); } - // Empty the file pool loading queue and spinlock on it filePool.emptyFileLoadingQueue(); - while (filePool.shouldEmptyQueue()) { - std::this_thread::sleep_for(1ms); - } - voices.clear(); for (int i = 0; i < numVoices; ++i) voices.push_back(std::make_unique(midiState));