Skip to main content

SlewRateLimiter

Struct SlewRateLimiter 

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

Models op-amp slew rate limiting for physically accurate WDF processing.

Real op-amps have a finite maximum rate of output voltage change (dV/dt), measured in V/µs. When the signal demands a faster slew than the op-amp can deliver, the output “rounds off” — this is the mechanism behind the distinctive compression character of slow op-amps like the LM308 (RAT) versus fast ones like the TL072 (Klon).

The slew rate limiter operates as a per-sample voltage clamp on the derivative: |V[n] - V[n-1]| ≤ slew_rate * dt, where dt = 1/fs.

This is NOT a WDF root — it sits in the signal path between stages, modeling the op-amp’s output stage limitation. Thin wrapper over the shared [crate::stage::NonIdealFxState] dV/dt clamp.

Carries NO copy of the slew math: process delegates to NonIdealFxState::slew_step (the single source of truth) and only adds the finite guard. Only test code uses this type now — the live SPQR pipeline applies slew in-loop via NonIdealFxState directly.

Implementations§

§

impl SlewRateLimiter

pub fn new(slew_rate_v_per_us: f64, sample_rate: f64) -> SlewRateLimiter

Create a slew rate limiter from a slew rate in V/µs and sample rate.

Slew rate values from real op-amps:

  • LM308: 0.3 V/µs (the RAT’s character)
  • LM741: 0.5 V/µs (vintage slow)
  • JRC4558: 1.7 V/µs (Tube Screamer warmth)
  • NE5532: 9.0 V/µs (studio clean)
  • TL072: 13.0 V/µs (modern, transparent)
  • CA3080: 50.0 V/µs (OTA, essentially transparent)

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

Process one sample through the slew rate limiter.

If the requested voltage change exceeds what the op-amp can deliver in one sample period, the output is clamped to the maximum slew rate. This creates asymmetric HF compression — the exact behavior that makes the LM308 RAT sound different from a TL072 RAT.

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

Update sample rate and recompute max_dv.

pub fn reset(&mut self)

Reset internal state.

pub fn slew_rate(&self) -> f64

Get the slew rate in V/µs.

pub fn is_limiting(&self) -> bool

Check if slew limiting is currently active (for diagnostics).

Returns the ratio of actual dV to max_dv for the last sample. Values > 1.0 mean the limiter was engaged.

Trait Implementations§

§

impl Clone for SlewRateLimiter

§

fn clone(&self) -> SlewRateLimiter

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 Copy for SlewRateLimiter

§

impl Debug for SlewRateLimiter

§

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