Skip to main content

Audio

Struct Audio 

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

Whole-audio value backed by a planar FP32 [channels, samples] matrix.

Clones retain the same matrix storage and semantic audio metadata.

Implementations§

Source§

impl Audio

Source

pub fn new( data: Matrix, sample_rate: u32, layout: AudioChannelLayout, ) -> Result<Self>

Attach audio semantics to a planar FP32 matrix.

§Errors

Returns an error unless data is a non-empty rank-two FP32 matrix, the sample rate is non-zero, and a known layout agrees with the matrix’s channel extent.

Source

pub fn new_from_planar_f32( engine: &Engine, samples: &[f32], channel_count: usize, sample_rate: u32, layout: AudioChannelLayout, ) -> Result<Self>

Upload planar FP32 samples and attach audio metadata.

samples contains all samples for channel zero, followed by all samples for channel one, and so on.

§Errors

Returns an error for zero channels, an empty or incomplete planar buffer, a zero sample rate, incompatible layout metadata, checked-size overflow, or device allocation/upload failure.

Source

pub const fn as_matrix(&self) -> &Matrix

Return the zero-copy planar matrix view.

Source

pub fn channels(&self) -> usize

Return the number of channels.

Source

pub fn samples(&self) -> usize

Return the sample count per channel.

Source

pub const fn sample_rate(&self) -> u32

Return the sample rate in hertz.

Source

pub const fn layout(&self) -> AudioChannelLayout

Return the semantic speaker layout.

Source

pub fn duration_seconds(&self) -> f64

Return the clip duration in seconds.

Source§

impl Audio

Source

pub fn normalize(&self, config: NormalizeAudioConfig) -> Result<Self>

Normalize global peak or RMS level to the configured decibel target.

Delegates to crate::audio::normalize.

Source

pub fn resample(&self, config: ResampleConfig) -> Result<Self>

Resample planar audio using the donor windowed-sinc gather kernel.

Delegates to crate::audio::resample.

Source

pub fn gain(&self, gain_db: f32) -> Result<Self>

Apply scalar gain in decibels.

Delegates to crate::audio::gain.

Source

pub fn clip(&self, minimum: f32, maximum: f32) -> Result<Self>

Clamp every sample to an inclusive finite interval.

Delegates to crate::audio::clip.

Source

pub fn saturate(&self, drive_db: f32, mix: f32) -> Result<Self>

Apply tanh soft clipping with a dry/wet mix.

Delegates to crate::audio::saturate.

Source

pub fn biquad(&self, coefficients: BiquadCoefficients) -> Result<Self>

Apply one stable zero-state biquad independently to every channel.

Delegates to crate::audio::biquad.

Source

pub fn reverb(&self, decay_seconds: f32, wet: f32) -> Result<Self>

Render a finite zero-state Schroeder reverberation tail.

Delegates to crate::audio::reverb.

Source

pub fn sos_filter(&self, sections: &[BiquadCoefficients]) -> Result<Self>

Apply one to 64 stable biquad sections as a zero-state cascade.

Delegates to crate::audio::sos_filter.

Source

pub fn pre_emphasis(&self, alpha: f32) -> Result<Self>

Apply y[n] = x[n] - alpha*x[n-1] independently per channel.

Delegates to crate::audio::pre_emphasis.

Source

pub fn to_mono(&self) -> Result<Self>

Average all channels into one mono channel.

Delegates to crate::audio::to_mono.

Source

pub fn fade(&self, fade_in_samples: u64, fade_out_samples: u64) -> Result<Self>

Apply linear fade-in and fade-out envelopes measured in samples.

Delegates to crate::audio::fade.

Source

pub fn mix( &self, right: &Audio, gain_left: f32, gain_right: f32, ) -> Result<Self>

Compute a weighted sum of matching Audio values.

Delegates to crate::audio::mix.

Source

pub fn amplitude_to_db(&self, floor_db: f32) -> Result<Matrix>

Convert absolute amplitude to finite decibels with a silence floor.

Delegates to crate::audio::amplitude_to_db.

Source

pub fn waveform_envelope(&self, bins: u32) -> Result<Matrix>

Reduce multichannel audio to [bins, 2] minimum/maximum pairs.

Delegates to crate::audio::waveform_envelope.

Source

pub fn stft(&self, config: StftConfig) -> Result<Matrix>

Compute magnitude STFT features in [channels, frames, frequency_bins] layout.

Delegates to crate::audio::stft.

Source

pub fn stft_complex(&self, config: StftConfig) -> Result<Matrix>

Compute complex STFT coefficients in [channels, frames, frequency_bins, 2] interleaved real/imaginary layout.

Delegates to crate::audio::stft_complex.

Source

pub fn mel_spectrogram(&self, config: MelConfig) -> Result<Matrix>

Compute HTK triangular-filter mel features in [channels, mels, frames] layout.

Delegates to crate::audio::mel_spectrogram.

Source

pub fn mfcc(&self, config: MfccConfig) -> Result<Matrix>

Compute orthonormal DCT-II coefficients in [channels, coefficients, frames] layout.

Delegates to crate::audio::mfcc.

Trait Implementations§

Source§

impl Clone for Audio

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Audio

§

impl !Send for Audio

§

impl !Sync for Audio

§

impl !UnwindSafe for Audio

§

impl Forget for Audio

§

impl Freeze for Audio

§

impl Move for Audio

§

impl Unpin for Audio

§

impl UnsafeUnpin for Audio

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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.