pub struct Normalizer { /* private fields */ }Expand description
Stateful two-stage converter that normalizes input device frames to the internal canonical form (48k/stereo/960 frames), then converts them to one or more output taps (primary and optional secondary).
Stage 1 (internal normalization) runs once and feeds the resulting canonical form to stage 2
of both taps. An optional InnerProcessor is applied once to the canonical form before it
is split for stage 2, so both taps receive the same processed audio.
Accumulate interleaved samples with push, then retrieve completed output chunks one at a
time with pop_chunk (primary) and pop_secondary (secondary).
Implementations§
Source§impl Normalizer
impl Normalizer
Sourcepub fn new(
in_sample_rate: u32,
in_channels: u16,
output: OutputFormat,
) -> Result<Self>
pub fn new( in_sample_rate: u32, in_channels: u16, output: OutputFormat, ) -> Result<Self>
Create a normalizer for the input sample rate, input channel count, and output format.
Stage 1 normalizes input to 48k/stereo (in_sample_rate == 48000 bypasses sample-rate
conversion; in_channels of 1 duplicates mono to stereo, 2 is unchanged, and 3 or more
uses the front two channels). Stage 2 converts the canonical form to output (passthrough
when output == {48000, 2}).
Expects the caller to have run OutputFormat::validate on output (this method does not
clamp it to a valid range).
rubato resampler construction can fail, for example with extreme rate ratios. Panicking
would silently stop the non-RT capture thread, so failures return Error::Backend and
propagate to the caller.
Sourcepub fn with_secondary(self, secondary: OutputFormat) -> Result<Self>
pub fn with_secondary(self, secondary: OutputFormat) -> Result<Self>
Add a secondary output tap (expects OutputFormat::validate to have been called).
The internal canonical form (48k/stereo) is generated once and fed to stage 2 of both taps.
The secondary tap has independent stage 2 and PTS state, and emits its own fixed 20ms chunks.
rubato construction failures return Error::Backend.
Sourcepub fn with_inner_processor(self, processor: Box<dyn InnerProcessor>) -> Self
pub fn with_inner_processor(self, processor: Box<dyn InnerProcessor>) -> Self
Inject a processor to apply once to the internal canonical form before the stage 2 split.
Sourcepub fn in_sample_rate(&self) -> u32
pub fn in_sample_rate(&self) -> u32
Input sample rate (Hz).
Sourcepub fn output(&self) -> OutputFormat
pub fn output(&self) -> OutputFormat
Primary output format.
Sourcepub fn secondary_output(&self) -> Option<OutputFormat>
pub fn secondary_output(&self) -> Option<OutputFormat>
Secondary output format (only when a secondary tap is configured).
Sourcepub fn has_secondary(&self) -> bool
pub fn has_secondary(&self) -> bool
Whether a secondary tap is enabled.
Sourcepub fn is_passthrough(&self) -> bool
pub fn is_passthrough(&self) -> bool
Whether stage 1 sample-rate conversion is bypassed (in == 48000).
Sourcepub fn is_output_passthrough(&self) -> bool
pub fn is_output_passthrough(&self) -> bool
Whether stage 2 for the primary output is fully bypassed (output == {48000, 2}).
Sourcepub fn push(&mut self, interleaved: &[f32], device_pts_ns: i64) -> Result<()>
pub fn push(&mut self, interleaved: &[f32], device_pts_ns: i64) -> Result<()>
Accumulate interleaved input samples.
interleaved must have a length divisible by in_channels. device_pts_ns is the
device-provided PTS for the first frame in this push.
Returns Error::Backend if rubato’s process fails. This avoids silently stopping the
capture thread with a panic and lets the caller stop the stream explicitly.
Sourcepub fn pop_chunk(&mut self) -> Option<(Vec<f32>, i64)>
pub fn pop_chunk(&mut self) -> Option<(Vec<f32>, i64)>
Retrieve one completed primary output chunk.
Returns (out_chunk_frames interleaved frames at output.channels, PTS in ns for the
first sample). Returns None if a full chunk is not buffered.
Sourcepub fn pop_secondary(&mut self) -> Option<(Vec<f32>, i64)>
pub fn pop_secondary(&mut self) -> Option<(Vec<f32>, i64)>
Retrieve one completed secondary output chunk (None if no secondary tap is configured).
Sourcepub fn flush(&mut self)
pub fn flush(&mut self)
Flush on stop. Feed the processor’s trailing tail (e.g. denoise), drain each tap’s stage 2
resampler remainder, and pad a final partial chunk with silence to align it to the fixed
20ms boundary so it can be retrieved with pop_chunk / pop_secondary.
Continue on a best-effort basis if resampler flushing fails, so the stop path does not fail (at most the final few milliseconds are lost).
Sourcepub fn buffered_out_frames(&self) -> usize
pub fn buffered_out_frames(&self) -> usize
Number of output frames buffered but not yet retrieved from out_buf (primary tap).