pub struct GainProcessor { /* private fields */ }Expand description
An audio processor that applies gain with smooth transitions.
GainProcessor implements the AudioProcessor trait and applies a gain factor
to audio samples. When the gain value changes, it smoothly transitions from the
current value to the new target using a simple one-pole low-pass filter, preventing
audible clicks and pops.
The gain value is read from an Arc<AtomicF32> that can be safely updated
from other threads (e.g., the UI thread) without requiring locks.
Implementations§
Source§impl GainProcessor
impl GainProcessor
Sourcepub fn new(gain: Arc<AtomicF32>) -> Self
pub fn new(gain: Arc<AtomicF32>) -> Self
Creates a new GainProcessor with the given atomic gain value.
Initializes the internal smoothing state (current) to the initial gain value
loaded from the atomic.
§Arguments
gain- AnArc<AtomicF32>that holds the target gain value. This value can be updated from other threads, and changes will be smoothly transitioned.
Trait Implementations§
Source§impl AudioProcessor for GainProcessor
impl AudioProcessor for GainProcessor
Source§fn process(&mut self, sample: f32) -> f32
fn process(&mut self, sample: f32) -> f32
Processes a single audio sample with the current gain factor.
Reads the target gain value from the atomic and smoothly transitions the internal state toward it using a one-pole smoothing algorithm.
§Gain Smoothing Visualization
The red line shows the instantaneous jump (Target), while the curve shows the gradual adjustment of the multiplier (Current).
§Arguments
sample- The input audio sample to be scaled by the gain.
§Returns
The gain-scaled audio sample.