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 {
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;
}
onDestruct() {
this.effect.destruct();
}
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) {
this.effect.samplerate = this.samplerate;
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) {
effect->samplerate = samplerate;
bool outputChanged = effect->process(interleavedInput, interleavedOutput, numberOfFrames);
...
}
Properties
ada
PROPERTYEnables ADA cabinet simulation. Adds a lot of bass and treble.
Type | Min | Max | Default |
---|
Number | | | false |
ada
PROPERTYEnables ADA cabinet simulation. Adds a lot of bass and treble.
Type | Min | Max | Default |
---|
boolean | | | false |
bassFrequency
PROPERTYHigh-pass filter frequency in Hz.
Type | Min | Max | Default |
---|
Number | 1 | 250 | 1 |
bassFrequency
PROPERTYHigh-pass filter frequency in Hz.
Type | Min | Max | Default |
---|
float | 1 | 250 | 1 |
distortion0
PROPERTYEnables the first distortion sound, that is similar to Boss DS-1.
Type | Min | Max | Default |
---|
Number | | | false |
distortion0
PROPERTYEnables the first distortion sound, that is similar to Boss DS-1.
Type | Min | Max | Default |
---|
boolean | | | false |
distortion1
PROPERTYEnables the second distortion sound, that is similar to Tyrian.
Type | Min | Max | Default |
---|
Number | | | false |
distortion1
PROPERTYEnables the second distortion sound, that is similar to Tyrian.
Type | Min | Max | Default |
---|
boolean | | | false |
drive
PROPERTYDrive percentage.
Type | Min | Max | Default |
---|
Number | 0 | 1 | 0 |
drive
PROPERTYDrive percentage.
Type | Min | Max | Default |
---|
float | 0 | 1 | 0 |
eq2200HzDecibel
PROPERTYEQ 2200 Hz decibel gain.
Type | Min | Max | Default |
---|
Number | -96 | 24 | 0 |
eq2200HzDecibel
PROPERTYEQ 2200 Hz decibel gain.
Type | Min | Max | Default |
---|
float | -96 | 24 | 0 |
eq240HzDecibel
PROPERTYEQ 240 Hz decibel gain.
Type | Min | Max | Default |
---|
Number | -96 | 24 | 0 |
eq240HzDecibel
PROPERTYEQ 240 Hz decibel gain.
Type | Min | Max | Default |
---|
float | -96 | 24 | 0 |
eq6600HzDecibel
PROPERTYEQ 6600 Hz decibel gain.
Type | Min | Max | Default |
---|
Number | -96 | 24 | 0 |
eq6600HzDecibel
PROPERTYEQ 6600 Hz decibel gain.
Type | Min | Max | Default |
---|
float | -96 | 24 | 0 |
eq750HzDecibel
PROPERTYEQ 750 Hz decibel gain.
Type | Min | Max | Default |
---|
Number | -96 | 24 | 0 |
eq750HzDecibel
PROPERTYEQ 750 Hz decibel gain.
Type | Min | Max | Default |
---|
float | -96 | 24 | 0 |
eq80HzDecibel
PROPERTYEQ 80 Hz decibel gain.
Type | Min | Max | Default |
---|
Number | -96 | 24 | 0 |
eq80HzDecibel
PROPERTYEQ 80 Hz decibel gain.
Type | Min | Max | Default |
---|
float | -96 | 24 | 0 |
gainDecibel
PROPERTYGain value in decibel.
Type | Min | Max | Default |
---|
Number | -96 | 24 | 0 |
gainDecibel
PROPERTYGain value in decibel.
Type | Min | Max | Default |
---|
float | -96 | 24 | 0 |
marshall
PROPERTYEnables Marshall cabinet simulation.
Type | Min | Max | Default |
---|
Number | | | false |
marshall
PROPERTYEnables Marshall cabinet simulation.
Type | Min | Max | Default |
---|
boolean | | | false |
trebleFrequency
PROPERTYLow-pass filter frequency in Hz.
Type | Min | Max | Default |
---|
Number | 6000 | sample rate / 2 | sample rate / 2 - 100 |
trebleFrequency
PROPERTYLow-pass filter frequency in Hz.
Type | Min | Max | Default |
---|
float | 6000 | sample rate / 2 | sample rate / 2 - 100 |
vtwin
PROPERTYEnables V-Twin preamp simulation. Recommended for blues/jazz.
Type | Min | Max | Default |
---|
Number | | | false |
vtwin
PROPERTYEnables V-Twin preamp simulation. Recommended for blues/jazz.
Type | Min | Max | Default |
---|
boolean | | | false |
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 a GuitarDistortion instance.
ParametersName | Type | Description |
---|
samplerate | Number | The initial sample rate in Hz. |
ReturnsType | Description |
---|
Superpowered.GuitarDistortion | The constructed instance. |
constructor
METHODCreates a GuitarDistortion instance.
ParametersName | Type | Default | Description |
---|
samplerate | unsigned int | | The initial sample rate in Hz. |
ReturnsType | Description |
---|
Superpowered::GuitarDistortion | The constructed instance. |
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). |