pub struct AdsrEnvelope { /* private fields */ }Expand description
A four-stage attack/decay/sustain/release amplitude envelope.
Segment lengths are stored in samples (derived from seconds × sample-rate at
construction). Attack ramps 0 → 1, decay ramps 1 → sustain, sustain holds,
and release ramps the level captured at note_off() down to 0.
Implementations§
Source§impl AdsrEnvelope
impl AdsrEnvelope
Sourcepub fn new(
sample_rate: f32,
attack_s: f32,
decay_s: f32,
sustain: f32,
release_s: f32,
) -> Self
pub fn new( sample_rate: f32, attack_s: f32, decay_s: f32, sustain: f32, release_s: f32, ) -> Self
Build an envelope. Times are in seconds; sustain is a 0..=1 level.
Non-finite / negative inputs are clamped to safe values.
Sourcepub fn note_on(&mut self)
pub fn note_on(&mut self)
Trigger the envelope: enter the attack stage (rising from the current level).
Sourcepub fn note_off(&mut self)
pub fn note_off(&mut self)
Release the envelope: ramp the current level down to zero over the release time.
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
true while the envelope is producing (or will produce) a non-zero contribution.
Sourcepub fn sustain_level(&self) -> f32
pub fn sustain_level(&self) -> f32
Current sustain level (0..=1).
Sourcepub fn process_sample(&mut self) -> f32
pub fn process_sample(&mut self) -> f32
Advance one sample and return the current gain in 0.0..=1.0.
Trait Implementations§
Source§impl Clone for AdsrEnvelope
impl Clone for AdsrEnvelope
impl Copy for AdsrEnvelope
Auto Trait Implementations§
impl Freeze for AdsrEnvelope
impl RefUnwindSafe for AdsrEnvelope
impl Send for AdsrEnvelope
impl Sync for AdsrEnvelope
impl Unpin for AdsrEnvelope
impl UnsafeUnpin for AdsrEnvelope
impl UnwindSafe for AdsrEnvelope
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more