AudioFilterWorklet

ceramic.AudioFilterWorklet (Class) → HighPassFilterWorklet, LowPassFilterWorklet

The actual worklet class that will do the audio processing of a given AudioFilter.

AudioFilterWorklet is the base class for implementing custom audio effects and processors. Each worklet runs in the audio processing pipeline and can modify audio data in real-time.

Features:

  • Thread-safe parameter access (atomic operations on native platforms)
  • Automatic parameter management via @param metadata
  • Support for boolean, int, and float parameters
  • Per-bus audio processing

To create a custom filter:

  1. Extend this class
  2. Mark parameters with @param metadata
  3. Override the process() method
  4. Create an AudioFilter wrapper for public API
class MyEchoWorklet extends AudioFilterWorklet {
    var delayBuffer:Array<Float> = [];
    var writePos:Int = 0;
    override function process(buffer:AudioFilterBuffer, samples:Int,
                             channels:Int, sampleRate:Float, time:Float):Void {
        // Implement echo effect here
    }
}

Instance Members

filterId: Int

The id of the audio filter this worklet is associated with


bus: Int

active: Bool

numParams(): Int

Return the number of parameters this filter has. (automatically generated from fields marked with @param, no need to override it)

Returns
Int

process(buffer: AudioFilterBuffer, samples: Int, channels: Int, sampleRate: Float, time: Float): Void

Process audio buffer in place. Override this method to implement custom filtering. CAUTION: this may be called from a background thread

Name Type Description
buffer AudioFilterBuffer The audio buffer to process (modify in place, planar layout: one channel after another, not interleaved)
samples Int Number of samples per channel
channels Int Number of audio channels (1 = mono, 2 = stereo)
sampleRate Float Sample rate in Hz
time Float Current playback time in seconds

new(filterId: Int, bus: Int): Void

Creates a new audio filter worklet.

Name Type Description
filterId Int Unique identifier for this filter instance
bus Int Audio bus ID where this filter will process audio

Private Members

params: Array<Float>

Internal storage for filter parameters. Populated automatically from fields marked with @param metadata.


getBool(index: Int): Bool

Get a boolean parameter at the given position (0-based). Parameters are stored as floats where 0 = false, non-zero = true.

Name Type Description
index Int Parameter index (order matches
Returns Description
Bool Boolean value of the parameter

getInt(index: Int): Int

Get an int parameter at the given position (0-based). The float value is truncated to an integer.

Name Type Description
index Int Parameter index (order matches
Returns Description
Int Integer value of the parameter

getFloat(index: Int): Float

Get a float parameter at the given position (0-based).

Name Type Description
index Int Parameter index (order matches
Returns Description
Float Float value of the parameter