Skip to main content

AudioFrame

Struct AudioFrame 

Source
pub struct AudioFrame<'a> { /* private fields */ }
Expand description

A frame of audio samples with associated sample rate.

AudioFrame is the standard audio input type across the WaveKat ecosystem. It stores samples as f32 normalized to [-1.0, 1.0], regardless of the original input format.

Construct via AudioFrame::new, which accepts both &[f32] (zero-copy) and &[i16] (converts once) through the IntoSamples trait.

§Examples

use wavekat_core::AudioFrame;

// f32 input — zero-copy via Cow::Borrowed
let samples = [0.1f32, -0.2, 0.3];
let frame = AudioFrame::new(&samples, 16000);
assert_eq!(frame.samples(), &[0.1, -0.2, 0.3]);

// i16 input — normalized to f32 [-1.0, 1.0]
let samples = [i16::MAX, 0, i16::MIN];
let frame = AudioFrame::new(&samples, 16000);
assert!((frame.samples()[0] - 1.0).abs() < 0.001);

Implementations§

Source§

impl<'a> AudioFrame<'a>

Source

pub fn new(samples: impl IntoSamples<'a>, sample_rate: u32) -> AudioFrame<'a>

Create a new audio frame from any supported sample type.

Accepts &[f32] (zero-copy) or &[i16] (converts to normalized f32).

Source

pub fn samples(&self) -> &[f32]

The audio samples as f32 normalized to [-1.0, 1.0].

Source

pub fn sample_rate(&self) -> u32

Sample rate in Hz (e.g. 16000).

Source

pub fn len(&self) -> usize

Number of samples in the frame.

Source

pub fn is_empty(&self) -> bool

Returns true if the frame contains no samples.

Source

pub fn duration_secs(&self) -> f64

Duration of this frame in seconds.

Source

pub fn into_owned(self) -> AudioFrame<'static>

Consume the frame and return the owned samples.

Trait Implementations§

Source§

impl<'a> Clone for AudioFrame<'a>

Source§

fn clone(&self) -> AudioFrame<'a>

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> Debug for AudioFrame<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for AudioFrame<'a>

§

impl<'a> RefUnwindSafe for AudioFrame<'a>

§

impl<'a> Send for AudioFrame<'a>

§

impl<'a> Sync for AudioFrame<'a>

§

impl<'a> Unpin for AudioFrame<'a>

§

impl<'a> UnsafeUnpin for AudioFrame<'a>

§

impl<'a> UnwindSafe for AudioFrame<'a>

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.