Added a method to FilePromise to get a data source

This commit is contained in:
Paul Ferrand 2019-12-22 18:39:05 +01:00
parent c0f1350cc4
commit d1e031e8e2
2 changed files with 16 additions and 9 deletions

View file

@ -47,10 +47,21 @@ struct PreloadedFileHandle
struct FilePromise
{
auto getData()
{
if (dataReady)
return AudioSpan<const float>(*fileData);
else if (availableFrames > preloadedData->getNumFrames())
return AudioSpan<const float>(*fileData).first(availableFrames);
else
return AudioSpan<const float>(*preloadedData);
}
absl::string_view filename {};
AudioBufferPtr preloadedData {};
std::unique_ptr<AudioBuffer<float>> fileData {};
float sampleRate { config::defaultSampleRate };
std::atomic<int> availableFrames { 0 };
std::atomic<bool> dataReady { false };
Oversampling oversamplingFactor { config::defaultOversamplingFactor };
};

View file

@ -374,16 +374,12 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
if (buffer.getNumFrames() == 0)
return;
auto source { [&]() {
// if (region->trueSampleEnd() < currentPromise->preloadedData->getNumFrames())
// return AudioSpan<const float>(*currentPromise->preloadedData);
// else
if (!currentPromise->dataReady)
return AudioSpan<const float>(*currentPromise->preloadedData);
else
return AudioSpan<const float>(*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());