pub trait AudioWorkletProcessor {
    type ProcessorOptions: Send;
    // Required methods
    fn constructor(opts: Self::ProcessorOptions) -> Self
       where Self: Sized;
    fn process<'a, 'b>(
        &mut self,
        inputs: &'b [&'a [&'a [f32]]],
        outputs: &'b mut [&'a mut [&'a mut [f32]]],
        params: AudioParamValues<'b>,
        scope: &'b AudioWorkletGlobalScope,
    ) -> bool;
    // Provided methods
    fn parameter_descriptors() -> Vec<AudioParamDescriptor>
       where Self: Sized { ... }
    fn onmessage(&mut self, _msg: &mut dyn Any) { ... }
}Expand description
Audio processing code that runs on the audio rendering thread.
Required Associated Types§
Sourcetype ProcessorOptions: Send
 
type ProcessorOptions: Send
Constructor options for the audio processor
This holds any user-defined data that may be used to initialize custom properties in an AudioWorkletProcessor instance that is associated with the AudioWorkletNode.
Required Methods§
Sourcefn constructor(opts: Self::ProcessorOptions) -> Selfwhere
    Self: Sized,
 
fn constructor(opts: Self::ProcessorOptions) -> Selfwhere
    Self: Sized,
Constructor of the AudioWorkletProcessor instance (to be executed in the render thread)
Sourcefn process<'a, 'b>(
    &mut self,
    inputs: &'b [&'a [&'a [f32]]],
    outputs: &'b mut [&'a mut [&'a mut [f32]]],
    params: AudioParamValues<'b>,
    scope: &'b AudioWorkletGlobalScope,
) -> bool
 
fn process<'a, 'b>( &mut self, inputs: &'b [&'a [&'a [f32]]], outputs: &'b mut [&'a mut [&'a mut [f32]]], params: AudioParamValues<'b>, scope: &'b AudioWorkletGlobalScope, ) -> bool
Audio processing function
§Arguments
- inputs: readonly array of input buffers
- outputs: array of output buffers
- params: available AudioParamvalues for this processor
- scope: AudioWorkletGlobalScope object with current frame, timestamp, sample rate
§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 parameter_descriptors() -> Vec<AudioParamDescriptor>where
    Self: Sized,
 
fn parameter_descriptors() -> Vec<AudioParamDescriptor>where
    Self: Sized,
List of AudioParams for this audio processor
A default implementation is provided that supplies no parameters.
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 the AudioWorkletNode MessagePort.
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.