Moved the file pool into a resource pool
This commit is contained in:
parent
d151e31406
commit
1536ead90b
4 changed files with 25 additions and 10 deletions
|
|
@ -132,8 +132,13 @@ private:
|
||||||
moodycamel::BlockingReaderWriterQueue<FileLoadingInformation> loadingQueue { config::numVoices };
|
moodycamel::BlockingReaderWriterQueue<FileLoadingInformation> loadingQueue { config::numVoices };
|
||||||
void loadingThread() noexcept;
|
void loadingThread() noexcept;
|
||||||
void garbageThread() noexcept;
|
void garbageThread() noexcept;
|
||||||
|
|
||||||
|
Oversampling oversamplingFactor { config::defaultOversamplingFactor };
|
||||||
|
|
||||||
|
// Signals
|
||||||
bool quitThread { false };
|
bool quitThread { false };
|
||||||
bool emptyQueue { false };
|
bool emptyQueue { false };
|
||||||
|
|
||||||
std::mutex fileHandleMutex;
|
std::mutex fileHandleMutex;
|
||||||
std::vector<std::shared_ptr<AudioBuffer<float>>> fileHandles;
|
std::vector<std::shared_ptr<AudioBuffer<float>>> fileHandles;
|
||||||
absl::flat_hash_map<absl::string_view, std::shared_ptr<AudioBuffer<float>>> preloadedData;
|
absl::flat_hash_map<absl::string_view, std::shared_ptr<AudioBuffer<float>>> preloadedData;
|
||||||
|
|
|
||||||
10
src/sfizz/Resources.h
Normal file
10
src/sfizz/Resources.h
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#pragma once
|
||||||
|
#include "FilePool.h"
|
||||||
|
|
||||||
|
namespace sfz
|
||||||
|
{
|
||||||
|
struct Resources
|
||||||
|
{
|
||||||
|
FilePool filePool;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -123,7 +123,7 @@ void sfz::Synth::clear()
|
||||||
for (auto& list: ccActivationLists)
|
for (auto& list: ccActivationLists)
|
||||||
list.clear();
|
list.clear();
|
||||||
regions.clear();
|
regions.clear();
|
||||||
filePool.clear();
|
resources.filePool.clear();
|
||||||
hasGlobal = false;
|
hasGlobal = false;
|
||||||
hasControl = false;
|
hasControl = false;
|
||||||
numGroups = 0;
|
numGroups = 0;
|
||||||
|
|
@ -219,7 +219,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename)
|
||||||
if (regions.empty())
|
if (regions.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
filePool.setRootDirectory(this->rootDirectory);
|
resources.filePool.setRootDirectory(this->rootDirectory);
|
||||||
|
|
||||||
auto lastRegion = regions.end() - 1;
|
auto lastRegion = regions.end() - 1;
|
||||||
auto currentRegion = regions.begin();
|
auto currentRegion = regions.begin();
|
||||||
|
|
@ -227,7 +227,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename)
|
||||||
auto region = currentRegion->get();
|
auto region = currentRegion->get();
|
||||||
|
|
||||||
if (!region->isGenerator()) {
|
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) {
|
if (!fileInformation) {
|
||||||
DBG("Removing the region with sample " << region->sample);
|
DBG("Removing the region with sample " << region->sample);
|
||||||
std::iter_swap(currentRegion, lastRegion);
|
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);
|
voice->startVoice(region, delay, channel, noteNumber, velocity, Voice::TriggerType::NoteOn);
|
||||||
if (!region->isGenerator()) {
|
if (!region->isGenerator()) {
|
||||||
voice->expectFileData(fileTicket);
|
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);
|
voice->startVoice(region, delay, channel, noteNumber, replacedVelocity, Voice::TriggerType::NoteOff);
|
||||||
if (!region->isGenerator()) {
|
if (!region->isGenerator()) {
|
||||||
voice->expectFileData(fileTicket);
|
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);
|
voice->startVoice(region, delay, channel, ccNumber, ccValue, Voice::TriggerType::CC);
|
||||||
if (!region->isGenerator()) {
|
if (!region->isGenerator()) {
|
||||||
voice->expectFileData(fileTicket);
|
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<absl::string_view> sfz::Synth::getUnknownOpcodes() const noexcept
|
||||||
}
|
}
|
||||||
size_t sfz::Synth::getNumPreloadedSamples() const noexcept
|
size_t sfz::Synth::getNumPreloadedSamples() const noexcept
|
||||||
{
|
{
|
||||||
return filePool.getNumPreloadedSamples();
|
return resources.filePool.getNumPreloadedSamples();
|
||||||
}
|
}
|
||||||
|
|
||||||
float sfz::Synth::getVolume() const noexcept
|
float sfz::Synth::getVolume() const noexcept
|
||||||
|
|
@ -533,7 +533,7 @@ void sfz::Synth::resetVoices(int numVoices)
|
||||||
std::this_thread::sleep_for(1ms);
|
std::this_thread::sleep_for(1ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
filePool.emptyFileLoadingQueue();
|
resources.filePool.emptyFileLoadingQueue();
|
||||||
voices.clear();
|
voices.clear();
|
||||||
for (int i = 0; i < numVoices; ++i)
|
for (int i = 0; i < numVoices; ++i)
|
||||||
voices.push_back(std::make_unique<Voice>(midiState));
|
voices.push_back(std::make_unique<Voice>(midiState));
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "FilePool.h"
|
#include "Resources.h"
|
||||||
#include "Parser.h"
|
#include "Parser.h"
|
||||||
#include "Region.h"
|
#include "Region.h"
|
||||||
#include "LeakDetector.h"
|
#include "LeakDetector.h"
|
||||||
|
|
@ -355,7 +355,7 @@ private:
|
||||||
|
|
||||||
// Singletons passed as references to the voices
|
// 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...
|
// 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;
|
MidiState midiState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue