Struct web_audio_api::render::AudioRenderQuantum
source · 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 AudioRenderQuantumChannel
s 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
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)
sourcepub fn is_silent(&self) -> bool
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.
sourcepub fn make_silent(&mut self)
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
impl Clone for AudioRenderQuantum
source§fn clone(&self) -> AudioRenderQuantum
fn clone(&self) -> AudioRenderQuantum
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more