From 3fdeb05e301bff6982f7d147c39601796efcdf47 Mon Sep 17 00:00:00 2001 From: Sami Perttu Date: Sat, 22 Jun 2024 10:44:12 +0300 Subject: [PATCH] Fix. --- CHANGES.md | 4 ++++ src/adsr.rs | 29 +++++++++++++---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9d96d2e..110ac45 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ ## Changes +### Version 0.18.1 + +- Denormal flushing was removed for now. + ### Version 0.18 - This release involves a major rewrite and many changes. diff --git a/src/adsr.rs b/src/adsr.rs index 92bca6e..0c28532 100644 --- a/src/adsr.rs +++ b/src/adsr.rs @@ -15,7 +15,7 @@ //! connected MIDI input device it finds, and play the corresponding pitches with the volume moderated by //! an `adsr_live()` envelope. -use super::prelude::{clamp01, envelope2, lerp, shared, var, An, EnvelopeIn, Frame, U1}; +use super::prelude::{clamp01, delerp, envelope2, lerp, shared, var, An, EnvelopeIn, Frame, U1}; use super::Float; pub fn adsr_live( @@ -26,23 +26,28 @@ pub fn adsr_live( ) -> An) -> f32 + Clone, U1, f32>> { let neg1 = -1.0; let zero = 0.0; - let a = shared(neg1); + let a = shared(zero); let b = shared(neg1); let attack_start = var(&a); let release_start = var(&b); envelope2(move |time, control| { - if attack_start.value() < zero && control > zero { + if release_start.value() >= zero && control > zero { attack_start.set_value(time); release_start.set_value(neg1); } else if release_start.value() < zero && control <= zero { release_start.set_value(time); - attack_start.set_value(neg1); } - clamp01(if release_start.value() < zero { - ads(attack, decay, sustain, time - attack_start.value()) + let ads_value = ads(attack, decay, sustain, time - attack_start.value()); + if release_start.value() < zero { + ads_value } else { - releasing(sustain, release, time - release_start.value()) - }) + ads_value + * clamp01(delerp( + release_start.value() + release, + release_start.value(), + time, + )) + } }) } @@ -58,11 +63,3 @@ fn ads(attack: F, decay: F, sustain: F, time: F) -> F { } } } - -fn releasing(sustain: F, release: F, release_time: F) -> F { - if release_time > release { - F::from_f64(0.0) - } else { - lerp(sustain, F::from_f64(0.0), release_time / release) - } -}