diff --git a/src/sfizz/ADSREnvelope.cpp b/src/sfizz/ADSREnvelope.cpp index 311e7b2c..9a99a412 100644 --- a/src/sfizz/ADSREnvelope.cpp +++ b/src/sfizz/ADSREnvelope.cpp @@ -13,14 +13,17 @@ namespace sfz { using Float = ADSREnvelope::Float; -Float ADSREnvelope::secondsToSamples(Float timeInSeconds) const noexcept +int ADSREnvelope::secondsToSamples(Float timeInSeconds) const noexcept { + if (timeInSeconds <= 0) + return Float(0); + return static_cast(timeInSeconds * sampleRate); }; Float ADSREnvelope::secondsToLinRate(Float timeInSeconds) const noexcept { - if (timeInSeconds == 0) + if (timeInSeconds <= 0) return Float(1); return 1 / (sampleRate * timeInSeconds); @@ -28,7 +31,7 @@ Float ADSREnvelope::secondsToLinRate(Float timeInSeconds) const noexcept Float ADSREnvelope::secondsToExpRate(Float timeInSeconds) const noexcept { - if (timeInSeconds == 0) + if (timeInSeconds <= 0) return Float(0.0); timeInSeconds = std::max(Float(25e-3), timeInSeconds); @@ -44,8 +47,8 @@ void ADSREnvelope::reset(const EGDescription& desc, const Region& region, const this->decayRate = secondsToExpRate(desc.getDecay(state, velocity)); this->releaseRate = secondsToExpRate(desc.getRelease(state, velocity)); this->hold = secondsToSamples(desc.getHold(state, velocity)); - this->sustain = desc.getSustain(state, velocity); - this->start = desc.getStart(state, velocity); + this->sustain = clamp(desc.getSustain(state, velocity), 0.0f, 1.0f); + this->start = clamp(desc.getStart(state, velocity), 0.0f, 1.0f); releaseDelay = 0; sustainThreshold = this->sustain + config::virtuallyZero; diff --git a/src/sfizz/ADSREnvelope.h b/src/sfizz/ADSREnvelope.h index 341ec021..f1d3d668 100644 --- a/src/sfizz/ADSREnvelope.h +++ b/src/sfizz/ADSREnvelope.h @@ -72,7 +72,7 @@ public: private: float sampleRate { config::defaultSampleRate }; - Float secondsToSamples(Float timeInSeconds) const noexcept; + int secondsToSamples(Float timeInSeconds) const noexcept; Float secondsToLinRate(Float timeInSeconds) const noexcept; Float secondsToExpRate(Float timeInSeconds) const noexcept; diff --git a/src/sfizz/EGDescription.h b/src/sfizz/EGDescription.h index a646dfb1..26202ff1 100644 --- a/src/sfizz/EGDescription.h +++ b/src/sfizz/EGDescription.h @@ -104,7 +104,7 @@ struct EGDescription { for (auto& mod: ccAttack) { returnedValue += state.getCCValue(mod.cc) * mod.data; } - return Default::egTime.bounds.clamp(returnedValue); + return returnedValue; } /** * @brief Get the decay with possibly a CC modifier and a velocity modifier @@ -120,7 +120,7 @@ struct EGDescription { for (auto& mod: ccDecay) { returnedValue += state.getCCValue(mod.cc) * mod.data; } - return Default::egTime.bounds.clamp(returnedValue); + return returnedValue; } /** * @brief Get the delay with possibly a CC modifier and a velocity modifier @@ -136,7 +136,7 @@ struct EGDescription { for (auto& mod: ccDelay) { returnedValue += state.getCCValue(mod.cc) * mod.data; } - return Default::egTime.bounds.clamp(returnedValue); + return returnedValue; } /** * @brief Get the holding duration with possibly a CC modifier and a velocity modifier @@ -152,7 +152,7 @@ struct EGDescription { for (auto& mod: ccHold) { returnedValue += state.getCCValue(mod.cc) * mod.data; } - return Default::egTime.bounds.clamp(returnedValue); + return returnedValue; } /** * @brief Get the release duration with possibly a CC modifier and a velocity modifier @@ -168,7 +168,7 @@ struct EGDescription { for (auto& mod: ccRelease) { returnedValue += state.getCCValue(mod.cc) * mod.data; } - return Default::egTime.bounds.clamp(returnedValue); + return returnedValue; } /** * @brief Get the starting level with possibly a CC modifier and a velocity modifier @@ -184,7 +184,7 @@ struct EGDescription { for (auto& mod: ccStart) { returnedValue += state.getCCValue(mod.cc) * mod.data; } - return Default::egPercent.bounds.clamp(returnedValue); + return returnedValue; } /** * @brief Get the sustain level with possibly a CC modifier and a velocity modifier @@ -200,7 +200,7 @@ struct EGDescription { for (auto& mod: ccSustain) { returnedValue += state.getCCValue(mod.cc) * mod.data; } - return Default::egPercent.bounds.clamp(returnedValue); + return returnedValue; } LEAK_DETECTOR(EGDescription); };