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 arrayMulti: 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§
Implementations§
Source§impl<T: AudioSample> AudioData<'static, T>
impl<T: AudioSample> AudioData<'static, T>
Sourcepub fn from_owned(data: AudioData<'_, T>) -> Self
pub fn from_owned(data: AudioData<'_, T>) -> Self
Creates a new AudioData instance from owned data.
Sourcepub fn into_mono_data(self) -> Option<Array1<T>>
pub fn into_mono_data(self) -> Option<Array1<T>>
Consumes self and returns the underlying data as an owned Array1 or Array2.
Sourcepub fn into_multi_data(self) -> Option<Array2<T>>
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>
impl<T: AudioSample> AudioData<'_, T>
Sourcepub const fn new_mono(data: Array1<T>) -> AudioData<'static, T>
pub const fn new_mono(data: Array1<T>) -> AudioData<'static, T>
Creates a new mono AudioData from an owned Array1.
Sourcepub const fn new_multi(data: Array2<T>) -> AudioData<'static, T>
pub const fn new_multi(data: Array2<T>) -> AudioData<'static, T>
Creates a new multi-channel AudioData from an owned Array2.
Sourcepub fn from_slice<'a>(slice: &'a [T]) -> AudioData<'a, T>
pub fn from_slice<'a>(slice: &'a [T]) -> AudioData<'a, T>
Creates mono AudioData from a slice (borrowed).
Sourcepub fn from_slice_mut<'a>(slice: &'a mut [T]) -> AudioData<'a, T>
pub fn from_slice_mut<'a>(slice: &'a mut [T]) -> AudioData<'a, T>
Creates mono AudioData from a mutable slice (borrowed).
Sourcepub fn from_slice_multi<'a>(slice: &'a [T], channels: usize) -> AudioData<'a, T>
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 bychannels - If the slice cannot be reshaped into the desired shape
Sourcepub fn from_slice_multi_mut<'a>(
slice: &'a mut [T],
channels: usize,
) -> AudioData<'a, T>
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 bychannels - If the slice cannot be reshaped into the desired shape
Source§impl<'a, T: AudioSample> AudioData<'a, T>
impl<'a, T: AudioSample> AudioData<'a, T>
Sourcepub fn into_owned<'b>(self) -> AudioData<'b, T>
pub fn into_owned<'b>(self) -> AudioData<'b, T>
Converts this AudioData to owned data.
Sourcepub fn from_borrowed<'b>(&'b self) -> AudioData<'b, T>
pub fn from_borrowed<'b>(&'b self) -> AudioData<'b, T>
Creates a new AudioData instance from borrowed data.
Sourcepub const fn from_borrowed_array1<'b>(
view: ArrayView1<'b, T>,
) -> AudioData<'b, T>
pub const fn from_borrowed_array1<'b>( view: ArrayView1<'b, T>, ) -> AudioData<'b, T>
Creates AudioData from a borrowed mono array view.
Sourcepub const fn from_borrowed_array1_mut<'b>(
view: ArrayViewMut1<'b, T>,
) -> AudioData<'b, T>
pub const fn from_borrowed_array1_mut<'b>( view: ArrayViewMut1<'b, T>, ) -> AudioData<'b, T>
Creates AudioData from a borrowed mutable mono array view.
Sourcepub const fn from_borrowed_array2<'b>(
view: ArrayView2<'b, T>,
) -> AudioData<'b, T>
pub const fn from_borrowed_array2<'b>( view: ArrayView2<'b, T>, ) -> AudioData<'b, T>
Creates AudioData from a borrowed multi-channel array view.
Sourcepub const fn from_borrowed_array2_mut<'b>(
view: ArrayViewMut2<'b, T>,
) -> AudioData<'b, T>
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.
Sourcepub fn num_channels(&self) -> usize
pub fn num_channels(&self) -> usize
Returns the number of channels in the audio data.
Sourcepub const fn is_multi_channel(&self) -> bool
pub const fn is_multi_channel(&self) -> bool
Returns true if the audio data has multiple channels.
Sourcepub fn samples_per_channel(&self) -> usize
pub fn samples_per_channel(&self) -> usize
Returns the number of samples per channel.
Sourcepub fn mean_axis(&self, axis: Axis) -> Option<Self>
pub fn mean_axis(&self, axis: Axis) -> Option<Self>
Returns the mean of the audio data along the specified axis.
Sourcepub fn bytes(&self) -> AudioSampleResult<AudioBytes<'_>>
pub fn bytes(&self) -> AudioSampleResult<AudioBytes<'_>>
Returns a contiguous byte view when possible, falling back to I24 packing when required.
Sourcepub const fn bytes_per_sample(&self) -> usize
pub const fn bytes_per_sample(&self) -> usize
Returns the number of bytes per sample for the current sample type.
Sourcepub fn into_bytes(&self) -> Vec<u8> ⓘ
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.
Sourcepub fn as_bytes(&self) -> Vec<u8> ⓘ
👎Deprecated: use bytes() for borrowed access or into_bytes() for owned bytes
pub fn as_bytes(&self) -> Vec<u8> ⓘ
Deprecated: use bytes() for borrowed access or into_bytes() for owned bytes.
Sourcepub fn mapv<F, U>(&self, f: F) -> AudioData<'static, U>where
F: Fn(T) -> U,
U: AudioSample,
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.
Sourcepub fn mapv_inplace<F>(&mut self, f: F)where
F: Fn(T) -> T,
pub fn mapv_inplace<F>(&mut self, f: F)where
F: Fn(T) -> T,
Maps a function over each sample in place.
Sourcepub fn apply<F>(&mut self, func: F)where
F: Fn(T) -> T,
pub fn apply<F>(&mut self, func: F)where
F: Fn(T) -> T,
Applies a function to each sample in place.
Sourcepub fn apply_with_index<F>(&mut self, func: F)
pub fn apply_with_index<F>(&mut self, func: F)
Applies a function to each sample with its index in place.
Sourcepub fn apply_windowed<F>(
&mut self,
window_size: usize,
hop_size: usize,
func: F,
) -> AudioSampleResult<()>
pub fn apply_windowed<F>( &mut self, window_size: usize, hop_size: usize, func: F, ) -> AudioSampleResult<()>
Applies a windowed function to the audio data with overlap processing.
Sourcepub fn apply_to_all_channels<F>(&mut self, f: F)where
F: Fn(T) -> T,
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.
Sourcepub fn apply_to_channels<F>(&mut self, channels: &[usize], f: F)where
F: Fn(T) -> T,
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.
Sourcepub fn convert_to<O: AudioSample>(&self) -> AudioData<'static, O>where
T: ConvertTo<O>,
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.
Sourcepub fn to_interleaved_vec(self) -> Vec<T>
pub fn to_interleaved_vec(self) -> Vec<T>
Converts the audio data to an interleaved vector, consuming the data.
Sourcepub fn as_interleaved_vec(&self) -> Vec<T>
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>
impl<'a, T: AudioSample> Add<T> for AudioData<'a, T>
Source§impl<'a, T: AudioSample> Add for AudioData<'a, T>
impl<'a, T: AudioSample> Add for AudioData<'a, T>
Source§impl<'a, T> AddAssign<T> for AudioData<'a, T>where
T: Clone + AudioSample,
impl<'a, T> AddAssign<T> for AudioData<'a, T>where
T: Clone + AudioSample,
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+= operation. Read moreSource§impl<'a, T> AddAssign for AudioData<'a, T>where
T: Clone + AudioSample,
impl<'a, T> AddAssign for AudioData<'a, T>where
T: Clone + AudioSample,
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<T: AudioSample> Clone for AudioData<'_, T>
impl<T: AudioSample> Clone for AudioData<'_, T>
Source§impl<'a, T: AudioSample> Div<T> for AudioData<'a, T>
impl<'a, T: AudioSample> Div<T> for AudioData<'a, T>
Source§impl<'a, T: AudioSample> Div for AudioData<'a, T>
impl<'a, T: AudioSample> Div for AudioData<'a, T>
Source§impl<'a, T> DivAssign<T> for AudioData<'a, T>where
T: Clone + AudioSample,
impl<'a, T> DivAssign<T> for AudioData<'a, T>where
T: Clone + AudioSample,
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/= operation. Read moreSource§impl<'a, T> DivAssign for AudioData<'a, T>where
T: Clone + AudioSample,
impl<'a, T> DivAssign for AudioData<'a, T>where
T: Clone + AudioSample,
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl<'a, T: AudioSample> From<ArrayBase<ViewRepr<&'a T>, Dim<[usize; 1]>>> for AudioData<'a, T>
impl<'a, T: AudioSample> From<ArrayBase<ViewRepr<&'a T>, Dim<[usize; 1]>>> for AudioData<'a, T>
Source§fn from(arr: ArrayView1<'a, T>) -> Self
fn from(arr: ArrayView1<'a, T>) -> Self
Source§impl<'a, T: AudioSample> From<ArrayBase<ViewRepr<&'a T>, Dim<[usize; 2]>>> for AudioData<'a, T>
impl<'a, T: AudioSample> From<ArrayBase<ViewRepr<&'a T>, Dim<[usize; 2]>>> for AudioData<'a, T>
Source§fn from(arr: ArrayView2<'a, T>) -> Self
fn from(arr: ArrayView2<'a, T>) -> Self
Source§impl<'a, T: AudioSample> From<ArrayBase<ViewRepr<&'a mut T>, Dim<[usize; 1]>>> for AudioData<'a, T>
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
fn from(arr: ArrayViewMut1<'a, T>) -> Self
Source§impl<'a, T: AudioSample> From<ArrayBase<ViewRepr<&'a mut T>, Dim<[usize; 2]>>> for AudioData<'a, T>
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
fn from(arr: ArrayViewMut2<'a, T>) -> Self
Source§impl<'a, T: AudioSample> Mul<T> for AudioData<'a, T>
impl<'a, T: AudioSample> Mul<T> for AudioData<'a, T>
Source§impl<'a, T: AudioSample> Mul for AudioData<'a, T>
impl<'a, T: AudioSample> Mul for AudioData<'a, T>
Source§impl<'a, T> MulAssign<T> for AudioData<'a, T>where
T: Clone + AudioSample,
impl<'a, T> MulAssign<T> for AudioData<'a, T>where
T: Clone + AudioSample,
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*= operation. Read moreSource§impl<'a, T> MulAssign for AudioData<'a, T>where
T: Clone + AudioSample,
impl<'a, T> MulAssign for AudioData<'a, T>where
T: Clone + AudioSample,
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl<'a, T: AudioSample> Sub<T> for AudioData<'a, T>
impl<'a, T: AudioSample> Sub<T> for AudioData<'a, T>
Source§impl<'a, T: AudioSample> Sub for AudioData<'a, T>
impl<'a, T: AudioSample> Sub for AudioData<'a, T>
Source§impl<'a, T> SubAssign<T> for AudioData<'a, T>where
T: Clone + AudioSample,
impl<'a, T> SubAssign<T> for AudioData<'a, T>where
T: Clone + AudioSample,
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-= operation. Read moreSource§impl<'a, T> SubAssign for AudioData<'a, T>where
T: Clone + AudioSample,
impl<'a, T> SubAssign for AudioData<'a, T>where
T: Clone + AudioSample,
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more