FX Class: Flanger

Interactive example


Overview

The flanger creates an aggressive “jet” like sound. It operates by mixing two identical audio signals together, with one of the signals playing at a slighter different and changing speed.

Similar to other effects the wet and depth properties allow controlling of the effect with values ranging from 0 to 1. The lfoBeats property is the length in beats between the “lowest and “highest” jet sound, from 0.25 (fastest) up to 128 (slowest).

The “jet” effect doesn't change the stereo sound stage, but using the additional stereo property it can sound wider.

The integrated Superpowered Clipper prevents overdrive. It can be fine-tuned using the clipperThresholdDb and clipperMaximumDb properties.

One instance allocates around 80 kb memory.

Implementation example

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

class SuperpoweredFlangerProcessor extends SuperpoweredWebAudio.AudioWorkletProcessor {
// Called when the AudioWorklet is ready to start processing audio
onReady() {
this.flanger = new this.Superpowered.Flanger(
this.samplerate, // The initial sample rate in Hz.
);
this.flanger.enabled = true;
this.flanger.frequency = 22500;
this.eflangerfect.bits = 8;
}
// Runs before the node is destroyed.
// Clean up memory and objects here (such as free allocated linear memory or destruct Superpowered objects).
onDestruct() {
this.flanger.destruct();
}
// messages are received from the main scope through this method.
onMessageFromMainScope(message) {
if (typeof message.wet !== 'undefined') this.flanger.wet = message.wet;
if (typeof message.depth !== 'undefined') this.flanger.depth = message.depth;
if (typeof message.lfoBeats !== 'undefined') this.flanger.lfoBeats = message.lfoBeats;
if (typeof message.bpm !== 'undefined') this.flanger.bpm = message.bpm;
if (typeof message.clipperThresholdDb !== 'undefined') this.flanger.clipperThresholdDb = message.clipperThresholdDb;
if (typeof message.clipperMaximumDb !== 'undefined') this.flanger.clipperMaximumDb = message.clipperMaximumDb;
if (typeof message.stereo !== 'undefined') this.flanger.stereo = Boolean(message.stereo);
if (typeof message.enabled !== 'undefined') this.flanger.enabled = Boolean(message.enabled);
}
processAudio(inputBuffer, outputBuffer, buffersize, parameters) {
// Ensure the samplerate is in sync on every audio processing callback
this.flanger.samplerate = this.samplerate;
// Render the output buffers, forward input if process returns false (no output changes)
if (!this.flanger.process(inputBuffer.pointer, outputBuffer.pointer, buffersize)) {
for (let n = 0; n < buffersize * 2 ; n++) outputBuffer.array[n] = inputBuffer.array[n];
}
}
}
#include "SuperpoweredFlanger.h"
void initFlangerEffect() {
const unsigned int sampleRate = 44100;
flanger = new Superpowered::Flanger(sampleRate);
flanger->enabled = true;
}
void configureFlangerEffect() {
flanger->bpm = 140;
flanger->lfoBeats = 1;
flanger->wet = 0.5;
}
void processAudio(float *interleavedInput, float *interleavedOutput, unsigned int numberOfFrames, unsigned int samplerate) {
// Ensure the samplerate is in sync on every audio processing callback
flanger->samplerate = samplerate;
// Render the output buffers
bool outputChanged = flanger->process(interleavedInput, interleavedOutput, numberOfFrames);
...
}

Properties

bpm

PROPERTY
The bpm of the current audio, defines the speed of the flanger in combination with lfoBeats.
TypeMinMaxDefault
Number
40250128

bpm

PROPERTY
The bpm of the current audio, defines the speed of the flanger in combination with lfoBeats.
TypeMinMaxDefault
float
40250128

clipperMaximumDb

PROPERTY
The flanger has a Clipper inside to prevent overdrive. This is the maximumDb parameter.
TypeMinMaxDefault
Number
-48486

clipperMaximumDb

PROPERTY
The flanger has a Clipper inside to prevent overdrive. This is the maximumDb parameter.
TypeMinMaxDefault
float
-48486

clipperThresholdDb

PROPERTY
The flanger has a Clipper inside to prevent overdrive. This is the maximumDb parameter.
TypeMinMaxDefault
Number
-1000-3

clipperThresholdDb

PROPERTY
The flanger has a Clipper inside to prevent overdrive. This is the maximumDb parameter.
TypeMinMaxDefault
float
-1000-3

depth

PROPERTY
How far the flanger deviates from the input sound. 0 is 0.3 ms, 1 is 8 ms.
TypeMinMaxDefault
Number
010.16

depth

PROPERTY
How far the flanger deviates from the input sound. 0 is 0.3 ms, 1 is 8 ms.
TypeMinMaxDefault
float
010.16

lfoBeats

PROPERTY
The length in beats between the "lowest" and the "highest" jet sound. Depends on bpm property.
TypeMinMaxDefault
Number
0.2512816

lfoBeats

PROPERTY
The length in beats between the "lowest" and the "highest" jet sound. Depends on bpm property.
TypeMinMaxDefault
float
0.2512816

stereo

PROPERTY
True: stereo, false: mono. It doesn't transform the input or output to mono, this applies for the additional jet effect only.
TypeMinMaxDefault
Boolean
false

stereo

PROPERTY
True: stereo, false: mono. It doesn't transform the input or output to mono, this applies for the additional jet effect only.
TypeMinMaxDefault
bool
false

wet

PROPERTY
The wet signal mixed into the output.
TypeMinMaxDefault
Number
010.7

wet

PROPERTY
The wet signal mixed into the output.
TypeMinMaxDefault
float
010.7
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 an instance of the Flanger class.
    Parameters
    NameTypeDescription
    samplerateNumberThe initial sample rate in Hz.
    Returns
    TypeDescription
    Superpowered.FlangerThe constructed instance.
  • constructor

    METHOD
    Creates an instance of the Flanger class.
    Parameters
    NameTypeDefaultDescription
    samplerateunsigned intThe initial sample rate in Hz.
    Returns
    TypeDescription
    Superpowered::FlangerThe constructed instance.
  • getDepthMs

    METHOD
    Returns with the current depth, 0.3 to 8.0 (0.3 ms to 8 ms).
    Parameters
    None
    Returns
    TypeDescription
    NumberCurrent depth in milliseconds.
  • getDepthMs

    METHOD
    Returns with the current depth, 0.3 to 8.0 (0.3 ms to 8 ms).
    Parameters
    None
    Returns
    TypeDescription
    floatCurrent depth in milliseconds.
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.34