pub trait AudioProcessor: Send {
    fn process(
        &mut self,
        inputs: &[AudioRenderQuantum],
        outputs: &mut [AudioRenderQuantum],
        params: AudioParamValues<'_>,
        timestamp: f64,
        sample_rate: SampleRate
    ) -> bool; }
Expand description

Interface for audio processing code that runs on the audio rendering thread.

Note that the AudioProcessor is typically constructed together with an crate::node::AudioNode (the user facing object that lives in the control thread). See crate::context::ConcreteBaseAudioContext::register.

Check the examples/worklet.rs file for example usage of this trait.

Required methods

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 false when the node only transforms their inputs, and as such can be removed when the inputs are disconnected (e.g. GainNode)
  • return true for some time when the node still outputs after the inputs are disconnected (e.g. DelayNode)
  • return true as long as this node is a source of output (e.g. OscillatorNode)

Implementors