Skip to main content

Chunk

Struct Chunk 

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

A buffer of audio samples with associated metadata.

Chunk is the unit of data that flows between DspNodes in a pipeline. It owns its sample buffer so that nodes can process in-place without extra allocations.

Samples are stored interleaved when channels > 1: [L0, R0, L1, R1, ...] for stereo.

§Examples

use resonant_stream::Chunk;

let chunk = Chunk::new(vec![0.0_f32; 1024], 44100, 1);
assert_eq!(chunk.frames(), 1024);
assert_eq!(chunk.sample_rate(), 44100);

Implementations§

Source§

impl Chunk

Source

pub fn new(data: Vec<f32>, sample_rate: u32, channels: u16) -> Self

Creates a new chunk from interleaved sample data.

§Panics

Panics if channels is zero or sample_rate is zero.

Source

pub fn empty(sample_rate: u32, channels: u16) -> Self

Creates an empty chunk with the given format.

§Panics

Panics if channels is zero or sample_rate is zero.

Source

pub fn data(&self) -> &[f32]

Returns a reference to the interleaved sample data.

Source

pub fn data_mut(&mut self) -> &mut [f32]

Returns a mutable reference to the interleaved sample data.

Source

pub fn into_data(self) -> Vec<f32>

Consumes the chunk, returning the underlying sample buffer.

Source

pub fn sample_rate(&self) -> u32

The sample rate in Hz.

Source

pub fn channels(&self) -> u16

The number of interleaved channels.

Source

pub fn frames(&self) -> usize

The number of sample frames (total samples / channels).

Source

pub fn is_empty(&self) -> bool

Returns true if the chunk contains no samples.

Source

pub fn len(&self) -> usize

The total number of samples (frames * channels).

Trait Implementations§

Source§

impl Clone for Chunk

Source§

fn clone(&self) -> Chunk

Returns a duplicate 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 Chunk

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Chunk

Source§

fn eq(&self, other: &Chunk) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Chunk

Auto Trait Implementations§

§

impl Freeze for Chunk

§

impl RefUnwindSafe for Chunk

§

impl Send for Chunk

§

impl Sync for Chunk

§

impl Unpin for Chunk

§

impl UnsafeUnpin for Chunk

§

impl UnwindSafe for Chunk

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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> 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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,