AudioData

Enum AudioData 

Source
pub enum AudioData<'a, T: AudioSample> {
    Mono(MonoData<'a, T>),
    Multi(MultiData<'a, T>),
}
Expand description

Storage container for audio sample data.

Differentiates between mono (single-channel) and multi-channel audio data while providing a unified interface for processing operations.

§Variants

  • Mono: Single-channel audio data stored as 1D array
  • Multi: Multi-channel audio data stored as 2D array (channels as rows)

§Example

use audio_samples::{AudioData, MonoData, MultiData};
use ndarray::{array, Array1, Array2};

// Mono audio data
let mono: AudioData<f32> = AudioData::Mono(MonoData::from(array![0.1, 0.2, 0.3]));

// Stereo audio data
let stereo: AudioData<f32> = AudioData::Multi(MultiData::from(
    array![[0.1, 0.2], [0.3, 0.4]]
));

Variants§

§

Mono(MonoData<'a, T>)

Single-channel audio data

§

Multi(MultiData<'a, T>)

Multi-channel audio data

Implementations§

Source§

impl<T: AudioSample> AudioData<'static, T>

Source

pub fn from_owned(data: AudioData<'_, T>) -> Self

Creates a new AudioData instance from owned data.

Source

pub fn mean(&self) -> Option<T>

Computes the mean value across all samples in the audio data.

Source

pub fn into_mono_data(self) -> Option<Array1<T>>

Consumes self and returns the underlying data as an owned Array1 or Array2.

Source

pub fn into_multi_data(self) -> Option<Array2<T>>

Consumes self and returns the underlying data as an owned Array2. Returns None if the data is mono.

Source§

impl<T: AudioSample> AudioData<'_, T>

Source

pub const fn new_mono(data: Array1<T>) -> AudioData<'static, T>

Creates a new mono AudioData from an owned Array1.

Source

pub const fn new_multi(data: Array2<T>) -> AudioData<'static, T>

Creates a new multi-channel AudioData from an owned Array2.

Source

pub fn from_slice<'a>(slice: &'a [T]) -> AudioData<'a, T>

Creates mono AudioData from a slice (borrowed).

Source

pub fn from_slice_mut<'a>(slice: &'a mut [T]) -> AudioData<'a, T>

Creates mono AudioData from a mutable slice (borrowed).

Source

pub fn from_slice_multi<'a>(slice: &'a [T], channels: usize) -> AudioData<'a, T>

Creates multi-channel AudioData from a slice with specified channel count (borrowed).

§Panics
  • If slice.len() is not divisible by channels
  • If the slice cannot be reshaped into the desired shape
Source

pub fn from_slice_multi_mut<'a>( slice: &'a mut [T], channels: usize, ) -> AudioData<'a, T>

Creates multi-channel AudioData from a mutable slice with specified channel count (borrowed).

§Panics
  • If slice.len() is not divisible by channels
  • If the slice cannot be reshaped into the desired shape
Source

pub fn from_vec(vec: Vec<T>) -> AudioData<'static, T>

Creates mono AudioData from a Vec (owned).

Source

pub fn from_vec_multi(vec: Vec<T>, channels: usize) -> AudioData<'static, T>

Creates multi-channel AudioData from a Vec with specified channel count (owned).

§Panics
  • If vec.len() is not divisible by channels
Source§

impl<'a, T: AudioSample> AudioData<'a, T>

Source

pub fn into_owned<'b>(self) -> AudioData<'b, T>

Converts this AudioData to owned data.

Source

pub fn from_borrowed<'b>(&'b self) -> AudioData<'b, T>

Creates a new AudioData instance from borrowed data.

Source

pub const fn from_borrowed_array1<'b>( view: ArrayView1<'b, T>, ) -> AudioData<'b, T>

Creates AudioData from a borrowed mono array view.

Source

pub const fn from_borrowed_array1_mut<'b>( view: ArrayViewMut1<'b, T>, ) -> AudioData<'b, T>

Creates AudioData from a borrowed mutable mono array view.

Source

pub const fn from_borrowed_array2<'b>( view: ArrayView2<'b, T>, ) -> AudioData<'b, T>

Creates AudioData from a borrowed multi-channel array view.

Source

pub const fn from_borrowed_array2_mut<'b>( view: ArrayViewMut2<'b, T>, ) -> AudioData<'b, T>

Creates AudioData from a borrowed mutable multi-channel array view.

Source

pub fn len(&self) -> usize

Returns the total number of samples in the audio data.

Source

pub fn num_channels(&self) -> usize

Returns the number of channels in the audio data.

Source

pub fn is_empty(&self) -> bool

Returns true if the audio data contains no samples.

Source

pub const fn is_mono(&self) -> bool

Returns true if the audio data is mono (single channel).

Source

pub const fn is_multi_channel(&self) -> bool

Returns true if the audio data has multiple channels.

Source

pub fn shape(&self) -> &[usize]

Returns the shape of the underlying array data.

Source

pub fn samples_per_channel(&self) -> usize

Returns the number of samples per channel.

Source

pub fn mean_axis(&self, axis: Axis) -> Option<Self>

Returns the mean of the audio data along the specified axis.

Source

pub fn as_slice(&self) -> Option<&[T]>

Returns audio data as a slice if contiguous.

Source

pub fn bytes(&self) -> AudioSampleResult<AudioBytes<'_>>

Returns a contiguous byte view when possible, falling back to I24 packing when required.

Source

pub const fn bytes_per_sample(&self) -> usize

Returns the number of bytes per sample for the current sample type.

Source

pub fn into_bytes(&self) -> Vec<u8>

Returns an owned byte buffer.

Note: this always allocates a new Vec<u8>. Use Self::bytes for a potentially zero-copy view.

Source

pub fn as_bytes(&self) -> Vec<u8>

👎Deprecated: use bytes() for borrowed access or into_bytes() for owned bytes

Deprecated: use bytes() for borrowed access or into_bytes() for owned bytes.

Source

pub fn mapv<F, U>(&self, f: F) -> AudioData<'static, U>
where F: Fn(T) -> U, U: AudioSample,

Maps a function over each sample, returning new owned audio data.

Source

pub fn mapv_inplace<F>(&mut self, f: F)
where F: Fn(T) -> T,

Maps a function over each sample in place.

Source

pub fn apply<F>(&mut self, func: F)
where F: Fn(T) -> T,

Applies a function to each sample in place.

Source

pub fn apply_with_index<F>(&mut self, func: F)
where F: Fn(usize, T) -> T,

Applies a function to each sample with its index in place.

Source

pub fn apply_windowed<F>( &mut self, window_size: usize, hop_size: usize, func: F, ) -> AudioSampleResult<()>
where F: Fn(&[T], &[T]) -> Vec<T>,

Applies a windowed function to the audio data with overlap processing.

Source

pub fn apply_to_all_channels<F>(&mut self, f: F)
where F: Fn(T) -> T,

Applies a function to all samples in all channels.

Source

pub fn apply_to_channels<F>(&mut self, channels: &[usize], f: F)
where F: Fn(T) -> T,

Applies a function to samples in specified channels only.

Source

pub fn convert_to<O: AudioSample>(&self) -> AudioData<'static, O>
where T: ConvertTo<O>,

Converts the samples to another sample type.

This is an audio-aware conversion using ConvertTo, so it can clamp and scale as needed for the source/target sample formats.

Source

pub fn to_interleaved_vec(self) -> Vec<T>

Converts the audio data to an interleaved vector, consuming the data.

Source

pub fn as_interleaved_vec(&self) -> Vec<T>

Returns the audio data as an interleaved vector without consuming the data.

Trait Implementations§

Source§

impl<'a, T: AudioSample> Add<T> for AudioData<'a, T>

Source§

type Output = AudioData<'a, T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: T) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, T: AudioSample> Add for AudioData<'a, T>

Source§

type Output = AudioData<'a, T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, T> AddAssign<T> for AudioData<'a, T>
where T: Clone + AudioSample,

Source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
Source§

impl<'a, T> AddAssign for AudioData<'a, T>
where T: Clone + AudioSample,

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<T: AudioSample> Clone for AudioData<'_, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, T: Debug + AudioSample> Debug for AudioData<'a, T>

Source§

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

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

impl<'a, T: AudioSample> Div<T> for AudioData<'a, T>

Source§

type Output = AudioData<'a, T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
Source§

impl<'a, T: AudioSample> Div for AudioData<'a, T>

Source§

type Output = AudioData<'a, T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl<'a, T> DivAssign<T> for AudioData<'a, T>
where T: Clone + AudioSample,

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<'a, T> DivAssign for AudioData<'a, T>
where T: Clone + AudioSample,

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl<'a, T: AudioSample> From<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>> for AudioData<'a, T>

Source§

fn from(a: Array1<T>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: AudioSample> From<ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>> for AudioData<'a, T>

Source§

fn from(a: Array2<T>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: AudioSample> From<ArrayBase<ViewRepr<&'a T>, Dim<[usize; 1]>>> for AudioData<'a, T>

Source§

fn from(arr: ArrayView1<'a, T>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: AudioSample> From<ArrayBase<ViewRepr<&'a T>, Dim<[usize; 2]>>> for AudioData<'a, T>

Source§

fn from(arr: ArrayView2<'a, T>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: AudioSample> From<ArrayBase<ViewRepr<&'a mut T>, Dim<[usize; 1]>>> for AudioData<'a, T>

Source§

fn from(arr: ArrayViewMut1<'a, T>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: AudioSample> From<ArrayBase<ViewRepr<&'a mut T>, Dim<[usize; 2]>>> for AudioData<'a, T>

Source§

fn from(arr: ArrayViewMut2<'a, T>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: AudioSample> Index<usize> for AudioData<'a, T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, T: AudioSample> Mul<T> for AudioData<'a, T>

Source§

type Output = AudioData<'a, T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, T: AudioSample> Mul for AudioData<'a, T>

Source§

type Output = AudioData<'a, T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, T> MulAssign<T> for AudioData<'a, T>
where T: Clone + AudioSample,

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<'a, T> MulAssign for AudioData<'a, T>
where T: Clone + AudioSample,

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<'a, T> Neg for AudioData<'a, T>
where T: Neg<Output = T> + AudioSample,

Source§

type Output = AudioData<'a, T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<'a, T: PartialEq + AudioSample> PartialEq for AudioData<'a, T>

Source§

fn eq(&self, other: &AudioData<'a, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T: AudioSample> Sub<T> for AudioData<'a, T>

Source§

type Output = AudioData<'a, T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: T) -> Self::Output

Performs the - operation. Read more
Source§

impl<'a, T: AudioSample> Sub for AudioData<'a, T>

Source§

type Output = AudioData<'a, T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<'a, T> SubAssign<T> for AudioData<'a, T>
where T: Clone + AudioSample,

Source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
Source§

impl<'a, T> SubAssign for AudioData<'a, T>
where T: Clone + AudioSample,

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<'a, T: AudioSample> StructuralPartialEq for AudioData<'a, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for AudioData<'a, T>

§

impl<'a, T> RefUnwindSafe for AudioData<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for AudioData<'a, T>

§

impl<'a, T> Sync for AudioData<'a, T>

§

impl<'a, T> Unpin for AudioData<'a, T>

§

impl<'a, T> !UnwindSafe for AudioData<'a, T>

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

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

Source§

fn vzip(self) -> V