Corrected a bug when preloading data for regions with large offsets
This commit is contained in:
parent
f41c36d241
commit
8e02171cb2
3 changed files with 9 additions and 5 deletions
|
|
@ -45,7 +45,7 @@ std::unique_ptr<AudioBuffer<T>> readFromFile(SndfileHandle& sndFile, int numFram
|
|||
return returnedBuffer;
|
||||
}
|
||||
|
||||
std::optional<sfz::FilePool::FileInformation> sfz::FilePool::getFileInformation(std::string_view filename) noexcept
|
||||
std::optional<sfz::FilePool::FileInformation> sfz::FilePool::getFileInformation(std::string_view filename, uint32_t offset) noexcept
|
||||
{
|
||||
std::filesystem::path file { rootDirectory / filename };
|
||||
if (!std::filesystem::exists(file))
|
||||
|
|
@ -72,11 +72,15 @@ std::optional<sfz::FilePool::FileInformation> sfz::FilePool::getFileInformation(
|
|||
if (config::preloadSize == 0)
|
||||
return returnedValue.end;
|
||||
else
|
||||
return std::min(returnedValue.end, static_cast<uint32_t>(config::preloadSize));
|
||||
return std::min(returnedValue.end, offset + static_cast<uint32_t>(config::preloadSize));
|
||||
}();
|
||||
|
||||
if (preloadedData.contains(filename)) {
|
||||
returnedValue.preloadedData = preloadedData[filename];
|
||||
auto alreadyPreloaded = preloadedData[filename];
|
||||
if (preloadedSize > alreadyPreloaded->getNumFrames()) {
|
||||
alreadyPreloaded.reset(readFromFile<float>(sndFile, preloadedSize).get());
|
||||
}
|
||||
returnedValue.preloadedData = alreadyPreloaded;
|
||||
} else {
|
||||
returnedValue.preloadedData = std::shared_ptr<AudioBuffer<float>>(readFromFile<float>(sndFile, preloadedSize));
|
||||
preloadedData[filename] = returnedValue.preloadedData;
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public:
|
|||
double sampleRate { config::defaultSampleRate };
|
||||
std::shared_ptr<AudioBuffer<float>> preloadedData;
|
||||
};
|
||||
std::optional<FileInformation> getFileInformation(std::string_view filename) noexcept;
|
||||
std::optional<FileInformation> getFileInformation(std::string_view filename, uint32_t offset) noexcept;
|
||||
void enqueueLoading(Voice* voice, std::string_view sample, int numFrames, unsigned ticket) noexcept;
|
||||
private:
|
||||
std::filesystem::path rootDirectory;
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename)
|
|||
auto region = currentRegion->get();
|
||||
|
||||
if (!region->isGenerator()) {
|
||||
auto fileInformation = filePool.getFileInformation(region->sample);
|
||||
auto fileInformation = filePool.getFileInformation(region->sample, region->offset + region->offsetRandom);
|
||||
if (!fileInformation) {
|
||||
DBG("Removing the region with sample " << region->sample);
|
||||
std::iter_swap(currentRegion, lastRegion);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue