Skip to main content

AudioBuffer

Struct AudioBuffer 

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

Non-interleaved audio buffer. Zero-copy — borrows host memory through the format wrapper.

Implementations§

Source§

impl<'a> AudioBuffer<'a>

Source

pub unsafe fn from_slices( inputs: &'a [&'a [f32]], outputs: &'a mut [&'a mut [f32]], num_samples: usize, ) -> Self

Create a buffer from pre-split channel slices. Used by format wrappers after converting from host-specific buffer types.

§Safety

The caller must ensure the slices are valid for the lifetime 'a and that num_samples does not exceed any slice’s length.

Source

pub fn num_samples(&self) -> usize

Source

pub fn num_input_channels(&self) -> usize

Source

pub fn num_output_channels(&self) -> usize

Source

pub fn input(&self, channel: usize) -> &[f32]

Source

pub fn output(&mut self, channel: usize) -> &mut [f32]

Source

pub fn channels(&self) -> usize

Number of channels (min of input and output).

Source

pub fn io_pair(&mut self, in_ch: usize, out_ch: usize) -> (&[f32], &mut [f32])

Get an input/output pair for a channel. Useful for in-place processing.

Source

pub fn io(&mut self, ch: usize) -> (&[f32], &mut [f32])

Get an input/output pair for the same channel index. Shorthand for io_pair(ch, ch).

Source

pub fn output_peak(&self, ch: usize) -> f32

Peak absolute value across an output channel.

Source

pub fn slice(&mut self, start: usize, len: usize) -> AudioBuffer<'_>

Return a sub-block view covering samples start..start+len.

The returned buffer borrows self exclusively — you cannot use the original buffer while the slice is alive.

§Panics

Panics if start + len > self.num_samples().

§Example
let mut offset = 0;
for event in events.iter() {
    let at = event.sample_offset as usize;
    if at > offset {
        let mut sub = buffer.slice(offset, at - offset);
        process_sub_block(&mut sub);
    }
    handle_event(&event.body);
    offset = at;
}
if offset < buffer.num_samples() {
    let mut sub = buffer.slice(offset, buffer.num_samples() - offset);
    process_sub_block(&mut sub);
}

Auto Trait Implementations§

§

impl<'a> Freeze for AudioBuffer<'a>

§

impl<'a> RefUnwindSafe for AudioBuffer<'a>

§

impl<'a> Send for AudioBuffer<'a>

§

impl<'a> Sync for AudioBuffer<'a>

§

impl<'a> Unpin for AudioBuffer<'a>

§

impl<'a> UnsafeUnpin for AudioBuffer<'a>

§

impl<'a> !UnwindSafe for AudioBuffer<'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> 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, 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.