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 audioonReady() {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 youonMessageFromMainScope(message) {// Here is an example of how to apply changes to the Three Band EQ instanceif (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 buffersclipper->process(interleavedInput, interleavedOutput, numberOfFrames);}
Properties
maximumDb
PROPERTYAudio will reach 1 (unity gain) at this point.
Type | Min | Max | Default | Number | -48 | 48 | 6 |
---|
maximumDb
PROPERTYAudio will reach 1 (unity gain) at this point.
Type | Min | Max | Default | float | -48 | 48 | 6 |
---|
thresholdDb
PROPERTYAudio below this will be unchanged, above this will be attenuated.
Type | Min | Max | Default | Number | -100 | 0 | 0 |
---|
thresholdDb
PROPERTYAudio below this will be unchanged, above this will be attenuated.
Type | Min | Max | Default | float | -100 | 0 | 0 |
---|
Methods
constructor
METHODCreates an instance of the Clipper class.ParametersNoneReturnsType Description Superpowered.Clipper
The constructed instance. constructor
METHODCreates an instance of the Clipper class.ParametersNoneReturnsType Description Superpowered::Clipper
The constructed instance. destruct
METHODDestructor to free Linear Memory.ParametersNoneReturnsNoneprocess
METHODProcesses the audio. It's never blocking for real-time usage. You can change all properties on any thread, concurrently with process().ParametersReturnsName Type Description input Number (pointer in Linear Memory)
32-bit interleaved stereo input. output Number (pointer in Linear Memory)
32-bit interleaved stereo output. numberOfFrames Number
Number of frames to process. Should be 4 minimum and exactly divisible with 4. Noneprocess
METHODProcesses the audio. It's never blocking for real-time usage. You can change all properties on any thread, concurrently with process().ParametersReturnsName Type Default Description input float *
32-bit interleaved stereo input. output float *
32-bit interleaved stereo output. numberOfFrames unsigned int
Number of frames to process. Should be 4 minimum and exactly divisible with 4. None