FX Class: Echo
Interactive example
Overview
This simple Echo effect is based on delaying a signal over time. Listeners perceive an audible repetition of a signal after some duration of time.
Implementation example
The wet property is the volume of each repeat and the the dry property is the volume of the original sound. Both values can be set between 0.0 and 1.0, **or** the setMix() method can be used instead to balance between the two.
The decay property controls the tail or trail of the echo which can be set between 0 and 1. The user also has access to the bpm property (beats per minute) of the echo (between 40 and 250) and the beats property which controls the delay in beats (between 0.03125 and 2).
One instance allocates around 770 kb memory.
Usage example without the optional FX processing chain:
class SuperpoweredEchoStageProcessor extends SuperpoweredWebAudio.AudioWorkletProcessor {onReady() {this.echo = new this.Superpowered.Echo(this.samplerate, // the samplerate96000 // The maximumSamplerate, the same in this case);this.effect.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.echo.destruct();}// Messages are received from the main scope through this method.onMessageFromMainScope(message) {if (typeof(message.dry) != 'undefined') this.echo.dry = message.dry;if (typeof(message.wet) != 'undefined') this.echo.wet = message.wet;if (typeof(message.bpm) != 'undefined') this.echo.bpm = message.bpm;if (typeof(message.decay) != 'undefined') this.echo.decay = message.decay;if (typeof(message.beats) != 'undefined') this.echo.beats = message.beats;if (typeof(message.enabled) != 'undefined') this.echo.enabled = Boolean(message.enabled);}// THe mai process block of the DSPprocessAudio(inputBuffer, outputBuffer, buffersize, parameters) {// Ensure the samplerate is in sync on every audio processing callbackthis.echo.samplerate = this.samplerate;// Render the output buffersif (!this.echo.process(inputBuffer.pointer, outputBuffer.pointer, buffersize)) {for (let n = 0; n < buffersize * 2 ; n++) outputBuffer.array[n] = inputBuffer.array[n];}}}
Or, to use with an optional effect FX added to the wet signal:
class SuperpoweredEchoStageProcessor extends SuperpoweredWebAudio.AudioWorkletProcessor {onReady() {this.echo = new this.Superpowered.Echo(this.samplerate,96000);this.filter = new this.Superpowered.Filter(this.Superpowered.Filter.Resonant_Lowpass,this.samplerate);this.echo.enabled = true;this.filter.frequency = 4000;this.filter.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.echo.destruct();this.filter.destruct();}// messages are received from the main scope through this method.onMessageFromMainScope(message) {if (typeof(message.dry) != 'undefined') this.echo.dry = message.dry;if (typeof(message.wet) != 'undefined') this.echo.wet = message.wet;if (typeof(message.bpm) != 'undefined') this.echo.bpm = message.bpm;if (typeof(message.decay) != 'undefined') this.echo.decay = message.decay;if (typeof(message.beats) != 'undefined') this.echo.beats = message.beats;if (typeof(message.enabled) != 'undefined') this.echo.enabled = Boolean(message.enabled);if (typeof(message.frequency) != 'undefined') this.filter.frequency = Number(message.frequency);}processAudio(inputBuffer, outputBuffer, buffersize, parameters) {// Ensure the samplerate is in sync on every audio processing callbackthis.echo.samplerate = this.samplerate;this.filter.samplerate = this.samplerate;// Render the output buffersif (!this.echo.processWithFx(inputBuffer.pointer, outputBuffer.pointer, buffersize, this.filter)) {for (let n = 0; n < buffersize * 2 ; n++) outputBuffer.array[n] = inputBuffer.array[n];}}}
To setup without the optional FX processing chain
#include "SuperpoweredEcho.h"void initEchoEffect() {const unsigned int sampleRate = 44100;echo = new Superpowered::Echo(sampleRate);}void configureEchoEffect() {echo->dry = 0.5;echo->wet = 42;echo->bpm = 170;echo->decay = 0.5;echo->beats = 0.5;echo->enabled = true;}void processAudio(float *interleavedInput, float *interleavedOutput, unsigned int numberOfFrames, unsigned int samplerate) {// Ensure the samplerate is in sync on every audio processing callbackecho->samplerate = samplerate;// Render the output buffersbool outputChanged = echo->process(interleavedInput, interleavedOutput, numberOfFrames);...}
Or, to use with the optional FX processing chain
#include "SuperpoweredEcho.h"void initEchoEffect() {const unsigned int sampleRate = 44100;const unsigned int maximumSampleRate = 96000;echo = new Superpowered::Echo(sampleRate, maximumSampleRate);filter = new Superpowered::Filter(Superpowered::Filter::Resonant_Lowpass, sampleRate);}void configureEchoEffect() {echo->dry = 0.5;echo->wet = 42;echo->bpm = 170;echo->decay = 0.5;echo->beats = 0.5;echo->enabled = true;filter->frequency - 4000;filter->enabled = true;}void processAudio(float *interleavedInput, float *interleavedOutput, unsigned int numberOfFrames, unsigned int samplerate) {// Ensure the samplerate is in sync on every audio processing callbackecho->samplerate = samplerate;filter->samplerate = samplerate;// Render the output buffersbool outputChanged = echo->processWithFx(interleavedInput, interleavedOutput, numberOfFrames, filter);...}
The optional FX processing is demonstrated below:
Properties
beats
PROPERTY| Type | Min | Max | Default | Number | 0.03125 | 2 | 0.5 |
|---|
beats
PROPERTY| Type | Min | Max | Default | float | 0.03125 | 2 | 0.5 |
|---|
bpm
PROPERTY| Type | Min | Max | Default | Number | 40 | 250 | 128 |
|---|
bpm
PROPERTY| Type | Min | Max | Default | float | 40 | 250 | 128 |
|---|
decay
PROPERTY| Type | Min | Max | Default | Number | 0 | 0.99 | 0.5 |
|---|
decay
PROPERTY| Type | Min | Max | Default | float | 0 | 0.99 | 0.5 |
|---|
dry
PROPERTY| Type | Min | Max | Default | Number | 0 | 1 | 1 |
|---|
dry
PROPERTY| Type | Min | Max | Default | float | 0 | 1 | 1 |
|---|
wet
PROPERTY| Type | Min | Max | Default | Number | 0 | 1 | 0.5 |
|---|
wet
PROPERTY| Type | Min | Max | Default | float | 0 | 1 | 0.5 |
|---|
enabled
PROPERTY| Type | Min | Max | Default | Boolean | false |
|---|
enabled
PROPERTY| Type | Min | Max | Default | bool | false |
|---|
samplerate
PROPERTY| Type | Min | Max | Default | Number |
|---|
samplerate
PROPERTY| Type | Min | Max | Default | unsigned int |
|---|
Methods
constructor
METHODCreates an instance of the Echo class.ParametersReturnsName Type Description samplerate NumberThe initial sample rate in Hz. maximumSamplerate NumberMaximum sample rate (affects memory usage, the lower the smaller). Type Description Superpowered.EchoThe constructed instance. constructor
METHODCreates an instance of the Echo class.ParametersReturnsName Type Default Description samplerate unsigned intThe initial sample rate in Hz. maximumSamplerate unsigned int96000 Maximum sample rate (affects memory usage, the lower the smaller). Type Description Superpowered::EchoThe constructed instance. processWithFx
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 properties and call setMix() on any thread, concurrently with process().ParametersReturnsName 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 NumberNumber of frames to process. Recommendations for best performance: multiply of 4, minimum 64. fx Superpowered.FX objectA Superpowered FX class instance, such as a Filter. fx->process() will be used to pass audio from input to the internal buffer, "coloring" the echo sounds. Type Description 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). processWithFx
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 properties and call setMix() on any thread, concurrently with process().ParametersReturnsName Type Default Description input float *32-bit interleaved stereo input. output float *32-bit interleaved stereo output. numberOfFrames unsigned intNumber of frames to process. Recommendations for best performance: multiply of 4, minimum 64. fx Superpowered::FX *A Superpowered FX class instance, such as a Filter. fx->process() will be used to pass audio from input to the internal buffer, "coloring" the echo sounds. Type Description 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). setMix
METHODSets dry and wet simultaneously with a good balance between them. Wet always equals to mix, but dry changes with a curve.ParametersReturnsName Type Description mix NumberMix value >= 0 and <= 1. NonesetMix
METHODSets dry and wet simultaneously with a good balance between them. Wet always equals to mix, but dry changes with a curve.ParametersReturnsName Type Default Description mix floatMix value >= 0 and <= 1. None
destruct
METHODDestructor to free Linear Memory.ParametersNoneReturnsNoneprocess
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.ParametersReturnsName 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 NumberNumber of frames to process. Recommendations for best performance: multiply of 4, minimum 64. Type Description 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
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().ParametersReturnsName Type Default Description input float *32-bit interleaved stereo input. output float *32-bit interleaved stereo output. numberOfFrames unsigned intNumber of frames to process. Recommendations for best performance: multiply of 4, minimum 64. Type Description 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).