pub struct AudioBuffer<S: Sample> { /* private fields */ }
Expand description

AudioBuffer is a container for multi-channel planar audio sample data. An AudioBuffer is characterized by the duration (capacity), and audio specification (channels and sample rate). The capacity of an AudioBuffer is the maximum number of samples the buffer may store per channel. Manipulation of samples is accomplished through the Signal trait or direct buffer manipulation.

Implementations§

source§

impl<S: Sample> AudioBuffer<S>

source

pub fn new(duration: Duration, spec: SignalSpec) -> Self

Instantiate a new AudioBuffer using the specified signal specification and of the given duration.

source

pub fn unused() -> Self

Instantiates an unused AudioBuffer. An unused AudioBuffer will not allocate any memory, has a sample rate of 0, and no audio channels.

source

pub fn is_unused(&self) -> bool

Returns true if the AudioBuffer is unused.

source

pub fn spec(&self) -> &SignalSpec

Gets the signal specification for the buffer.

source

pub fn capacity(&self) -> usize

Gets the total capacity of the buffer. The capacity is the maximum number of audio frames a buffer can store.

source

pub fn planes(&self) -> AudioPlanes<'_, S>

Gets immutable references to all audio planes (channels) within the audio buffer.

Note: This is not a cheap operation for audio buffers with > 8 channels. It is advisable that this call is only used when operating on large batches of frames. Generally speaking, it is almost always better to use chan() to selectively choose the plane to read instead.

source

pub fn planes_mut(&mut self) -> AudioPlanesMut<'_, S>

Gets mutable references to all audio planes (channels) within the buffer.

Note: This is not a cheap operation for audio buffers with > 8 channels. It is advisable that this call is only used when modifying large batches of frames. Generally speaking, it is almost always better to use render(), fill(), chan_mut(), and chan_pair_mut() to modify the buffer instead.

source

pub fn convert<T: Sample>(&self, dest: &mut AudioBuffer<T>)
where S: IntoSample<T>,

Converts the contents of an AudioBuffer into an equivalent destination AudioBuffer of a different type. If the types are the same then this is a copy operation.

source

pub fn make_equivalent<E: Sample>(&self) -> AudioBuffer<E>

Makes an equivalent AudioBuffer of a different type.

Trait Implementations§

source§

impl AsAudioBufferRef for AudioBuffer<f32>

source§

fn as_audio_buffer_ref(&self) -> AudioBufferRef<'_>

Get an AudioBufferRef reference.
source§

impl AsAudioBufferRef for AudioBuffer<f64>

source§

fn as_audio_buffer_ref(&self) -> AudioBufferRef<'_>

Get an AudioBufferRef reference.
source§

impl AsAudioBufferRef for AudioBuffer<i16>

source§

fn as_audio_buffer_ref(&self) -> AudioBufferRef<'_>

Get an AudioBufferRef reference.
source§

impl AsAudioBufferRef for AudioBuffer<i24>

source§

fn as_audio_buffer_ref(&self) -> AudioBufferRef<'_>

Get an AudioBufferRef reference.
source§

impl AsAudioBufferRef for AudioBuffer<i32>

source§

fn as_audio_buffer_ref(&self) -> AudioBufferRef<'_>

Get an AudioBufferRef reference.
source§

impl AsAudioBufferRef for AudioBuffer<i8>

source§

fn as_audio_buffer_ref(&self) -> AudioBufferRef<'_>

Get an AudioBufferRef reference.
source§

impl AsAudioBufferRef for AudioBuffer<u16>

source§

fn as_audio_buffer_ref(&self) -> AudioBufferRef<'_>

Get an AudioBufferRef reference.
source§

impl AsAudioBufferRef for AudioBuffer<u24>

source§

fn as_audio_buffer_ref(&self) -> AudioBufferRef<'_>

Get an AudioBufferRef reference.
source§

impl AsAudioBufferRef for AudioBuffer<u32>

source§

fn as_audio_buffer_ref(&self) -> AudioBufferRef<'_>

Get an AudioBufferRef reference.
source§

impl AsAudioBufferRef for AudioBuffer<u8>

source§

fn as_audio_buffer_ref(&self) -> AudioBufferRef<'_>

Get an AudioBufferRef reference.
source§

impl<S: Clone + Sample> Clone for AudioBuffer<S>

source§

fn clone(&self) -> AudioBuffer<S>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<S: Sample> Signal<S> for AudioBuffer<S>

source§

fn clear(&mut self)

Clears all written frames from the buffer. This is a cheap operation and does not zero the underlying audio data.
source§

fn frames(&self) -> usize

Gets the number of actual frames written to the buffer. Conversely, this also is the number of written samples in any one channel.
source§

fn chan(&self, channel: usize) -> &[S]

Gets an immutable reference to all the written samples in the specified channel.
source§

fn chan_mut(&mut self, channel: usize) -> &mut [S]

Gets a mutable reference to all the written samples in the specified channel.
source§

fn chan_pair_mut(&mut self, first: usize, second: usize) -> (&mut [S], &mut [S])

Gets two mutable references to two different channels.
source§

fn render_silence(&mut self, n_frames: Option<usize>)

Renders a number of silent frames. Read more
source§

fn render_reserved(&mut self, n_frames: Option<usize>)

Renders a reserved number of frames. This is a cheap operation and simply advances the frame counter. The underlying audio data is not modified and should be overwritten through other means. Read more
source§

fn render<'a, F>(&'a mut self, n_frames: Option<usize>, render: F) -> Result<()>
where F: FnMut(&mut AudioPlanesMut<'a, S>, usize) -> Result<()>,

Renders a number of frames using the provided render function. The number of frames to render is specified by n_frames. If n_frames is None, the remaining number of frames in the buffer will be rendered. If the render function returns an error, the render operation is terminated prematurely.
source§

fn transform<F>(&mut self, f: F)
where F: Fn(S) -> S,

Transforms every written sample in the signal using the transformation function provided. This function does not guarantee an order in which the samples are transformed.
source§

fn truncate(&mut self, n_frames: usize)

Truncates the buffer to the number of frames specified. If the number of frames in the buffer is less-than the number of frames specified, then this function does nothing.
source§

fn shift(&mut self, shift: usize)

Shifts the contents of the buffer back by the number of frames specified. The leading frames are dropped from the buffer.
source§

fn fill<'a, F>(&'a mut self, fill: F) -> Result<()>
where F: FnMut(&mut AudioPlanesMut<'a, S>, usize) -> Result<()>,

Clears, and then renders the entire buffer using the fill function. This is a convenience wrapper around render and exhibits the same behaviour as render in regards to the fill function.
source§

fn trim(&mut self, start: usize, end: usize)

Trims samples from the start and end of the buffer.

Auto Trait Implementations§

§

impl<S> RefUnwindSafe for AudioBuffer<S>
where S: RefUnwindSafe,

§

impl<S> Send for AudioBuffer<S>
where S: Send,

§

impl<S> Sync for AudioBuffer<S>
where S: Sync,

§

impl<S> Unpin for AudioBuffer<S>
where S: Unpin,

§

impl<S> UnwindSafe for AudioBuffer<S>
where S: UnwindSafe,

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

source§

fn into_sample(self) -> T

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.