Skip to main content

EnvelopeFollower

Struct EnvelopeFollower 

pub struct EnvelopeFollower { /* private fields */ }
Expand description

Envelope follower for dynamics-based modulation.

Tracks the amplitude envelope of an audio signal, producing a control signal for auto-wah, compressor side-chains, or dynamic modulation. Uses asymmetric attack/release smoothing for natural response.

Implementations§

§

impl EnvelopeFollower

pub fn new(sample_rate: f64) -> EnvelopeFollower

Create a new envelope follower with default parameters.

Default: 10ms attack, 100ms release, unity sensitivity.

pub fn from_rc( attack_r: f64, attack_c: f64, release_r: f64, release_c: f64, sensitivity_r: f64, sample_rate: f64, ) -> EnvelopeFollower

Create an envelope follower from physical RC timing components.

This mirrors real envelope detector circuits where attack and release time constants are set by RC networks, and sensitivity is set by an input gain resistor.

  • attack_r: Attack timing resistor (Ω)
  • attack_c: Attack timing capacitor (F)
  • release_r: Release timing resistor (Ω)
  • release_c: Release timing capacitor (F)
  • sensitivity_r: Sensitivity resistor (Ω) — gain = sensitivity_r / 10kΩ

Time constants: τ_attack = R_attack × C_attack (in seconds), τ_release = R_release × C_release (in seconds).

pub fn set_attack(&mut self, ms: f64)

Set attack time in milliseconds.

Shorter attack responds faster to transients but may track individual waveform cycles. Typical range: 1-50ms.

pub fn attack(&self) -> f64

Get current attack time in milliseconds.

pub fn set_release(&mut self, ms: f64)

Set release time in milliseconds.

Longer release gives smoother output but slower response to level drops. Typical range: 50-500ms.

pub fn release(&self) -> f64

Get current release time in milliseconds.

pub fn set_sensitivity(&mut self, sens: f64)

Set input sensitivity/gain.

Higher sensitivity amplifies the input before envelope detection, useful for low-level signals. Typical range: 0.5-5.0.

pub fn sensitivity(&self) -> f64

Get current sensitivity.

pub fn process(&mut self, input: f64) -> f64

Process one audio sample and return the envelope value.

The envelope tracks the rectified (absolute value) input with asymmetric attack/release smoothing. Output range is 0.0 upward, typically staying below 1.0 for normalized audio input.

pub fn envelope(&self) -> f64

Get current envelope value without processing new input.

pub fn reset(&mut self)

Reset envelope to zero.

pub fn set_sample_rate(&mut self, sample_rate: f64)

Update sample rate and recalculate coefficients.

Trait Implementations§

§

impl Clone for EnvelopeFollower

§

fn clone(&self) -> EnvelopeFollower

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for EnvelopeFollower

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more