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: TensorFloat/Double tensor in [channels,frames], usually normalized to [-1,1].
sample_rate: u32Frames per second; nonzero.
channel_layout: ChannelLayoutChannel ordering. Multi-channel decoding uses Discrete unless known.
time_origin: f64Time of frame zero in seconds, finite and nonnegative.
Implementations§
Source§impl Waveform
impl Waveform
Sourcepub fn new(samples: Tensor, sample_rate: u32, time_origin: f64) -> Result<Self>
pub fn new(samples: Tensor, sample_rate: u32, time_origin: f64) -> Result<Self>
Validates a floating-point waveform and infers mono/stereo channel layout.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validates shape, rate, channel count and finite time origin.
Sourcepub fn gain(self, decibels: f64) -> Result<Self>
pub fn gain(self, decibels: f64) -> Result<Self>
Applies finite decibel gain without mutating the original tensor storage.
Sourcepub fn add_noise(
self,
amplitude: f32,
context: &TaskContext,
limits: ResourceLimits,
) -> Result<Self>
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.
Sourcepub fn time_shift(self, frames: i64) -> Result<Self>
pub fn time_shift(self, frames: i64) -> Result<Self>
Shifts by signed frames with zero fill, preserving duration and time origin.
Sourcepub fn mix(self, other: &Self, scale: f64) -> Result<Self>
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.
Sourcepub fn resample(self, new_rate: u32, limits: ResourceLimits) -> Result<Self>
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.
Sourcepub fn spectrogram(
&self,
config: SpectrogramConfig,
limits: ResourceLimits,
) -> Result<Tensor>
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.
Sourcepub fn mel_spectrogram(
&self,
config: SpectrogramConfig,
n_mels: usize,
limits: ResourceLimits,
) -> Result<Tensor>
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.
Sourcepub fn mfcc(
&self,
config: SpectrogramConfig,
n_mels: usize,
n_mfcc: usize,
limits: ResourceLimits,
) -> Result<Tensor>
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.