Skip to main content

Normalizer

Struct Normalizer 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn buffered_capture_frames(&self) -> usize

Canonical frames produced but not emitted, discarded when this generation is rebuilt.

Source

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.

Source

pub fn pop_capture_with_metadata( &mut self, stopping: bool, ) -> Option<NormalizedChunk>

Retrieve valid canonical frames with no transport padding.

Source

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.

Source

pub fn in_sample_rate(&self) -> u32

Input sample rate (Hz).

Source

pub fn output(&self) -> OutputFormat

Primary output format.

Source

pub fn secondary_output(&self) -> Option<OutputFormat>

Secondary output format (only when a secondary tap is configured).

Source

pub fn has_secondary(&self) -> bool

Whether a secondary tap is enabled.

Source

pub fn is_passthrough(&self) -> bool

Whether stage 1 sample-rate conversion is bypassed (in == 48000).

Source

pub fn is_output_passthrough(&self) -> bool

Whether stage 2 for the primary output is fully bypassed (output == {48000, 2}).

Source

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 labels the first frame in this push; the facade supplies an ingest arrival time, not a device timestamp.

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.

Source

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.

Source

pub fn pop_secondary(&mut self) -> Option<(Vec<f32>, i64)>

Retrieve one completed secondary output chunk (None if no secondary tap is configured).

Source

pub fn pop_chunk_with_metadata(&mut self) -> Option<NormalizedChunk>

Retrieve primary PCM with its integrity flags.

Source

pub fn pop_secondary_with_metadata(&mut self) -> Option<NormalizedChunk>

Retrieve secondary PCM with its integrity flags.

Source

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.

Source

pub fn buffered_out_frames(&self) -> usize

Number of output frames buffered but not yet retrieved from out_buf (primary tap).

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.