Trait web_audio_api::render::AudioProcessor
source · pub trait AudioProcessor: Send {
// Required method
fn process(
&mut self,
inputs: &[AudioRenderQuantum],
outputs: &mut [AudioRenderQuantum],
params: AudioParamValues<'_>,
scope: &RenderScope
) -> bool;
// Provided method
fn onmessage(&mut self, msg: &mut dyn Any) { ... }
}Expand description
Interface for audio processing code that runs on the audio rendering thread.
Note that the AudioProcessor is typically constructed together with an
AudioNode (the user facing object that lives in the control
thread). See BaseAudioContext::register.
Check the examples/worklet.rs file for example usage of this trait.
Required Methods§
sourcefn process(
&mut self,
inputs: &[AudioRenderQuantum],
outputs: &mut [AudioRenderQuantum],
params: AudioParamValues<'_>,
scope: &RenderScope
) -> bool
fn process( &mut self, inputs: &[AudioRenderQuantum], outputs: &mut [AudioRenderQuantum], params: AudioParamValues<'_>, scope: &RenderScope ) -> bool
Audio processing function
§Arguments
- inputs: readonly array of input buffers
- outputs: array of output buffers
- params: available
AudioParams for this processor - timestamp: time of the start of this render quantum
- sample_rate: sample rate of this render quantum
§Return value
The return value (bool) of this callback controls the lifetime of the processor.
- return
falsewhen the node only transforms their inputs, and as such can be removed when the inputs are disconnected (e.g. GainNode) - return
truefor some time when the node still outputs after the inputs are disconnected (e.g. DelayNode) - return
trueas long as this node is a source of output (e.g. OscillatorNode)
Provided Methods§
sourcefn onmessage(&mut self, msg: &mut dyn Any)
fn onmessage(&mut self, msg: &mut dyn Any)
Handle incoming messages from the linked AudioNode
By overriding this method you can add a handler for messages sent from the control thread
via
AudioContextRegistration::post_message.
This will not be necessary for most processors.
Receivers are supposed to consume the content of msg. The content of msg might
also be replaced by cruft that needs to be deallocated outside of the render thread
afterwards, e.g. when replacing an internal buffer.
This method is just a shim of the full
MessagePort
onmessage functionality of the AudioWorkletProcessor.