pub struct AudioBuffer { /* private fields */ }Expand description
Normalized, interleaved f32 audio with sample-rate and channel metadata.
Samples are stored interleaved (frame-major) and scaled to the [-1.0, 1.0]
range regardless of the source bit depth. The buffer is cheap to clone and
owns its samples, which can be taken with AudioBuffer::into_samples.
Implementations§
Source§impl AudioBuffer
impl AudioBuffer
Sourcepub fn new(
sample_rate: u32,
channels: u16,
samples: Vec<f32>,
) -> Result<Self, ResampleError>
pub fn new( sample_rate: u32, channels: u16, samples: Vec<f32>, ) -> Result<Self, ResampleError>
Create a buffer from interleaved f32 samples.
Returns ResampleError::InvalidSampleRate when sample_rate is zero,
ResampleError::InvalidChannelCount when channels is zero, and
ResampleError::BufferError when the sample count is not a whole
number of frames.
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Source sample rate in Hz.
Sourcepub fn into_samples(self) -> Vec<f32>
pub fn into_samples(self) -> Vec<f32>
Consume the buffer and return the owned interleaved samples.
Sourcepub fn frame_count(&self) -> usize
pub fn frame_count(&self) -> usize
Number of frames (samples.len() / channels).
Sourcepub fn resample_to(&self, output_rate: u32) -> Result<Self, ResampleError>
pub fn resample_to(&self, output_rate: u32) -> Result<Self, ResampleError>
Resample to output_rate, preserving the channel layout.
Trait Implementations§
Source§impl Clone for AudioBuffer
impl Clone for AudioBuffer
Source§fn clone(&self) -> AudioBuffer
fn clone(&self) -> AudioBuffer
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AudioBuffer
impl Debug for AudioBuffer
Source§impl PartialEq for AudioBuffer
impl PartialEq for AudioBuffer
impl StructuralPartialEq for AudioBuffer
Auto Trait Implementations§
impl Freeze for AudioBuffer
impl RefUnwindSafe for AudioBuffer
impl Send for AudioBuffer
impl Sync for AudioBuffer
impl Unpin for AudioBuffer
impl UnsafeUnpin for AudioBuffer
impl UnwindSafe for AudioBuffer
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