diff --git a/src/sfizz/FilePool.h b/src/sfizz/FilePool.h index e9dee38c..c7f63fe3 100644 --- a/src/sfizz/FilePool.h +++ b/src/sfizz/FilePool.h @@ -132,8 +132,13 @@ private: moodycamel::BlockingReaderWriterQueue loadingQueue { config::numVoices }; void loadingThread() noexcept; void garbageThread() noexcept; + + Oversampling oversamplingFactor { config::defaultOversamplingFactor }; + + // Signals bool quitThread { false }; bool emptyQueue { false }; + std::mutex fileHandleMutex; std::vector>> fileHandles; absl::flat_hash_map>> preloadedData; diff --git a/src/sfizz/Resources.h b/src/sfizz/Resources.h new file mode 100644 index 00000000..3fb24a5f --- /dev/null +++ b/src/sfizz/Resources.h @@ -0,0 +1,10 @@ +#pragma once +#include "FilePool.h" + +namespace sfz +{ +struct Resources +{ + FilePool filePool; +}; +} diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index d13f4292..7b2a7b7f 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -123,7 +123,7 @@ void sfz::Synth::clear() for (auto& list: ccActivationLists) list.clear(); regions.clear(); - filePool.clear(); + resources.filePool.clear(); hasGlobal = false; hasControl = false; numGroups = 0; @@ -219,7 +219,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename) if (regions.empty()) return false; - filePool.setRootDirectory(this->rootDirectory); + resources.filePool.setRootDirectory(this->rootDirectory); auto lastRegion = regions.end() - 1; auto currentRegion = regions.begin(); @@ -227,7 +227,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename) auto region = currentRegion->get(); if (!region->isGenerator()) { - auto fileInformation = filePool.getFileInformation(region->sample, region->offset + region->offsetRandom); + auto fileInformation = resources.filePool.getFileInformation(region->sample, region->offset + region->offsetRandom); if (!fileInformation) { DBG("Removing the region with sample " << region->sample); std::iter_swap(currentRegion, lastRegion); @@ -389,7 +389,7 @@ void sfz::Synth::noteOn(int delay, int channel, int noteNumber, uint8_t velocity voice->startVoice(region, delay, channel, noteNumber, velocity, Voice::TriggerType::NoteOn); if (!region->isGenerator()) { voice->expectFileData(fileTicket); - filePool.enqueueLoading(voice, ®ion->sample, region->trueSampleEnd(), fileTicket++); + resources.filePool.enqueueLoading(voice, ®ion->sample, region->trueSampleEnd(), fileTicket++); } } } @@ -422,7 +422,7 @@ void sfz::Synth::noteOff(int delay, int channel, int noteNumber, uint8_t velocit voice->startVoice(region, delay, channel, noteNumber, replacedVelocity, Voice::TriggerType::NoteOff); if (!region->isGenerator()) { voice->expectFileData(fileTicket); - filePool.enqueueLoading(voice, ®ion->sample, region->trueSampleEnd(), fileTicket++); + resources.filePool.enqueueLoading(voice, ®ion->sample, region->trueSampleEnd(), fileTicket++); } } } @@ -451,7 +451,7 @@ void sfz::Synth::cc(int delay, int channel, int ccNumber, uint8_t ccValue) noexc voice->startVoice(region, delay, channel, ccNumber, ccValue, Voice::TriggerType::CC); if (!region->isGenerator()) { voice->expectFileData(fileTicket); - filePool.enqueueLoading(voice, ®ion->sample, region->trueSampleEnd(), fileTicket++); + resources.filePool.enqueueLoading(voice, ®ion->sample, region->trueSampleEnd(), fileTicket++); } } } @@ -503,7 +503,7 @@ std::set sfz::Synth::getUnknownOpcodes() const noexcept } size_t sfz::Synth::getNumPreloadedSamples() const noexcept { - return filePool.getNumPreloadedSamples(); + return resources.filePool.getNumPreloadedSamples(); } float sfz::Synth::getVolume() const noexcept @@ -533,7 +533,7 @@ void sfz::Synth::resetVoices(int numVoices) std::this_thread::sleep_for(1ms); } - filePool.emptyFileLoadingQueue(); + resources.filePool.emptyFileLoadingQueue(); voices.clear(); for (int i = 0; i < numVoices; ++i) voices.push_back(std::make_unique(midiState)); diff --git a/src/sfizz/Synth.h b/src/sfizz/Synth.h index 5187a595..2cfa3614 100644 --- a/src/sfizz/Synth.h +++ b/src/sfizz/Synth.h @@ -22,7 +22,7 @@ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once -#include "FilePool.h" +#include "Resources.h" #include "Parser.h" #include "Region.h" #include "LeakDetector.h" @@ -355,7 +355,7 @@ private: // Singletons passed as references to the voices // TODO: these should probably go in a global singleton holder along with a buffer distribution and LFO/EG stuff... - FilePool filePool; + Resources resources; MidiState midiState; /**