From d1e031e8e2b02cdc9b60656241dcea56092fc8a5 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 22 Dec 2019 18:39:05 +0100 Subject: [PATCH] Added a method to FilePromise to get a data source --- src/sfizz/FilePool.h | 11 +++++++++++ src/sfizz/Voice.cpp | 14 +++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/sfizz/FilePool.h b/src/sfizz/FilePool.h index 9d54fd6d..679526e1 100644 --- a/src/sfizz/FilePool.h +++ b/src/sfizz/FilePool.h @@ -47,10 +47,21 @@ struct PreloadedFileHandle struct FilePromise { + auto getData() + { + if (dataReady) + return AudioSpan(*fileData); + else if (availableFrames > preloadedData->getNumFrames()) + return AudioSpan(*fileData).first(availableFrames); + else + return AudioSpan(*preloadedData); + } + absl::string_view filename {}; AudioBufferPtr preloadedData {}; std::unique_ptr> fileData {}; float sampleRate { config::defaultSampleRate }; + std::atomic availableFrames { 0 }; std::atomic dataReady { false }; Oversampling oversamplingFactor { config::defaultOversamplingFactor }; }; diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index ce0ffd1d..227dc2e3 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -374,16 +374,12 @@ void sfz::Voice::fillWithData(AudioSpan buffer) noexcept if (buffer.getNumFrames() == 0) return; - auto source { [&]() { - // if (region->trueSampleEnd() < currentPromise->preloadedData->getNumFrames()) - // return AudioSpan(*currentPromise->preloadedData); - // else - if (!currentPromise->dataReady) - return AudioSpan(*currentPromise->preloadedData); - else - return AudioSpan(*currentPromise->fileData); - }() }; + if (currentPromise == nullptr) { + DBG("[Voice] Missing promise during fillWithData"); + return; + } + auto source = currentPromise->getData(); auto indices = indexSpan.first(buffer.getNumFrames()); auto jumps = tempSpan1.first(buffer.getNumFrames()); auto bends = tempSpan2.first(buffer.getNumFrames());