pub struct AudioRenderQuantum { /* private fields */ }
Expand description

Render thread audio buffer, consisting of multiple channel buffers

This is a fixed length audio asset of render_quantum_size sample frames for block rendering, basically a list of AudioRenderQuantumChannels cf. https://webaudio.github.io/web-audio-api/#render-quantum

The render_quantum_size is equal to 128 by default, but in future versions it may be equal to the hardware preferred render quantum size or any other value.

An AudioRenderQuantum has copy-on-write semantics, so it is cheap to clone.

Usage

Audio buffers are managed with a dedicated allocator per render thread, hence there are no public constructors available. If you must create a new instance, copy an existing one and mutate it from there.

use web_audio_api::render::AudioRenderQuantum;

fn apply_gain(buffer: &mut AudioRenderQuantum, gain: f32) {
    buffer.channels_mut()
        .iter_mut()
        .for_each(|ch| ch.iter_mut().for_each(|s| *s *= gain))
}

Implementations§

source§

impl AudioRenderQuantum

source

pub fn number_of_channels(&self) -> usize

Number of channels in this AudioRenderQuantum

source

pub fn set_number_of_channels(&mut self, n: usize)

Set number of channels in this AudioRenderQuantum

Note: if the new number is higher than the previous, the new channels will be filled with garbage.

Panics

This function will panic if the given number of channels is outside the [1, 32] range, 32 being defined by the MAX_CHANNELS constant.

source

pub fn channel_data(&self, index: usize) -> &AudioRenderQuantumChannel

Get the samples from this specific channel.

Panics

Panics if the index is greater than the available number of channels

source

pub fn channel_data_mut(
    &mut self,
    index: usize
) -> &mut AudioRenderQuantumChannel

Get the samples (mutable) from this specific channel.

Panics

Panics if the index is greater than the available number of channels

source

pub fn channels(&self) -> &[AudioRenderQuantumChannel]

Channel data as slice

source

pub fn channels_mut(&mut self) -> &mut [AudioRenderQuantumChannel]

Channel data as slice (mutable)

source

pub fn is_silent(&self) -> bool

O(1) check if this buffer is equal to the ‘silence buffer’

If this function returns false, it is still possible for all samples to be zero.

source

pub fn make_silent(&mut self)

Convert this buffer to silence

O(1) operation to convert this buffer to the ‘silence buffer’ which will enable some optimizations in the graph rendering.

Trait Implementations§

source§

impl Clone for AudioRenderQuantum

source§

fn clone(&self) -> AudioRenderQuantum

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 AudioRenderQuantum

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 Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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 Twhere
    U: From<T>,

const: unstable · 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.

§

impl<F, T> IntoSample<T> for Fwhere
    T: FromSample<F>,

§

fn into_sample(self) -> T

source§

impl<T> ToOwned for Twhere
    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> ToSample<U> for Twhere
    U: FromSample<T>,

source§

fn to_sample_(self) -> U

source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

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