FX Class: Guitar Distortion

Interactive example


Overview

The Guitar Distortion audio effect is used to mimic the sound of amplified electric musical instruments, usually by increasing their gain and simulating their saturation going into overdrive, producing a "fuzzy", "growling", or "gritty" tone. This effect has Marshall cabinet, ADA cabinet and V-Twin preamp simulation, 5-band equalizer, bass and treble tone controls and two distortion sound paths (similar to Boss DS-1 and Tyrian).


Implementation example

gainDecibel, eq80HzDecibel, eq240HzDecibel, gainDecibeq750HzDecibel, eq2200HzDecibel, eq6600HzDecibel have the strongest impact on the sound, adjustable from `-96` to `24` decibels.

Additional frequency range limiting is possible with the bassFrequency and trebleFrequency properties.

The drive property acts as the overall distortion ratio from 0 to 1.

Amp cabinet simulation can be added using marshall, ada and vtwin switches.

Pedal simulation can be enabled using distortion0 (similar to Boss DS-1) and distortion1 (similar to Tyrian).

Guitar distortion 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. One instance allocates around 32 kb memory.

class SuperpoweredFilterProcessor extends SuperpoweredWebAudio.AudioWorkletProcessor {
// Called when the AudioWorklet is ready to start processing audio
onReady() {
this.effect = new this.Superpowered.GuitarDistortion(
this.samplerate
);
this.effect.enabled = true;
this.effect.distortion1 = true;
this.effect.marshall = true;
this.effect.drive = 0.2;
this.effect.gainDecibel = -20;
}
// Runs before the node is destroyed.
// Clean up memory and objects here (such as free allocated linear memory or destruct Superpowered objects).
onDestruct() {
this.effect.destruct();
}
// messages are received from the main scope through this method.
onMessageFromMainScope(message) {
if (typeof message.gainDecibel !== 'undefined') this.effect.gainDecibel = message.gainDecibel;
if (typeof message.drive !== 'undefined') this.effect.drive = message.drive;
if (typeof message.bassFrequency !== 'undefined') this.effect.bassFrequency = message.bassFrequency;
if (typeof message.trebleFrequency !== 'undefined') this.effect.trebleFrequency = message.trebleFrequency;
if (typeof message.eq80HzDecibel !== 'undefined') this.effect.eq80HzDecibel = message.eq80HzDecibel;
if (typeof message.eq240HzDecibel !== 'undefined') this.effect.eq250HzDecibel = message.eq240HzDecibel;
if (typeof message.eq750HzDecibel !== 'undefined') this.effect.eq750HzDecibel = message.eq750HzDecibel;
if (typeof message.eq2200HzDecibel !== 'undefined') this.effect.eq2200HzDecibel = message.eq2200HzDecibel;
if (typeof message.eq6600HzDecibel !== 'undefined') this.effect.eq6600HzDecibel = message.eq6600HzDecibel;
if (typeof message.distortion0 !== 'undefined') this.effect.distortion0 = message.distortion0;
if (typeof message.distortion1 !== 'undefined') this.effect.distortion1 = message.distortion1;
if (typeof message.marshall !== 'undefined') this.effect.marshall = message.marshall;
if (typeof message.ada !== 'undefined') this.effect.ada = message.ada;
if (typeof message.vtwin !== 'undefined') this.effect.vtwin = message.vtwin;
if (typeof message.enabled !== 'undefined') this.effect.enabled = Boolean(message.enabled);
}
processAudio(inputBuffer, outputBuffer, buffersize, parameters) {
// Ensure the samplerate is in sync on every audio processing callback
this.effect.samplerate = this.samplerate;
// Render the output buffers
if (!this.effect.process(inputBuffer.pointer, outputBuffer.pointer, buffersize)) {
for (let n = 0; n < buffersize * 2 ; n++) outputBuffer.array[n] = inputBuffer.array[n];
}
}
}
#include "SuperpoweredGuitarDistortion.h"
void initEffect() {
effect = new Superpowered::GuitarDistortion(44100);
effect->enabled = true;
}
void configureEffect() {
effect->enabled = true;
effect->distortion1 = true;
effect->marshall = true;
effect->drive = 0.2;
effect->gainDecibel = -20;
}
void processAudio(float *interleavedInput, float *interleavedOutput, unsigned int numberOfFrames, unsigned int samplerate) {
// Ensure the samplerate is in sync on every audio processing callback
effect->samplerate = samplerate;
// Render the output buffers
bool outputChanged = effect->process(interleavedInput, interleavedOutput, numberOfFrames);
...
}

Properties

ada

PROPERTY
Enables ADA cabinet simulation. Adds a lot of bass and treble.
TypeMinMaxDefault
Number
false

ada

PROPERTY
Enables ADA cabinet simulation. Adds a lot of bass and treble.
TypeMinMaxDefault
boolean
false

bassFrequency

PROPERTY
High-pass filter frequency in Hz.
TypeMinMaxDefault
Number
12501

bassFrequency

PROPERTY
High-pass filter frequency in Hz.
TypeMinMaxDefault
float
12501

distortion0

PROPERTY
Enables the first distortion sound, that is similar to Boss DS-1.
TypeMinMaxDefault
Number
false

distortion0

PROPERTY
Enables the first distortion sound, that is similar to Boss DS-1.
TypeMinMaxDefault
boolean
false

distortion1

PROPERTY
Enables the second distortion sound, that is similar to Tyrian.
TypeMinMaxDefault
Number
false

distortion1

PROPERTY
Enables the second distortion sound, that is similar to Tyrian.
TypeMinMaxDefault
boolean
false

drive

PROPERTY
Drive percentage.
TypeMinMaxDefault
Number
010

drive

PROPERTY
Drive percentage.
TypeMinMaxDefault
float
010

eq2200HzDecibel

PROPERTY
EQ 2200 Hz decibel gain.
TypeMinMaxDefault
Number
-96240

eq2200HzDecibel

PROPERTY
EQ 2200 Hz decibel gain.
TypeMinMaxDefault
float
-96240

eq240HzDecibel

PROPERTY
EQ 240 Hz decibel gain.
TypeMinMaxDefault
Number
-96240

eq240HzDecibel

PROPERTY
EQ 240 Hz decibel gain.
TypeMinMaxDefault
float
-96240

eq6600HzDecibel

PROPERTY
EQ 6600 Hz decibel gain.
TypeMinMaxDefault
Number
-96240

eq6600HzDecibel

PROPERTY
EQ 6600 Hz decibel gain.
TypeMinMaxDefault
float
-96240

eq750HzDecibel

PROPERTY
EQ 750 Hz decibel gain.
TypeMinMaxDefault
Number
-96240

eq750HzDecibel

PROPERTY
EQ 750 Hz decibel gain.
TypeMinMaxDefault
float
-96240

eq80HzDecibel

PROPERTY
EQ 80 Hz decibel gain.
TypeMinMaxDefault
Number
-96240

eq80HzDecibel

PROPERTY
EQ 80 Hz decibel gain.
TypeMinMaxDefault
float
-96240

gainDecibel

PROPERTY
Gain value in decibel.
TypeMinMaxDefault
Number
-96240

gainDecibel

PROPERTY
Gain value in decibel.
TypeMinMaxDefault
float
-96240

marshall

PROPERTY
Enables Marshall cabinet simulation.
TypeMinMaxDefault
Number
false

marshall

PROPERTY
Enables Marshall cabinet simulation.
TypeMinMaxDefault
boolean
false

trebleFrequency

PROPERTY
Low-pass filter frequency in Hz.
TypeMinMaxDefault
Number
6000sample rate / 2sample rate / 2 - 100

trebleFrequency

PROPERTY
Low-pass filter frequency in Hz.
TypeMinMaxDefault
float
6000sample rate / 2sample rate / 2 - 100

vtwin

PROPERTY
Enables V-Twin preamp simulation. Recommended for blues/jazz.
TypeMinMaxDefault
Number
false

vtwin

PROPERTY
Enables V-Twin preamp simulation. Recommended for blues/jazz.
TypeMinMaxDefault
boolean
false
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 GuitarDistortion instance.
    Parameters
    NameTypeDescription
    samplerateNumberThe initial sample rate in Hz.
    Returns
    TypeDescription
    Superpowered.GuitarDistortionThe constructed instance.
  • constructor

    METHOD
    Creates a GuitarDistortion instance.
    Parameters
    NameTypeDefaultDescription
    samplerateunsigned intThe initial sample rate in Hz.
    Returns
    TypeDescription
    Superpowered::GuitarDistortionThe constructed instance.
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).
v2.7.2