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 {
onReady() {
this.flanger = new this.Superpowered.Flanger(
this.samplerate,
);
this.flanger.enabled = true;
this.flanger.frequency = 22500;
this.eflangerfect.bits = 8;
}
onDestruct() {
this.flanger.destruct();
}
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) {
this.flanger.samplerate = this.samplerate;
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) {
flanger->samplerate = samplerate;
bool outputChanged = flanger->process(interleavedInput, interleavedOutput, numberOfFrames);
...
}
Properties
bpm
PROPERTYThe bpm of the current audio, defines the speed of the flanger in combination with lfoBeats.
Type | Min | Max | Default |
---|
Number | 40 | 250 | 128 |
bpm
PROPERTYThe bpm of the current audio, defines the speed of the flanger in combination with lfoBeats.
Type | Min | Max | Default |
---|
float | 40 | 250 | 128 |
clipperMaximumDb
PROPERTYThe flanger has a Clipper inside to prevent overdrive. This is the maximumDb parameter.
Type | Min | Max | Default |
---|
Number | -48 | 48 | 6 |
clipperMaximumDb
PROPERTYThe flanger has a Clipper inside to prevent overdrive. This is the maximumDb parameter.
Type | Min | Max | Default |
---|
float | -48 | 48 | 6 |
clipperThresholdDb
PROPERTYThe flanger has a Clipper inside to prevent overdrive. This is the maximumDb parameter.
Type | Min | Max | Default |
---|
Number | -100 | 0 | -3 |
clipperThresholdDb
PROPERTYThe flanger has a Clipper inside to prevent overdrive. This is the maximumDb parameter.
Type | Min | Max | Default |
---|
float | -100 | 0 | -3 |
depth
PROPERTYHow far the flanger deviates from the input sound. 0 is 0.3 ms, 1 is 8 ms.
Type | Min | Max | Default |
---|
Number | 0 | 1 | 0.16 |
depth
PROPERTYHow far the flanger deviates from the input sound. 0 is 0.3 ms, 1 is 8 ms.
Type | Min | Max | Default |
---|
float | 0 | 1 | 0.16 |
lfoBeats
PROPERTYThe length in beats between the "lowest" and the "highest" jet sound. Depends on bpm property.
Type | Min | Max | Default |
---|
Number | 0.25 | 128 | 16 |
lfoBeats
PROPERTYThe length in beats between the "lowest" and the "highest" jet sound. Depends on bpm property.
Type | Min | Max | Default |
---|
float | 0.25 | 128 | 16 |
stereo
PROPERTYTrue: stereo, false: mono. It doesn't transform the input or output to mono, this applies for the additional jet effect only.
Type | Min | Max | Default |
---|
Boolean | | | false |
stereo
PROPERTYTrue: stereo, false: mono. It doesn't transform the input or output to mono, this applies for the additional jet effect only.
Type | Min | Max | Default |
---|
bool | | | false |
wet
PROPERTYThe wet signal mixed into the output.
Type | Min | Max | Default |
---|
Number | 0 | 1 | 0.7 |
wet
PROPERTYThe wet signal mixed into the output.
Type | Min | Max | Default |
---|
float | 0 | 1 | 0.7 |
Inherited from FX Classenabled
PROPERTYTurns the effect on/off. The actual switch will happen on the next process() call for smooth, audio-artifact free operation.
Type | Min | Max | Default |
---|
Boolean | | | false |
enabled
PROPERTYTurns the effect on/off. The actual switch will happen on the next process() call for smooth, audio-artifact free operation.
Type | Min | Max | Default |
---|
bool | | | false |
samplerate
PROPERTYThe sample rate of the audio context, you must update if it changes.
samplerate
PROPERTYThe sample rate of the audio context, you must update if it changes.
Type | Min | Max | Default |
---|
unsigned int | | | |
Methods
constructor
METHODCreates an instance of the Flanger class.
ParametersName | Type | Description |
---|
samplerate | Number | The initial sample rate in Hz. |
ReturnsType | Description |
---|
Superpowered.Flanger | The constructed instance. |
constructor
METHODCreates an instance of the Flanger class.
ParametersName | Type | Default | Description |
---|
samplerate | unsigned int | | The initial sample rate in Hz. |
ReturnsType | Description |
---|
Superpowered::Flanger | The constructed instance. |
getDepthMs
METHODReturns with the current depth, 0.3 to 8.0 (0.3 ms to 8 ms).
ParametersNone
ReturnsType | Description |
---|
Number | Current depth in milliseconds. |
getDepthMs
METHODReturns with the current depth, 0.3 to 8.0 (0.3 ms to 8 ms).
ParametersNone
ReturnsType | Description |
---|
float | Current depth in milliseconds. |
Inherited from FX Classdestruct
METHODDestructor to free Linear Memory.
ParametersNone
ReturnsNone
process
METHODProcesses/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.
ParametersName | 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. Recommendations for best performance: multiply of 4, minimum 64. |
ReturnsType | Description |
---|
Boolean | If 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
METHODProcesses/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().
ParametersName | 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. Recommendations for best performance: multiply of 4, minimum 64. |
ReturnsType | Description |
---|
bool | If 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). |