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>
impl<'a> AudioBuffer<'a>
Sourcepub unsafe fn from_slices(
inputs: &'a [&'a [f32]],
outputs: &'a mut [&'a mut [f32]],
num_samples: usize,
) -> Self
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.
pub fn num_samples(&self) -> usize
pub fn num_input_channels(&self) -> usize
pub fn num_output_channels(&self) -> usize
pub fn input(&self, channel: usize) -> &[f32]
pub fn output(&mut self, channel: usize) -> &mut [f32]
Sourcepub fn io_pair(&mut self, in_ch: usize, out_ch: usize) -> (&[f32], &mut [f32])
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.
Sourcepub fn io(&mut self, ch: usize) -> (&[f32], &mut [f32])
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).
Sourcepub fn output_peak(&self, ch: usize) -> f32
pub fn output_peak(&self, ch: usize) -> f32
Peak absolute value across an output channel.
Sourcepub fn slice(&mut self, start: usize, len: usize) -> AudioBuffer<'_>
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> 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