conformal_component::audio

Struct BufferData

Source
pub struct BufferData { /* private fields */ }
Expand description

A buffer of audio samples that owns its data.

This is a simple implementation of Buffer that owns its data on the heap. It is useful for testing and as a simple way to create buffers.

§Examples

let buffer = BufferData::new_mono(vec![1.0, 2.0, 3.0]);
assert_eq!(buffer.channel(0), [1.0, 2.0, 3.0]);

Implementations§

Source§

impl BufferData

Source

pub fn new(channel_layout: ChannelLayout, num_frames: usize) -> Self

Create a new buffer with the given channel layout and number of frames.

The buffer will be filled with zeros.

§Examples
let buffer = BufferData::new(ChannelLayout::Mono, 3);
assert_eq!(buffer.channel_layout(), ChannelLayout::Mono);
assert_eq!(buffer.channel(0), [0.0, 0.0, 0.0]);
Source

pub fn new_mono(data: Vec<f32>) -> BufferData

Create a new mono buffer with the given data.

§Examples
let buffer = BufferData::new_mono(vec![1.0, 2.0, 3.0]);
assert_eq!(buffer.channel_layout(), ChannelLayout::Mono);
assert_eq!(buffer.channel(0), [1.0, 2.0, 3.0]);
Source

pub fn new_stereo<L: IntoIterator<Item = f32>, R: IntoIterator<Item = f32>>( left: L, right: R, ) -> BufferData

Create a new stereo buffer with the given data.

§Examples
let buffer = BufferData::new_stereo([1.0, 2.0], [3.0, 4.0]);
assert_eq!(buffer.channel_layout(), ChannelLayout::Stereo);
assert!(channels(&buffer).eq([[1.0, 2.0], [3.0, 4.0]]));
§Panics

Panics if the length of left and right are not equal.

let buffer = BufferData::new_stereo([1.0, 2.0], [3.0]);

Trait Implementations§

Source§

impl Buffer for BufferData

Source§

fn channel_layout(&self) -> ChannelLayout

The layout of the channels in the buffer.
Source§

fn num_frames(&self) -> usize

The number of frames in the buffer. Read more
Source§

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

Get a channel from the buffer. Read more
Source§

fn num_channels(&self) -> usize

The number of channels in the buffer.
Source§

impl BufferMut for BufferData

Source§

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

Get a channel from the buffer as a mutable slice
Source§

impl Clone for BufferData

Source§

fn clone(&self) -> BufferData

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 Debug for BufferData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

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

Source§

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

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.