Continue integrating the preloading size and oversampling factor
This commit is contained in:
parent
630220e7e0
commit
d017a63a36
8 changed files with 72 additions and 48 deletions
|
|
@ -24,8 +24,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace sfz {
|
namespace sfz {
|
||||||
enum class Oversampling: int
|
enum Oversampling {
|
||||||
{
|
|
||||||
x1 = 1,
|
x1 = 1,
|
||||||
x2 = 2,
|
x2 = 2,
|
||||||
x4 = 4,
|
x4 = 4,
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ void sfz::FilePool::loadingThread() noexcept
|
||||||
if (sndFile.error() != 0)
|
if (sndFile.error() != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
DBG("Loading file for " << *promise->filename << " in the background");
|
DBG("Loading file for " << promise->filename << " in the background");
|
||||||
const uint32_t frames = sndFile.frames();
|
const uint32_t frames = sndFile.frames();
|
||||||
promise->fileData = readFromFile<float>(sndFile, frames);
|
promise->fileData = readFromFile<float>(sndFile, frames);
|
||||||
promise->dataReady = true;
|
promise->dataReady = true;
|
||||||
|
|
@ -179,3 +179,19 @@ void sfz::FilePool::cleanupPromises() noexcept
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void sfz::FilePool::setOversamplingFactor(sfz::Oversampling factor) noexcept
|
||||||
|
{
|
||||||
|
this->oversamplingFactor = factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
sfz::Oversampling sfz::FilePool::getOversamplingFactor() const noexcept
|
||||||
|
{
|
||||||
|
return oversamplingFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t sfz::FilePool::getPreloadSize() const noexcept
|
||||||
|
{
|
||||||
|
return preloadSize;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,9 @@ public:
|
||||||
void cleanupPromises() noexcept;
|
void cleanupPromises() noexcept;
|
||||||
FilePromisePtr getFilePromise(const std::string& filename) noexcept;
|
FilePromisePtr getFilePromise(const std::string& filename) noexcept;
|
||||||
void setPreloadSize(uint32_t preloadSize) noexcept;
|
void setPreloadSize(uint32_t preloadSize) noexcept;
|
||||||
|
uint32_t getPreloadSize() const noexcept;
|
||||||
|
void setOversamplingFactor(Oversampling factor) noexcept;
|
||||||
|
Oversampling getOversamplingFactor() const noexcept;
|
||||||
private:
|
private:
|
||||||
fs::path rootDirectory;
|
fs::path rootDirectory;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -644,9 +644,9 @@ float sfz::Region::getBaseGain() noexcept
|
||||||
return normalizePercents(amplitude);
|
return normalizePercents(amplitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t sfz::Region::getOffset() noexcept
|
uint32_t sfz::Region::getOffset(Oversampling factor) noexcept
|
||||||
{
|
{
|
||||||
return offset + offsetDistribution(Random::randomGenerator);
|
return (offset + offsetDistribution(Random::randomGenerator)) * factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
float sfz::Region::getDelay() noexcept
|
float sfz::Region::getDelay() noexcept
|
||||||
|
|
@ -654,9 +654,19 @@ float sfz::Region::getDelay() noexcept
|
||||||
return delay + delayDistribution(Random::randomGenerator);
|
return delay + delayDistribution(Random::randomGenerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t sfz::Region::trueSampleEnd() const noexcept
|
uint32_t sfz::Region::trueSampleEnd(Oversampling factor) const noexcept
|
||||||
{
|
{
|
||||||
return min(sampleEnd, loopRange.getEnd());
|
return min(sampleEnd, loopRange.getEnd()) * factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t sfz::Region::loopStart(Oversampling factor) const noexcept
|
||||||
|
{
|
||||||
|
return loopRange.getStart() * factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t sfz::Region::loopEnd(Oversampling factor) const noexcept
|
||||||
|
{
|
||||||
|
return loopRange.getEnd() * factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class U>
|
template<class T, class U>
|
||||||
|
|
@ -757,13 +767,3 @@ float sfz::Region::velocityCurve(uint8_t velocity) const noexcept
|
||||||
|
|
||||||
return gain;
|
return gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::Region::setOversamplingFactor(sfz::Oversampling factor) noexcept
|
|
||||||
{
|
|
||||||
oversamplingFactor = factor;
|
|
||||||
}
|
|
||||||
|
|
||||||
sfz::Oversampling sfz::Region::getOversamplingFactor() const noexcept
|
|
||||||
{
|
|
||||||
return oversamplingFactor;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,7 @@ struct Region {
|
||||||
*
|
*
|
||||||
* @return uint32_t
|
* @return uint32_t
|
||||||
*/
|
*/
|
||||||
uint32_t getOffset() noexcept;
|
uint32_t getOffset(Oversampling factor = x1) noexcept;
|
||||||
/**
|
/**
|
||||||
* @brief Get the region delay in seconds
|
* @brief Get the region delay in seconds
|
||||||
*
|
*
|
||||||
|
|
@ -214,14 +214,7 @@ struct Region {
|
||||||
*
|
*
|
||||||
* @return uint32_t
|
* @return uint32_t
|
||||||
*/
|
*/
|
||||||
uint32_t trueSampleEnd() const noexcept;
|
uint32_t trueSampleEnd(Oversampling factor = x1) const noexcept;
|
||||||
/**
|
|
||||||
* @brief Can the region use the preloaded data only to play its full range?
|
|
||||||
*
|
|
||||||
* @return true
|
|
||||||
* @return false
|
|
||||||
*/
|
|
||||||
bool canUsePreloadedData() const noexcept;
|
|
||||||
/**
|
/**
|
||||||
* @brief Parse a new opcode into the region to fill in the proper parameters.
|
* @brief Parse a new opcode into the region to fill in the proper parameters.
|
||||||
* This must be called multiple times for each opcode applying to this region.
|
* This must be called multiple times for each opcode applying to this region.
|
||||||
|
|
@ -232,21 +225,8 @@ struct Region {
|
||||||
*/
|
*/
|
||||||
bool parseOpcode(const Opcode& opcode);
|
bool parseOpcode(const Opcode& opcode);
|
||||||
|
|
||||||
/**
|
uint32_t loopStart(Oversampling factor = x1) const noexcept;
|
||||||
* @brief Set the oversampling factor to a new value. This will trigger updates of
|
uint32_t loopEnd(Oversampling factor = x1) const noexcept;
|
||||||
* all the relevant values (sample ends, loop points, etc). It will also trigger
|
|
||||||
* preloading the file data again.
|
|
||||||
*
|
|
||||||
* @param factor
|
|
||||||
*/
|
|
||||||
void setOversamplingFactor(Oversampling factor) noexcept;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief get the current oversampling factor
|
|
||||||
*
|
|
||||||
* @return Oversampling
|
|
||||||
*/
|
|
||||||
Oversampling getOversamplingFactor() const noexcept;
|
|
||||||
|
|
||||||
// Sound source: sample playback
|
// Sound source: sample playback
|
||||||
std::string sample {}; // Sample
|
std::string sample {}; // Sample
|
||||||
|
|
|
||||||
|
|
@ -550,10 +550,7 @@ void sfz::Synth::setOversamplingFactor(sfz::Oversampling factor) noexcept
|
||||||
for (auto& voice: voices)
|
for (auto& voice: voices)
|
||||||
voice->reset();
|
voice->reset();
|
||||||
|
|
||||||
for (auto& region: regions) {
|
resources.filePool.setOversamplingFactor(factor);
|
||||||
region->setOversamplingFactor(factor);
|
|
||||||
}
|
|
||||||
|
|
||||||
oversamplingFactor = factor;
|
oversamplingFactor = factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -561,3 +558,18 @@ sfz::Oversampling sfz::Synth::getOversamplingFactor() const noexcept
|
||||||
{
|
{
|
||||||
return oversamplingFactor;
|
return oversamplingFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sfz::Synth::setPreloadSize(uint32_t preloadSize) noexcept
|
||||||
|
{
|
||||||
|
AtomicDisabler callbackDisabler{ canEnterCallback };
|
||||||
|
while (inCallback) {
|
||||||
|
std::this_thread::sleep_for(1ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
resources.filePool.setPreloadSize(preloadSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t sfz::Synth::getPreloadSize() const noexcept
|
||||||
|
{
|
||||||
|
return resources.filePool.getPreloadSize();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -296,6 +296,20 @@ public:
|
||||||
* @return Oversampling
|
* @return Oversampling
|
||||||
*/
|
*/
|
||||||
Oversampling getOversamplingFactor() const noexcept;
|
Oversampling getOversamplingFactor() const noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the preloaded file size. This will disable the callback.
|
||||||
|
*
|
||||||
|
* @param factor
|
||||||
|
*/
|
||||||
|
void setPreloadSize(uint32_t preloadSize) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief get the current preloaded file size
|
||||||
|
*
|
||||||
|
* @return Oversampling
|
||||||
|
*/
|
||||||
|
uint32_t getPreloadSize() const noexcept;
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief The parser callback; this is called by the parent object each time
|
* @brief The parser callback; this is called by the parent object each time
|
||||||
|
|
|
||||||
|
|
@ -373,9 +373,9 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
|
||||||
add<int>(sourcePosition, indices);
|
add<int>(sourcePosition, indices);
|
||||||
|
|
||||||
//FIXME : all this casting is driving me crazy
|
//FIXME : all this casting is driving me crazy
|
||||||
const auto sampleEnd = min(static_cast<int>(region->trueSampleEnd()), static_cast<int>(source.getNumFrames())) - 1;
|
const auto sampleEnd = min(static_cast<size_t>(region->trueSampleEnd(currentPromise->oversamplingFactor)), source.getNumFrames()) - 1;
|
||||||
if (region->shouldLoop() && region->loopRange.getEnd() <= source.getNumFrames()) {
|
if (region->shouldLoop() && region->loopEnd(currentPromise->oversamplingFactor) <= source.getNumFrames()) {
|
||||||
const auto offset = sampleEnd - static_cast<int>(region->loopRange.getStart());
|
const auto offset = sampleEnd - static_cast<int>(region->loopStart(currentPromise->oversamplingFactor));
|
||||||
for (auto* index = indices.begin(); index < indices.end(); ++index) {
|
for (auto* index = indices.begin(); index < indices.end(); ++index) {
|
||||||
if (*index > sampleEnd) {
|
if (*index > sampleEnd) {
|
||||||
const auto remainingElements = static_cast<size_t>(std::distance(index, indices.end()));
|
const auto remainingElements = static_cast<size_t>(std::distance(index, indices.end()));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue