Used clamp int64 and get the modified offsets in getOffset()

This commit is contained in:
Paul Fd 2020-04-07 17:55:22 +02:00 committed by Jean Pierre Cimalando
parent 02ad421fa3
commit 7a59b35b80
4 changed files with 15 additions and 15 deletions

View file

@ -46,10 +46,10 @@ namespace Default
constexpr float delay { 0.0 };
constexpr float delayRandom { 0.0 };
constexpr Range<float> delayRange { 0.0, 100.0 };
constexpr uint32_t offset { 0 };
constexpr uint32_t offsetRandom { 0 };
constexpr Range<uint32_t> offsetRange { 0, std::numeric_limits<uint32_t>::max() };
constexpr Range<uint32_t> offsetCCRange = offsetRange;
constexpr int64_t offset { 0 };
constexpr int64_t offsetRandom { 0 };
constexpr Range<int64_t> offsetRange { 0, std::numeric_limits<uint32_t>::max() };
constexpr Range<int64_t> offsetCCRange = offsetRange;
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 SfzLoopMode loopMode { SfzLoopMode::no_loop };

View file

@ -1140,10 +1140,13 @@ float sfz::Region::getPhase() const noexcept
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 };
return (offset + offsetDistribution(Random::randomGenerator)) * static_cast<uint32_t>(factor);
std::uniform_int_distribution<int64_t> offsetDistribution { 0, offsetRandom };
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

View file

@ -189,7 +189,7 @@ struct Region {
*
* @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
*
@ -230,9 +230,9 @@ struct Region {
std::string sample {}; // Sample
float delay { Default::delay }; // delay
float delayRandom { Default::delayRandom }; // delay_random
uint32_t offset { Default::offset }; // offset
uint32_t offsetRandom { Default::offsetRandom }; // offset_random
CCMap<uint32_t> offsetCC { Default::offset };
int64_t offset { Default::offset }; // offset
int64_t offsetRandom { Default::offsetRandom }; // offset_random
CCMap<int64_t> offsetCC { Default::offset };
uint32_t sampleEnd { Default::sampleEndRange.getEnd() }; // end
absl::optional<uint32_t> sampleCount {}; // count
absl::optional<SfzLoopMode> loopMode {}; // loopmode

View file

@ -378,10 +378,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& file)
uint64_t sumOffsetCC = region->offset + region->offsetRandom;
for (const auto& offsets: region->offsetCC)
sumOffsetCC += offsets.value;
if (static_cast<uint64_t>(Default::offsetCCRange.getEnd()) < sumOffsetCC)
return Default::offsetCCRange.getEnd();
return static_cast<uint32_t>(sumOffsetCC);
return Default::offsetCCRange.clamp(sumOffsetCC);
}();
if (!resources.filePool.preloadFile(region->sample, maxOffset))