Skip to main content

Waveform

Struct Waveform 

Source
pub struct Waveform {
    pub samples: Tensor,
    pub sample_rate: u32,
    pub channel_layout: ChannelLayout,
    pub time_origin: f64,
}
Expand description

Owned waveform metadata and floating-point samples.

Fields§

§samples: Tensor

Float/Double tensor in [channels,frames], usually normalized to [-1,1].

§sample_rate: u32

Frames per second; nonzero.

§channel_layout: ChannelLayout

Channel ordering. Multi-channel decoding uses Discrete unless known.

§time_origin: f64

Time of frame zero in seconds, finite and nonnegative.

Implementations§

Source§

impl Waveform

Source

pub fn new(samples: Tensor, sample_rate: u32, time_origin: f64) -> Result<Self>

Validates a floating-point waveform and infers mono/stereo channel layout.

Source

pub fn validate(&self) -> Result<()>

Validates shape, rate, channel count and finite time origin.

Source

pub fn frames(&self) -> usize

Number of sample frames per channel.

Source

pub fn duration(&self) -> f64

Duration in seconds, excluding the time origin.

Source

pub fn gain(self, decibels: f64) -> Result<Self>

Applies finite decibel gain without mutating the original tensor storage.

Source

pub fn add_noise( self, amplitude: f32, context: &TaskContext, limits: ResourceLimits, ) -> Result<Self>

Adds deterministic uniform noise in [-amplitude, amplitude] using task randomness. Does not read or reseed LibTorch’s global random generator.

Source

pub fn time_shift(self, frames: i64) -> Result<Self>

Shifts by signed frames with zero fill, preserving duration and time origin.

Source

pub fn mix(self, other: &Self, scale: f64) -> Result<Self>

Mixes aligned waveforms with a finite scale. Rate, shape, layout, origin, dtype and device must match; there is no implicit broadcast or resampling.

Source

pub fn resample(self, new_rate: u32, limits: ResourceLimits) -> Result<Self>

Resamples on CPU using Rubato’s windowed-sinc interpolation, removing its startup delay. This host conversion is not differentiable. Output has ceil(input_frames * new_rate / old_rate) frames and preserves origin.

Source

pub fn spectrogram( &self, config: SpectrogramConfig, limits: ResourceLimits, ) -> Result<Tensor>

Computes one-sided periodic-Hann STFT magnitudes raised to power. Frames are uncentered with no padding: only complete windows are emitted. The result is [channels, n_fft/2+1, windows] and retains autograd.

Source

pub fn mel_spectrogram( &self, config: SpectrogramConfig, n_mels: usize, limits: ResourceLimits, ) -> Result<Tensor>

Projects the spectrogram through HTK triangular Mel filters. Frequencies span [0, sample_rate/2], with no Slaney area normalization.

Source

pub fn mfcc( &self, config: SpectrogramConfig, n_mels: usize, n_mfcc: usize, limits: ResourceLimits, ) -> Result<Tensor>

Computes orthonormal DCT-II of natural-log Mel energies with floor 1e-10. This is the explicitly named log-Mel convention, without dB/top-db scaling.

Trait Implementations§

Source§

impl Collate<Waveform> for PadAudio

Source§

type Batch = AudioBatch

Batch produced from the samples.
Source§

type Error = AudioError

Error returned when collation fails.
Source§

fn collate(&mut self, samples: Vec<Waveform>) -> Result<AudioBatch>

Collates samples into one batch.
Source§

impl Debug for Waveform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl MemoryFootprint for Waveform

Source§

fn resident_bytes(&self) -> usize

Returns the conservative logical payload size in bytes.
Source§

impl PinMemory for Waveform

Source§

fn pin_memory(self, d: Device) -> Result<Self>

Pins this value for the requested accelerator.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V