Skip to main content

DynamicsCore

Struct DynamicsCore 

Source
pub struct DynamicsCore { /* private fields */ }
Expand description

Shared dynamics processor used by both compressor and expander, single-band and multiband. Each band in a multiband plugin gets its own DynamicsCore instance.

Implementations§

Source§

impl DynamicsCore

Source

pub fn new(mode: DynamicsMode, channels: usize, sample_rate: u32) -> Self

Create a new dynamics core processor.

Pre-allocates all Vecs. Initializes coefficients for the given sample rate. LookaheadBuffer is sized for max 20ms capacity.

Source

pub fn initialize(&mut self, sample_rate: u32)

Update sample rate and recompute all derived coefficients.

Resizes level detectors and lookahead buffer for new sample rate.

Source

pub fn reset(&mut self)

Zero all state: envelopes, gate states, hold counters, HPF biquad states, level detectors, lookahead buffer.

Source

pub fn set_attack_release(&mut self, attack_ms: f32, release_ms: f32)

Update attack and release time constants.

Also updates dual release times (slow = release * 4.0).

Source

pub fn set_sidechain_hpf(&mut self, freq_hz: f32, order_index: usize)

Rebuild sidechain HPF biquad cascade using peq_butterworth_highpass().

Same Butterworth cascade pattern as the compressor plugin.

Source

pub fn set_sidechain_tilt(&mut self, tilt_db: f32)

Set a spectral tilt filter on the sidechain detection path.

tilt_db: positive values weight HF more heavily (e.g., +3 dB makes the compressor more sensitive to high frequencies). Negative values weight LF. Implemented as a 1st-order high-shelf at 1 kHz.

Source

pub fn set_sidechain_filter(&mut self, mode: SidechainFilterMode)

Set sidechain filter using the unified enum.

Source

pub fn set_detection_mode(&mut self, mode_index: usize)

Set detection mode: 0=peak, 1=RMS. Reinitializes level detectors.

Source

pub fn set_lookahead_ms(&mut self, ms: f32)

Update the lookahead delay.

Source

pub fn set_program_dependent_release(&mut self, enabled: bool)

Enable or disable program-dependent release (compress mode only).

Source

pub fn set_expand_params( &mut self, hysteresis_db: f32, hold_ms: f32, range_db: f32, )

Set expand-mode parameters: hysteresis, hold, and range.

Source

pub fn mode(&self) -> DynamicsMode

Get the dynamics mode.

Source

pub fn channels(&self) -> usize

Get the number of channels.

Source

pub fn apply_sidechain_filter(&mut self, ch: usize, sample: f32) -> f32

Run the sidechain filter (HPF or Tilt) for this channel.

Returns the filtered sample. If no sidechain filter is active, returns the input sample unchanged.

Source

pub fn detect_level(&mut self, ch: usize, sample: f32) -> f32

Detect level for one sample on a channel.

Peak mode returns abs(sample). RMS mode uses the LevelDetector’s sliding window and returns the linear RMS amplitude.

Source

pub fn calculate_gain_reduction( &self, input_db: f32, threshold: f32, ratio: f32, knee_db: f32, ) -> f32

Calculate gain reduction/expansion attenuation for the given input level.

For Compress mode: standard soft-knee gain reduction (above threshold). For Expand mode: expansion attenuation (below threshold), capped by range_db.

Source

pub fn apply_envelope(&mut self, ch: usize, target_gr: f32) -> f32

Apply one-pole attack/release envelope smoothing.

For compress mode with program_dependent_release enabled, uses DualRelease for the release coefficient. Returns the smoothed gain reduction in dB.

Source

pub fn process_gate_state( &mut self, ch: usize, input_db: f32, threshold: f32, ratio: f32, knee_db: f32, ) -> f32

Process the 3-state gate machine for expansion mode.

Implements Open/Hold/Closing transitions with hysteresis. Returns the target attenuation in dB (0.0 when gate is open, or the expansion attenuation when gate is closing).

This method integrates the gate state machine AND the expansion attenuation calculation, matching the expander plugin’s process_channel pattern.

Source

pub fn envelope_db(&self, ch: usize) -> f32

Get the current envelope value (gain reduction in dB) for a channel.

Source

pub fn measured_makeup_db(&self) -> f32

Get the measured makeup gain in dB.

Source

pub fn measured_makeup_linear(&self) -> f32

Get the measured makeup gain as a linear multiplier.

Source

pub fn update_measured_makeup(&mut self, gain_reduction: f32)

Update the measured makeup tracker with the current gain reduction.

Source

pub fn lookahead_process_frame(&mut self, input: &[f32], output: &mut [f32])

Push one interleaved frame into the lookahead buffer, get the delayed frame out. input and output must have channels elements.

Source

pub fn lookahead_delay_samples(&self) -> usize

Returns the current lookahead delay in samples.

Source

pub fn lookahead_frame_buf(&mut self) -> &mut [f32]

Get a mutable reference to the lookahead frame buffer (pre-allocated).

This buffer has channels elements and is used to avoid per-frame allocation when processing lookahead.

Source

pub fn gate_state(&self, ch: usize) -> GateState

Get the current gate state for a channel (expand mode only).

Source

pub fn range_db(&self) -> f32

Get the range_db value (expand mode only).

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.