Clipper

Interactive example


Overview

Hard knee clipping with 0 latency. This effect will reduce the amplitude of the audio signal above the threshold level, and prevents going over the maximum level. The thresholdDb property can be set between `-100` and `0`. Anything below this value will be unchanged, and above will be attenuated. The maximumDb property is the maximum level between -48 and 48 decibels.

The clipper doesn't allocate any internal buffers and needs just a few bytes of memory.


Implementation example

The clipper expects both an input and output buffer. The process() method should be called on every loop of the audio processing block.

class SuperpoweredClipperProcessor extends SuperpoweredWebAudio.AudioWorkletProcessor {
// Called when the AudioWorklet is ready to start processing audio
onReady() {
this.clipper = new this.Superpowered.Clipper();
}
// Runs before the node is destroyed.
// Clean up memory and objects here (such as free allocated linear memory or destruct Superpowered objects).
onDestruct() {
this.clipper.destruct();
}
// The shape of the message we pass from our main thread is up to you
onMessageFromMainScope(message) {
// Here is an example of how to apply changes to the Three Band EQ instance
if (typeof message.thresholdDb !== 'undefined') this.clipper.thresholdDb = message.thresholdDb;
if (typeof message.maximumDb !== 'undefined') this.clipper.maximumDb = message.maximumDb;
}
// This is the process loop which is passed pointers to buffers
// from the WebAudio API (inputBuffer and outputBuffer), with the buffersize (128 samples when running as a native AudioWorklet)
processAudio(inputBuffer, outputBuffer, buffersize) {
this.clipper.process(inputBuffer.pointer, outputBuffer.pointer, buffersize);
}
}
#include "SuperpoweredClipper.h"
void initClipperEffect() {
clipper = new Superpowered::Clipper();
clipper->thresholdDb = -6;
clipper->maximumDb = 0;
}
void processAudio(float *interleavedInput, float *interleavedOutput, unsigned int numberOfFrames, unsigned int samplerate) {
// Render the output buffers
clipper->process(interleavedInput, interleavedOutput, numberOfFrames);
}

Properties

maximumDb

PROPERTY
Audio will reach 1 (unity gain) at this point.
TypeMinMaxDefault
Number
-48486

maximumDb

PROPERTY
Audio will reach 1 (unity gain) at this point.
TypeMinMaxDefault
float
-48486

thresholdDb

PROPERTY
Audio below this will be unchanged, above this will be attenuated.
TypeMinMaxDefault
Number
-10000

thresholdDb

PROPERTY
Audio below this will be unchanged, above this will be attenuated.
TypeMinMaxDefault
float
-10000

Methods

  • constructor

    METHOD
    Creates an instance of the Clipper class.
    Parameters
    None
    Returns
    TypeDescription
    Superpowered.ClipperThe constructed instance.
  • constructor

    METHOD
    Creates an instance of the Clipper class.
    Parameters
    None
    Returns
    TypeDescription
    Superpowered::ClipperThe constructed instance.
  • destruct

    METHOD
    Destructor to free Linear Memory.
    Parameters
    None
    Returns
    None
  • process

    METHOD
    Processes the audio. It's never blocking for real-time usage. You can change all properties on any thread, concurrently with process().
    Parameters
    NameTypeDescription
    inputNumber (pointer in Linear Memory)32-bit interleaved stereo input.
    outputNumber (pointer in Linear Memory)32-bit interleaved stereo output.
    numberOfFramesNumberNumber of frames to process. Should be 4 minimum and exactly divisible with 4.
    Returns
    None
  • process

    METHOD
    Processes the audio. It's never blocking for real-time usage. You can change all properties on any thread, concurrently with process().
    Parameters
    NameTypeDefaultDescription
    inputfloat *32-bit interleaved stereo input.
    outputfloat *32-bit interleaved stereo output.
    numberOfFramesunsigned intNumber of frames to process. Should be 4 minimum and exactly divisible with 4.
    Returns
    None
v2.7.2