Added a method to FilePromise to get a data source
This commit is contained in:
parent
c0f1350cc4
commit
d1e031e8e2
2 changed files with 16 additions and 9 deletions
|
|
@ -47,10 +47,21 @@ struct PreloadedFileHandle
|
||||||
|
|
||||||
struct FilePromise
|
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 {};
|
absl::string_view filename {};
|
||||||
AudioBufferPtr preloadedData {};
|
AudioBufferPtr preloadedData {};
|
||||||
std::unique_ptr<AudioBuffer<float>> fileData {};
|
std::unique_ptr<AudioBuffer<float>> fileData {};
|
||||||
float sampleRate { config::defaultSampleRate };
|
float sampleRate { config::defaultSampleRate };
|
||||||
|
std::atomic<int> availableFrames { 0 };
|
||||||
std::atomic<bool> dataReady { false };
|
std::atomic<bool> dataReady { false };
|
||||||
Oversampling oversamplingFactor { config::defaultOversamplingFactor };
|
Oversampling oversamplingFactor { config::defaultOversamplingFactor };
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -374,16 +374,12 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
|
||||||
if (buffer.getNumFrames() == 0)
|
if (buffer.getNumFrames() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto source { [&]() {
|
if (currentPromise == nullptr) {
|
||||||
// if (region->trueSampleEnd() < currentPromise->preloadedData->getNumFrames())
|
DBG("[Voice] Missing promise during fillWithData");
|
||||||
// return AudioSpan<const float>(*currentPromise->preloadedData);
|
return;
|
||||||
// else
|
}
|
||||||
if (!currentPromise->dataReady)
|
|
||||||
return AudioSpan<const float>(*currentPromise->preloadedData);
|
|
||||||
else
|
|
||||||
return AudioSpan<const float>(*currentPromise->fileData);
|
|
||||||
}() };
|
|
||||||
|
|
||||||
|
auto source = currentPromise->getData();
|
||||||
auto indices = indexSpan.first(buffer.getNumFrames());
|
auto indices = indexSpan.first(buffer.getNumFrames());
|
||||||
auto jumps = tempSpan1.first(buffer.getNumFrames());
|
auto jumps = tempSpan1.first(buffer.getNumFrames());
|
||||||
auto bends = tempSpan2.first(buffer.getNumFrames());
|
auto bends = tempSpan2.first(buffer.getNumFrames());
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue