Class: Delay
Interactive example
Overview
This simple delay effect outputs the input signal after a defined period of time, and the processing is performed by minimal memory operations.
Implementation example
The original audio is heard, followed by the delayed audio which is determined by the delayMs
property (delay in milliseconds).
class SuperpoweredDelayStageProcessor extends SuperpoweredWebAudio.AudioWorkletProcessor {// runs after the constructoronReady() {this.delay = new this.Superpowered.Delay(5000, // maximum value delayMs can be setthis.samplerate, // The maxiumum sample rate in Hz.1024, // maximum buffer size we might send this processorthis.samplerate // The initial sample rate in Hz.);}// Runs before the node is destroyed.// Clean up memory and objects here (such as free allocated linear memory or destruct Superpowered objects).onDestruct() {this.delay.destruct();}// messages are received from the main scope through this method.onMessageFromMainScope(message) {if (typeof message.delayMs !== 'undefined') this.delay.delayMs = message.delayMs;}processAudio(inputBuffer, outputBuffer, buffersize, parameters) {// Ensure the samplerate is in sync on every audio processing callbackthis.delay.samplerate = this.samplerate;let output = this.delay.process(inputBuffer.pointer, buffersize);// output is a pointer in Linear Memory. Create an array view on this.let jsArray = new Float32Array(this.Superpowered.linearMemory, // Linear memory buffer of the Superpowered module instance.output, // This linear memory index was returned by delay.process().buffersize * 2 // Number of frames multiplied by the number of channels. In this example, 128 * 2.);for (let n = 0; n < buffersize * 2 ; n++) outputBuffer.array[n] = jsArray[n];// Add the orginal signal into the mix so we can hear the delay effectthis.Superpowered.Add1(inputBuffer.pointer, outputBuffer.pointer, buffersize * 2);}}
#include "SuperpoweredDelay.h"void initDelay() {unsigned int maximumDelayMs = 100;unsigned int maximumSamplerate = 48000;unsigned int maximumNumberOfFramesToProcess = 48000;unsigned int samplerate = 44100;delay = new Superpowered::Delay(maximumDelayMs, maximumSamplerate, maximumNumberOfFramesToProcess, samplerate);}void processAudio(float *interleavedInput, float *interleavedOutput, unsigned int numberOfFrames, unsigned int samplerate) {// Ensure the samplerate is in sync on every audio processing callbackdelay->samplerate = samplerate;// Render the output buffersconst float *delayOutput = delay->process(interleavedInput, numberOfFrames);memcpy(interleavedOutput, delayOutput, numberOfFrames * sizeof(float) * 2);}
Properties
delayMs
PROPERTYDelay in milliseconds.
Type | Min | Max | Default | Number | 0 | 0 |
---|
delayMs
PROPERTYDelay in milliseconds.
Type | Min | Max | Default | float | 0 | 0 |
---|
samplerate
PROPERTYSample rate in Hz.
Type | Min | Max | Default | Number |
---|
samplerate
PROPERTYSample rate in Hz.
Type | Min | Max | Default | float |
---|
Methods
constructor
METHODCreates an instance of the Delay class.ParametersReturnsName Type Description maximumDelayMs Number
Maximum delay in milliseconds. Higher values increase memory usage. maximumSamplerate Number
Maximum sample rate to support. Higher values increase memory usage. maximumNumberOfFramesToProcess Number
Maximum number of frames for the process() call. Has minimum effect on memory usage. samplerate Number
The initial sample rate in Hz. Type Description Superpowered.Delay
The constructed instance. constructor
METHODCreates an instance of the Delay class.ParametersReturnsName Type Default Description maximumDelayMs unsigned int
Maximum delay in milliseconds. Higher values increase memory usage. maximumSamplerate unsigned int
Maximum sample rate to support. Higher values increase memory usage. maximumNumberOfFramesToProcess unsigned int
Maximum number of frames for the process() call. Has minimum effect on memory usage. samplerate unsigned int
The initial sample rate in Hz. Type Description Superpowered::Delay
The constructed instance. destruct
METHODDestructor to free Linear Memory.ParametersNoneReturnsNoneprocess
METHODProcesses the audio. It's never blocking for real-time usage. You can change any properties concurrently with process().ParametersReturnsName Type Description input Number (pointer in Linear Memory)
32-bit interleaved stereo input. Special case: set to 0 to empty all buffered content. numberOfFrames Number
Number of frames to input and output. Type Description Number (pointer in Linear Memory)
Returns with a pointer to floating point numbers, which is the output with numberOfFrames audio available in it. It is valid until the next call to process(). process
METHODProcesses the audio. It's never blocking for real-time usage. You can change any properties concurrently with process().ParametersReturnsName Type Default Description input float *
32-bit interleaved stereo input. Special case: set to 0 to empty all buffered content. numberOfFrames int
Number of frames to input and output. Type Description float *
Returns with a pointer to floating point numbers, which is the output with numberOfFrames audio available in it. It is valid until the next call to process(). processWithFx
METHODProcesses the audio. It's never blocking for real-time usage.ParametersReturnsName Type Description input Number (pointer in Linear Memory)
32-bit interleaved stereo input. Special case: set to 0 to empty all buffered content. numberOfFrames Number
Number of frames to input and output. 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. Type Description Number (pointer in Linear Memory)
Returns with a pointer to floating point numbers, which is the output with numberOfFrames audio available in it. It is valid until the next call to process(). processWithFx
METHODProcesses the audio. It's never blocking for real-time usage.ParametersReturnsName Type Default Description input float *
32-bit interleaved stereo input. Special case: set to 0 to empty all buffered content. numberOfFrames int
Number of frames to input and output. 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. Type Description float *
Returns with a pointer to floating point numbers, which is the output with numberOfFrames audio available in it. It is valid until the next call to process().