Fix the value bounds in ADSR
This commit is contained in:
parent
8f81f6327d
commit
fb01fa7cfd
3 changed files with 16 additions and 13 deletions
|
|
@ -13,14 +13,17 @@ namespace sfz {
|
||||||
|
|
||||||
using Float = ADSREnvelope::Float;
|
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<int>(timeInSeconds * sampleRate);
|
return static_cast<int>(timeInSeconds * sampleRate);
|
||||||
};
|
};
|
||||||
|
|
||||||
Float ADSREnvelope::secondsToLinRate(Float timeInSeconds) const noexcept
|
Float ADSREnvelope::secondsToLinRate(Float timeInSeconds) const noexcept
|
||||||
{
|
{
|
||||||
if (timeInSeconds == 0)
|
if (timeInSeconds <= 0)
|
||||||
return Float(1);
|
return Float(1);
|
||||||
|
|
||||||
return 1 / (sampleRate * timeInSeconds);
|
return 1 / (sampleRate * timeInSeconds);
|
||||||
|
|
@ -28,7 +31,7 @@ Float ADSREnvelope::secondsToLinRate(Float timeInSeconds) const noexcept
|
||||||
|
|
||||||
Float ADSREnvelope::secondsToExpRate(Float timeInSeconds) const noexcept
|
Float ADSREnvelope::secondsToExpRate(Float timeInSeconds) const noexcept
|
||||||
{
|
{
|
||||||
if (timeInSeconds == 0)
|
if (timeInSeconds <= 0)
|
||||||
return Float(0.0);
|
return Float(0.0);
|
||||||
|
|
||||||
timeInSeconds = std::max(Float(25e-3), timeInSeconds);
|
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->decayRate = secondsToExpRate(desc.getDecay(state, velocity));
|
||||||
this->releaseRate = secondsToExpRate(desc.getRelease(state, velocity));
|
this->releaseRate = secondsToExpRate(desc.getRelease(state, velocity));
|
||||||
this->hold = secondsToSamples(desc.getHold(state, velocity));
|
this->hold = secondsToSamples(desc.getHold(state, velocity));
|
||||||
this->sustain = desc.getSustain(state, velocity);
|
this->sustain = clamp(desc.getSustain(state, velocity), 0.0f, 1.0f);
|
||||||
this->start = desc.getStart(state, velocity);
|
this->start = clamp(desc.getStart(state, velocity), 0.0f, 1.0f);
|
||||||
|
|
||||||
releaseDelay = 0;
|
releaseDelay = 0;
|
||||||
sustainThreshold = this->sustain + config::virtuallyZero;
|
sustainThreshold = this->sustain + config::virtuallyZero;
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float sampleRate { config::defaultSampleRate };
|
float sampleRate { config::defaultSampleRate };
|
||||||
Float secondsToSamples(Float timeInSeconds) const noexcept;
|
int secondsToSamples(Float timeInSeconds) const noexcept;
|
||||||
Float secondsToLinRate(Float timeInSeconds) const noexcept;
|
Float secondsToLinRate(Float timeInSeconds) const noexcept;
|
||||||
Float secondsToExpRate(Float timeInSeconds) const noexcept;
|
Float secondsToExpRate(Float timeInSeconds) const noexcept;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ struct EGDescription {
|
||||||
for (auto& mod: ccAttack) {
|
for (auto& mod: ccAttack) {
|
||||||
returnedValue += state.getCCValue(mod.cc) * mod.data;
|
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
|
* @brief Get the decay with possibly a CC modifier and a velocity modifier
|
||||||
|
|
@ -120,7 +120,7 @@ struct EGDescription {
|
||||||
for (auto& mod: ccDecay) {
|
for (auto& mod: ccDecay) {
|
||||||
returnedValue += state.getCCValue(mod.cc) * mod.data;
|
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
|
* @brief Get the delay with possibly a CC modifier and a velocity modifier
|
||||||
|
|
@ -136,7 +136,7 @@ struct EGDescription {
|
||||||
for (auto& mod: ccDelay) {
|
for (auto& mod: ccDelay) {
|
||||||
returnedValue += state.getCCValue(mod.cc) * mod.data;
|
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
|
* @brief Get the holding duration with possibly a CC modifier and a velocity modifier
|
||||||
|
|
@ -152,7 +152,7 @@ struct EGDescription {
|
||||||
for (auto& mod: ccHold) {
|
for (auto& mod: ccHold) {
|
||||||
returnedValue += state.getCCValue(mod.cc) * mod.data;
|
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
|
* @brief Get the release duration with possibly a CC modifier and a velocity modifier
|
||||||
|
|
@ -168,7 +168,7 @@ struct EGDescription {
|
||||||
for (auto& mod: ccRelease) {
|
for (auto& mod: ccRelease) {
|
||||||
returnedValue += state.getCCValue(mod.cc) * mod.data;
|
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
|
* @brief Get the starting level with possibly a CC modifier and a velocity modifier
|
||||||
|
|
@ -184,7 +184,7 @@ struct EGDescription {
|
||||||
for (auto& mod: ccStart) {
|
for (auto& mod: ccStart) {
|
||||||
returnedValue += state.getCCValue(mod.cc) * mod.data;
|
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
|
* @brief Get the sustain level with possibly a CC modifier and a velocity modifier
|
||||||
|
|
@ -200,7 +200,7 @@ struct EGDescription {
|
||||||
for (auto& mod: ccSustain) {
|
for (auto& mod: ccSustain) {
|
||||||
returnedValue += state.getCCValue(mod.cc) * mod.data;
|
returnedValue += state.getCCValue(mod.cc) * mod.data;
|
||||||
}
|
}
|
||||||
return Default::egPercent.bounds.clamp(returnedValue);
|
return returnedValue;
|
||||||
}
|
}
|
||||||
LEAK_DETECTOR(EGDescription);
|
LEAK_DETECTOR(EGDescription);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue