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>
impl<'a> AudioFrame<'a>
Sourcepub fn new(samples: impl IntoSamples<'a>, sample_rate: u32) -> Self
pub fn new(samples: impl IntoSamples<'a>, sample_rate: u32) -> Self
Create a new audio frame from any supported sample type.
Accepts &[f32] (zero-copy) or &[i16] (converts to normalized f32).
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Sample rate in Hz (e.g. 16000).
Sourcepub fn duration_secs(&self) -> f64
pub fn duration_secs(&self) -> f64
Duration of this frame in seconds.
Sourcepub fn into_owned(self) -> AudioFrame<'static>
pub fn into_owned(self) -> AudioFrame<'static>
Consume the frame and return the owned samples.
Trait Implementations§
Source§impl<'a> Clone for AudioFrame<'a>
impl<'a> Clone for AudioFrame<'a>
Source§fn clone(&self) -> AudioFrame<'a>
fn clone(&self) -> AudioFrame<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more