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
impl DynamicsCore
Sourcepub fn new(mode: DynamicsMode, channels: usize, sample_rate: u32) -> Self
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.
Sourcepub fn initialize(&mut self, sample_rate: u32)
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.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Zero all state: envelopes, gate states, hold counters, HPF biquad states, level detectors, lookahead buffer.
Sourcepub fn set_attack_release(&mut self, attack_ms: f32, release_ms: f32)
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).
Sourcepub fn set_sidechain_hpf(&mut self, freq_hz: f32, order_index: usize)
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.
Sourcepub fn set_sidechain_tilt(&mut self, tilt_db: f32)
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.
Sourcepub fn set_sidechain_filter(&mut self, mode: SidechainFilterMode)
pub fn set_sidechain_filter(&mut self, mode: SidechainFilterMode)
Set sidechain filter using the unified enum.
Sourcepub fn set_detection_mode(&mut self, mode_index: usize)
pub fn set_detection_mode(&mut self, mode_index: usize)
Set detection mode: 0=peak, 1=RMS. Reinitializes level detectors.
Sourcepub fn set_lookahead_ms(&mut self, ms: f32)
pub fn set_lookahead_ms(&mut self, ms: f32)
Update the lookahead delay.
Sourcepub fn set_program_dependent_release(&mut self, enabled: bool)
pub fn set_program_dependent_release(&mut self, enabled: bool)
Enable or disable program-dependent release (compress mode only).
Sourcepub fn set_expand_params(
&mut self,
hysteresis_db: f32,
hold_ms: f32,
range_db: f32,
)
pub fn set_expand_params( &mut self, hysteresis_db: f32, hold_ms: f32, range_db: f32, )
Set expand-mode parameters: hysteresis, hold, and range.
Sourcepub fn mode(&self) -> DynamicsMode
pub fn mode(&self) -> DynamicsMode
Get the dynamics mode.
Sourcepub fn apply_sidechain_filter(&mut self, ch: usize, sample: f32) -> f32
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.
Sourcepub fn detect_level(&mut self, ch: usize, sample: f32) -> f32
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.
Sourcepub fn calculate_gain_reduction(
&self,
input_db: f32,
threshold: f32,
ratio: f32,
knee_db: f32,
) -> f32
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.
Sourcepub fn apply_envelope(&mut self, ch: usize, target_gr: f32) -> f32
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.
Sourcepub fn process_gate_state(
&mut self,
ch: usize,
input_db: f32,
threshold: f32,
ratio: f32,
knee_db: f32,
) -> f32
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.
Sourcepub fn envelope_db(&self, ch: usize) -> f32
pub fn envelope_db(&self, ch: usize) -> f32
Get the current envelope value (gain reduction in dB) for a channel.
Sourcepub fn measured_makeup_db(&self) -> f32
pub fn measured_makeup_db(&self) -> f32
Get the measured makeup gain in dB.
Sourcepub fn measured_makeup_linear(&self) -> f32
pub fn measured_makeup_linear(&self) -> f32
Get the measured makeup gain as a linear multiplier.
Sourcepub fn update_measured_makeup(&mut self, gain_reduction: f32)
pub fn update_measured_makeup(&mut self, gain_reduction: f32)
Update the measured makeup tracker with the current gain reduction.
Sourcepub fn lookahead_process_frame(&mut self, input: &[f32], output: &mut [f32])
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.
Sourcepub fn lookahead_delay_samples(&self) -> usize
pub fn lookahead_delay_samples(&self) -> usize
Returns the current lookahead delay in samples.
Sourcepub fn lookahead_frame_buf(&mut self) -> &mut [f32]
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.
Sourcepub fn gate_state(&self, ch: usize) -> GateState
pub fn gate_state(&self, ch: usize) -> GateState
Get the current gate state for a channel (expand mode only).
Auto Trait Implementations§
impl Freeze for DynamicsCore
impl RefUnwindSafe for DynamicsCore
impl Send for DynamicsCore
impl Sync for DynamicsCore
impl Unpin for DynamicsCore
impl UnsafeUnpin for DynamicsCore
impl UnwindSafe for DynamicsCore
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.