pub struct AudioFrame {
pub samples: Vec<u8>,
pub sample_count: usize,
pub sample_rate: u32,
pub channels: usize,
pub format: SampleFormat,
pub pts: Option<i64>,
pub duration: Option<u64>,
}Expand description
An audio frame containing decoded samples.
Audio frames store PCM samples in interleaved format for multi-channel audio. For example, stereo audio is stored as [L0, R0, L1, R1, L2, R2, …].
Fields§
§samples: Vec<u8>Raw sample data (interleaved if multi-channel)
sample_count: usizeNumber of samples per channel
sample_rate: u32Sample rate in Hz (e.g., 48000 for 48kHz)
channels: usizeNumber of channels (1 = mono, 2 = stereo, etc.)
format: SampleFormatSample format
pts: Option<i64>Presentation timestamp in sample units
duration: Option<u64>Duration in sample units
Implementations§
Source§impl AudioFrame
impl AudioFrame
Sourcepub fn new(
samples: Vec<u8>,
sample_count: usize,
sample_rate: u32,
channels: usize,
format: SampleFormat,
) -> Self
pub fn new( samples: Vec<u8>, sample_count: usize, sample_rate: u32, channels: usize, format: SampleFormat, ) -> Self
Creates a new audio frame.
§Arguments
samples- Raw sample data (interleaved if multi-channel)sample_count- Number of samples per channelsample_rate- Sample rate in Hzchannels- Number of channelsformat- Sample format
Sourcepub fn with_timing(
samples: Vec<u8>,
sample_count: usize,
sample_rate: u32,
channels: usize,
format: SampleFormat,
pts: i64,
duration: u64,
) -> Self
pub fn with_timing( samples: Vec<u8>, sample_count: usize, sample_rate: u32, channels: usize, format: SampleFormat, pts: i64, duration: u64, ) -> Self
Creates a new audio frame with timing information.
Sourcepub const fn total_samples(&self) -> usize
pub const fn total_samples(&self) -> usize
Returns the total number of samples (all channels combined).
Sourcepub fn duration_seconds(&self) -> f64
pub fn duration_seconds(&self) -> f64
Returns the duration in seconds.
Sourcepub fn to_f32(&self) -> CodecResult<Vec<f32>>
pub fn to_f32(&self) -> CodecResult<Vec<f32>>
Converts bytes to f32 and returns a new Vec.
Sourcepub fn to_i16(&self) -> CodecResult<Vec<i16>>
pub fn to_i16(&self) -> CodecResult<Vec<i16>>
Converts bytes to i16 and returns a new Vec.
Trait Implementations§
Source§impl Clone for AudioFrame
impl Clone for AudioFrame
Source§fn clone(&self) -> AudioFrame
fn clone(&self) -> AudioFrame
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 Freeze for AudioFrame
impl RefUnwindSafe for AudioFrame
impl Send for AudioFrame
impl Sync for AudioFrame
impl Unpin for AudioFrame
impl UnsafeUnpin for AudioFrame
impl UnwindSafe for AudioFrame
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more