Used clamp int64 and get the modified offsets in getOffset()
This commit is contained in:
parent
02ad421fa3
commit
7a59b35b80
4 changed files with 15 additions and 15 deletions
|
|
@ -46,10 +46,10 @@ namespace Default
|
||||||
constexpr float delay { 0.0 };
|
constexpr float delay { 0.0 };
|
||||||
constexpr float delayRandom { 0.0 };
|
constexpr float delayRandom { 0.0 };
|
||||||
constexpr Range<float> delayRange { 0.0, 100.0 };
|
constexpr Range<float> delayRange { 0.0, 100.0 };
|
||||||
constexpr uint32_t offset { 0 };
|
constexpr int64_t offset { 0 };
|
||||||
constexpr uint32_t offsetRandom { 0 };
|
constexpr int64_t offsetRandom { 0 };
|
||||||
constexpr Range<uint32_t> offsetRange { 0, std::numeric_limits<uint32_t>::max() };
|
constexpr Range<int64_t> offsetRange { 0, std::numeric_limits<uint32_t>::max() };
|
||||||
constexpr Range<uint32_t> offsetCCRange = offsetRange;
|
constexpr Range<int64_t> offsetCCRange = offsetRange;
|
||||||
constexpr Range<uint32_t> sampleEndRange { 0, std::numeric_limits<uint32_t>::max() };
|
constexpr Range<uint32_t> sampleEndRange { 0, std::numeric_limits<uint32_t>::max() };
|
||||||
constexpr Range<uint32_t> sampleCountRange { 0, std::numeric_limits<uint32_t>::max() };
|
constexpr Range<uint32_t> sampleCountRange { 0, std::numeric_limits<uint32_t>::max() };
|
||||||
constexpr SfzLoopMode loopMode { SfzLoopMode::no_loop };
|
constexpr SfzLoopMode loopMode { SfzLoopMode::no_loop };
|
||||||
|
|
|
||||||
|
|
@ -1140,10 +1140,13 @@ float sfz::Region::getPhase() const noexcept
|
||||||
return phase;
|
return phase;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t sfz::Region::getOffset(Oversampling factor) const noexcept
|
uint64_t sfz::Region::getOffset(Oversampling factor) const noexcept
|
||||||
{
|
{
|
||||||
std::uniform_int_distribution<uint32_t> offsetDistribution { 0, offsetRandom };
|
std::uniform_int_distribution<int64_t> offsetDistribution { 0, offsetRandom };
|
||||||
return (offset + offsetDistribution(Random::randomGenerator)) * static_cast<uint32_t>(factor);
|
uint64_t finalOffset = offset + offsetDistribution(Random::randomGenerator);
|
||||||
|
for (const auto& mod: offsetCC)
|
||||||
|
finalOffset += static_cast<uint64_t>(mod.value * midiState.getCCValue(mod.cc));
|
||||||
|
return Default::offsetCCRange.clamp(offset + offsetDistribution(Random::randomGenerator)) * static_cast<uint64_t>(factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
float sfz::Region::getDelay() const noexcept
|
float sfz::Region::getDelay() const noexcept
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ struct Region {
|
||||||
*
|
*
|
||||||
* @return uint32_t
|
* @return uint32_t
|
||||||
*/
|
*/
|
||||||
uint32_t getOffset(Oversampling factor = Oversampling::x1) const noexcept;
|
uint64_t getOffset(Oversampling factor = Oversampling::x1) const noexcept;
|
||||||
/**
|
/**
|
||||||
* @brief Get the region delay in seconds
|
* @brief Get the region delay in seconds
|
||||||
*
|
*
|
||||||
|
|
@ -230,9 +230,9 @@ struct Region {
|
||||||
std::string sample {}; // Sample
|
std::string sample {}; // Sample
|
||||||
float delay { Default::delay }; // delay
|
float delay { Default::delay }; // delay
|
||||||
float delayRandom { Default::delayRandom }; // delay_random
|
float delayRandom { Default::delayRandom }; // delay_random
|
||||||
uint32_t offset { Default::offset }; // offset
|
int64_t offset { Default::offset }; // offset
|
||||||
uint32_t offsetRandom { Default::offsetRandom }; // offset_random
|
int64_t offsetRandom { Default::offsetRandom }; // offset_random
|
||||||
CCMap<uint32_t> offsetCC { Default::offset };
|
CCMap<int64_t> offsetCC { Default::offset };
|
||||||
uint32_t sampleEnd { Default::sampleEndRange.getEnd() }; // end
|
uint32_t sampleEnd { Default::sampleEndRange.getEnd() }; // end
|
||||||
absl::optional<uint32_t> sampleCount {}; // count
|
absl::optional<uint32_t> sampleCount {}; // count
|
||||||
absl::optional<SfzLoopMode> loopMode {}; // loopmode
|
absl::optional<SfzLoopMode> loopMode {}; // loopmode
|
||||||
|
|
|
||||||
|
|
@ -378,10 +378,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& file)
|
||||||
uint64_t sumOffsetCC = region->offset + region->offsetRandom;
|
uint64_t sumOffsetCC = region->offset + region->offsetRandom;
|
||||||
for (const auto& offsets: region->offsetCC)
|
for (const auto& offsets: region->offsetCC)
|
||||||
sumOffsetCC += offsets.value;
|
sumOffsetCC += offsets.value;
|
||||||
if (static_cast<uint64_t>(Default::offsetCCRange.getEnd()) < sumOffsetCC)
|
return Default::offsetCCRange.clamp(sumOffsetCC);
|
||||||
return Default::offsetCCRange.getEnd();
|
|
||||||
|
|
||||||
return static_cast<uint32_t>(sumOffsetCC);
|
|
||||||
}();
|
}();
|
||||||
|
|
||||||
if (!resources.filePool.preloadFile(region->sample, maxOffset))
|
if (!resources.filePool.preloadFile(region->sample, maxOffset))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue