Fix attack/decay interpolation (#114)

This commit is contained in:
Ricardo Matias
2020-05-22 20:10:41 +02:00
committed by GitHub
parent 184d4fb371
commit 9cb4114ccf

View File

@@ -95,27 +95,19 @@ class Envelope(
}
if (phase == EnvelopePhase.Attack) {
current = if (attack == 0.0) {
targetValue
} else {
val t = clamp(cycleTime / attack, 0.0, 1.0)
val denom = if (attack == 0.0) 1.0 else attack
mix(restValue, targetValue, exponentialEasing(t, easingFactor))
}
val t = clamp(cycleTime / denom, 0.0, 1.0)
current = mix(restValue, targetValue, exponentialEasing(t, easingFactor))
}
if (phase == EnvelopePhase.Decay) {
current = if (decay == 0.0) {
initialRestValue
} else {
val t = clamp((cycleTime - attack) / decay, 0.0, 1.0)
val denom = if (decay == 0.0) 1.0 else decay
mix(targetValue, initialRestValue, exponentialEasing(t, easingFactor))
}
}
val t = clamp((cycleTime - attack) / denom, 0.0, 1.0)
if (current.isNaN()) {
println("current is NaN, $phase")
current = mix(targetValue, initialRestValue, exponentialEasing(t, easingFactor))
}
}