FX Class: Limiter

Interactive example


Overview

Limiter with only 32 samples latency and less than 1 kb memory allocation. This effect can boost the perceived volume while keeping the maximum level below a limit. It can be used to prevent overload or reduce dynamic range.

thresholdDb and ceilingDb controls the amplitude in decibels between `0` and `-40`.The releaseSec property controls how fast the attenuation decreases between `0.001` and `1` (seconds). Also, there is a getGainReductionDb() method which will return the maximum gain reduction in decibels since the last getGainReductionDb() call.

Implementation example

The limiter is is an FX class, it expects both an input and output buffer. The process() method should be called on every loop of the audio processing block.

class SuperpoweredLimiterProcessor extends SuperpoweredWebAudio.AudioWorkletProcessor {
// Called when the AudioWorklet is ready to start processing audio
onReady() {
this.limiter = new this.Superpowered.Limiter(
44100 // The initial sample rate in Hz. -
);
this.limiter.enabled = true;
}
// Runs before the node is destroyed.
// Clean up memory and objects here (such as free allocated linear memory or destruct Superpowered objects).
onDestruct() {
this.limiter.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.bits !== 'undefined') this.limiter.bits = message.bits;
if (typeof message.frequency !== 'undefined') this.limiter.frequency = message.frequency;
}
// 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) {
// Ensure the samplerate is in sync on every audio processing callback
this.limiter.samplerate = this.samplerate;
// Render the output buffers
if (!this.limiter.process(inputBuffer.pointer, outputBuffer.pointer, buffersize)) {
for (let n = 0; n < buffersize * 2 ; n++) outputBuffer.array[n] = inputBuffer.array[n];
}
}
}
#include "SuperpoweredLimiter.h"
void initLimiterEffect() {
const unsigned int sampleRate = 44100;
limiter = new Superpowered::Limiter(sampleRate);
limiter->enabled = true;
}
void configureEffect() {
limiter->ceilingDb = 0;
limiter->thresholdDb = -16;
limiter->releaseSec = 0.2;
}
void processAudio(float *interleavedInput, float *interleavedOutput, unsigned int numberOfFrames, unsigned int samplerate) {
// Ensure the samplerate is in sync on every audio processing callback
limiter->samplerate = samplerate;
// Render the output buffers
bool outputChanged = limiter->process(interleavedInput, interleavedOutput, numberOfFrames);
...
}

Properties

ceilingDb

PROPERTY
Ceiling in decibels.
TypeMinMaxDefault
Number
-4000

ceilingDb

PROPERTY
Ceiling in decibels.
TypeMinMaxDefault
float
-4000

releaseSec

PROPERTY
Release in seconds (not milliseconds!).
TypeMinMaxDefault
Number
0.00110.05 (50ms)

releaseSec

PROPERTY
Release in seconds (not milliseconds!).
TypeMinMaxDefault
float
0.00110.05 (50ms)

thresholdDb

PROPERTY
Threshold in decibels.
TypeMinMaxDefault
Number
-4000

thresholdDb

PROPERTY
Threshold in decibels.
TypeMinMaxDefault
float
-4000
Inherited from FX Class

enabled

PROPERTY
Turns the effect on/off. The actual switch will happen on the next process() call for smooth, audio-artifact free operation.
TypeMinMaxDefault
Boolean
false

enabled

PROPERTY
Turns the effect on/off. The actual switch will happen on the next process() call for smooth, audio-artifact free operation.
TypeMinMaxDefault
bool
false

samplerate

PROPERTY
The sample rate of the audio context, you must update if it changes.
TypeMinMaxDefault
Number

samplerate

PROPERTY
The sample rate of the audio context, you must update if it changes.
TypeMinMaxDefault
unsigned int

Methods

  • constructor

    METHOD
    Creates a Limiter instance.
    Parameters
    NameTypeDescription
    samplerateNumberThe initial sample rate in Hz.
    Returns
    TypeDescription
    Superpowered.LimiterThe constructed instance.
  • constructor

    METHOD
    Creates a Limiter instance.
    Parameters
    NameTypeDefaultDescription
    samplerateunsigned intThe initial sample rate in Hz.
    Returns
    TypeDescription
    Superpowered::LimiterThe constructed instance.
  • getGainReductionDb

    METHOD
    Returns the maximum gain reduction in decibels since the last getGainReductionDb() call.
    Parameters
    None
    Returns
    TypeDescription
    NumberReduction in db.
  • getGainReductionDb

    METHOD
    Returns the maximum gain reduction in decibels since the last getGainReductionDb() call.
    Parameters
    None
    Returns
    TypeDescription
    floatReduction in db.
Inherited from FX Class
  • destruct

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

    METHOD
    Processes/renders the audio. Always call it in the audio processing callback, regardless if the effect is enabled or not for smooth, audio-artifact free operation. It's never blocking for real-time usage.
    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. Recommendations for best performance: multiply of 4, minimum 64.
    Returns
    TypeDescription
    BooleanIf process() returns with true, the contents of output are replaced with the audio output. If process() returns with false, it indicates silence. The contents of output are not changed in this case (not overwritten with zeros).
  • process

    METHOD
    Processes/renders the audio. Always call it in the audio processing callback, regardless if the effect is enabled or not for smooth, audio-artifact free operation. It's never blocking for real-time usage. You can change all effect 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. Recommendations for best performance: multiply of 4, minimum 64.
    Returns
    TypeDescription
    boolIf process() returns with true, the contents of output are replaced with the audio output. If process() returns with false, it indicates silence. The contents of output are not changed in this case (not overwritten with zeros).
v1.0.33