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 and 2 is unchanged.
Input above two channels is rejected with UnsupportedFormat). 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_capture_tap(self) -> Result<Self>
pub fn with_capture_tap(self) -> Result<Self>
Enable a pre-output-conversion canonical branch for off-callback consumers. Its stop tail contains valid frames only, never transport padding.
Sourcepub fn buffered_capture_frames(&self) -> usize
pub fn buffered_capture_frames(&self) -> usize
Canonical frames produced but not emitted, discarded when this generation is rebuilt.
Sourcepub fn pop_capture(&mut self, stopping: bool) -> Option<(Vec<f32>, i64)>
pub fn pop_capture(&mut self, stopping: bool) -> Option<(Vec<f32>, i64)>
Retrieve valid canonical stereo frames; allow a short final tail only at stop.
Sourcepub fn pop_capture_with_metadata(
&mut self,
stopping: bool,
) -> Option<NormalizedChunk>
pub fn pop_capture_with_metadata( &mut self, stopping: bool, ) -> Option<NormalizedChunk>
Retrieve valid canonical frames with no transport padding.
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.
Incomplete trailing frames are retained until a later push completes them.
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 pop_chunk_with_metadata(&mut self) -> Option<NormalizedChunk>
pub fn pop_chunk_with_metadata(&mut self) -> Option<NormalizedChunk>
Retrieve primary PCM with its integrity flags.
Sourcepub fn pop_secondary_with_metadata(&mut self) -> Option<NormalizedChunk>
pub fn pop_secondary_with_metadata(&mut self) -> Option<NormalizedChunk>
Retrieve secondary PCM with its integrity flags.
Sourcepub fn flush(&mut self) -> Result<()>
pub fn flush(&mut self) -> Result<()>
Drain stage 1, processor tail and all output stages, retaining independent failures. Repeated flush returns the same result without generating duplicate PCM. Valid output remains drainable on cleanup-only failure.
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).