Struct web_audio_api::render::AudioRenderQuantum
source · [−]pub struct AudioRenderQuantum { /* private fields */ }
Expand description
Render thread audio buffer, consisting of multiple channel buffers
Internal fixed length audio asset of RENDER_QUANTUM_SIZE
sample frames for
block rendering, basically a matrix of channels * AudioRenderQuantumChannel
cf. https://webaudio.github.io/web-audio-api/#render-quantum
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
sourceimpl AudioRenderQuantum
impl AudioRenderQuantum
sourcepub fn number_of_channels(&self) -> usize
pub fn number_of_channels(&self) -> usize
Number of channels in this AudioRenderQuantum
sourcepub fn set_number_of_channels(&mut self, n: usize)
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.
sourcepub fn channel_data(&self, index: usize) -> &AudioRenderQuantumChannel
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
sourcepub fn channel_data_mut(
&mut self,
index: usize
) -> &mut AudioRenderQuantumChannel
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
sourcepub fn channels(&self) -> &[AudioRenderQuantumChannel]
pub fn channels(&self) -> &[AudioRenderQuantumChannel]
Channel data as slice
sourcepub fn channels_mut(&mut self) -> &mut [AudioRenderQuantumChannel]
pub fn channels_mut(&mut self) -> &mut [AudioRenderQuantumChannel]
Channel data as slice (mutable)
pub fn is_silent(&self) -> bool
sourcepub fn make_silent(&mut self)
pub fn make_silent(&mut self)
Convert this buffer to silence
Trait Implementations
sourceimpl Clone for AudioRenderQuantum
impl Clone for AudioRenderQuantum
sourcefn clone(&self) -> AudioRenderQuantum
fn clone(&self) -> AudioRenderQuantum
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl !RefUnwindSafe for AudioRenderQuantum
impl !Send for AudioRenderQuantum
impl !Sync for AudioRenderQuantum
impl Unpin for AudioRenderQuantum
impl !UnwindSafe for AudioRenderQuantum
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more