Skip to main content

TraceNormalizer

Struct TraceNormalizer 

Source
pub struct TraceNormalizer { /* private fields */ }
Expand description

The waveform’s normalizer: one running peak of the trace’s magnitude, applied as a uniform gain to the whole trace.

One shared peak for the same reason BandNormalizer uses one — the samples of a trace only mean anything relative to each other, and a per-sample gain would erase the shape the trace exists to show. Two differences from that type, both forced by the quantity:

  • The peak tracks |x| and the output stays signed. A trace is a signal, not a magnitude, so it is divided rather than rectified and clamps to -1..=1 instead of 0..=1.
  • The divisor is returned rather than discarded, because it is published as AnalysisFrame::waveform_gain (ADR-0139): the raw amplitude is waveform[i] * waveform_gain, which is the escape hatch a consumer that genuinely wants absolute level reaches for.

Implementations§

Source§

impl TraceNormalizer

Source

pub fn new(sample_rate: u32) -> Self

A normalizer for the trace at sample_rate.

Source

pub fn normalize(&mut self, trace: &mut [f32; 512]) -> f32

Advance one hop, normalizing trace in place, and return the divisor removed — 0.0 while the tracked peak sits under the floor, where the trace is zeroed rather than amplified.

Source

pub fn normalize_pair( &mut self, left: &mut [f32; 512], right: &mut [f32; 512], ) -> f32

The same, over two traces at once and with one divisor tracked over the larger of their magnitudes.

One divisor rather than two, and that is the whole reason this exists beside normalize: a hard-panned signal has a silent side, and levelling that side against its own recent peak would amplify whatever noise is in it up to full scale. The pair would then read as two loud channels, and an x-y figure built from them would lose the aspect that says where the sound is.

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,