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
PROPERTYType | Min | Max | Default | Number | 0.03125 | 2 | 0.5 |
---|
beats
PROPERTYType | Min | Max | Default | float | 0.03125 | 2 | 0.5 |
---|
bpm
PROPERTYType | Min | Max | Default | Number | 40 | 250 | 128 |
---|
bpm
PROPERTYType | Min | Max | Default | float | 40 | 250 | 128 |
---|
decay
PROPERTYType | Min | Max | Default | Number | 0 | 0.99 | 0.5 |
---|
decay
PROPERTYType | Min | Max | Default | float | 0 | 0.99 | 0.5 |
---|
dry
PROPERTYType | Min | Max | Default | Number | 0 | 1 | 1 |
---|
dry
PROPERTYType | Min | Max | Default | float | 0 | 1 | 1 |
---|
wet
PROPERTYType | Min | Max | Default | Number | 0 | 1 | 0.5 |
---|
wet
PROPERTYType | Min | Max | Default | float | 0 | 1 | 0.5 |
---|
enabled
PROPERTYType | Min | Max | Default | Boolean | false |
---|
enabled
PROPERTYType | Min | Max | Default | bool | false |
---|
samplerate
PROPERTYType | Min | Max | Default | Number |
---|
samplerate
PROPERTYType | Min | Max | Default | unsigned int |
---|
Methods
constructor
METHODCreates an instance of the Echo class.ParametersReturnsName Type Description samplerate Number
The initial sample rate in Hz. maximumSamplerate Number
Maximum sample rate (affects memory usage, the lower the smaller). Type Description Superpowered.Echo
The constructed instance. constructor
METHODCreates an instance of the Echo class.ParametersReturnsName Type Default Description samplerate unsigned int
The initial sample rate in Hz. maximumSamplerate unsigned int
96000 Maximum sample rate (affects memory usage, the lower the smaller). Type Description Superpowered::Echo
The 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 Number
Number of frames to process. Recommendations for best performance: multiply of 4, minimum 64. fx Superpowered.FX object
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 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). 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 int
Number 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 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). 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 Number
Mix 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 float
Mix 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 Number
Number of frames to process. Recommendations for best performance: multiply of 4, minimum 64. Type 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().ParametersReturnsName 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. Type 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).