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 constructor
onReady() {
this.delay = new this.Superpowered.Delay(
5000, // maximum value delayMs can be set
this.samplerate, // The maxiumum sample rate in Hz.
1024, // maximum buffer size we might send this processor
this.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 callback
this.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 effect
this.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 callback
delay->samplerate = samplerate;
// Render the output buffers
const float *delayOutput = delay->process(interleavedInput, numberOfFrames);
memcpy(interleavedOutput, delayOutput, numberOfFrames * sizeof(float) * 2);
}

Properties

delayMs

PROPERTY
Delay in milliseconds.
TypeMinMaxDefault
Number
00

delayMs

PROPERTY
Delay in milliseconds.
TypeMinMaxDefault
float
00

samplerate

PROPERTY
Sample rate in Hz.
TypeMinMaxDefault
Number

samplerate

PROPERTY
Sample rate in Hz.
TypeMinMaxDefault
float

Methods

  • constructor

    METHOD
    Creates an instance of the Delay class.
    Parameters
    NameTypeDescription
    maximumDelayMsNumberMaximum delay in milliseconds. Higher values increase memory usage.
    maximumSamplerateNumberMaximum sample rate to support. Higher values increase memory usage.
    maximumNumberOfFramesToProcessNumberMaximum number of frames for the process() call. Has minimum effect on memory usage.
    samplerateNumberThe initial sample rate in Hz.
    Returns
    TypeDescription
    Superpowered.DelayThe constructed instance.
  • constructor

    METHOD
    Creates an instance of the Delay class.
    Parameters
    NameTypeDefaultDescription
    maximumDelayMsunsigned intMaximum delay in milliseconds. Higher values increase memory usage.
    maximumSamplerateunsigned intMaximum sample rate to support. Higher values increase memory usage.
    maximumNumberOfFramesToProcessunsigned intMaximum number of frames for the process() call. Has minimum effect on memory usage.
    samplerateunsigned intThe initial sample rate in Hz.
    Returns
    TypeDescription
    Superpowered::DelayThe constructed instance.
  • destruct

    METHOD
    Destructor to free Linear Memory.
    Parameters
    None
    Returns
    None
  • process

    METHOD
    Processes the audio. It's never blocking for real-time usage. You can change any properties concurrently with process().
    Parameters
    NameTypeDescription
    inputNumber (pointer in Linear Memory)32-bit interleaved stereo input. Special case: set to 0 to empty all buffered content.
    numberOfFramesNumberNumber of frames to input and output.
    Returns
    TypeDescription
    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

    METHOD
    Processes the audio. It's never blocking for real-time usage. You can change any properties concurrently with process().
    Parameters
    NameTypeDefaultDescription
    inputfloat *32-bit interleaved stereo input. Special case: set to 0 to empty all buffered content.
    numberOfFramesintNumber of frames to input and output.
    Returns
    TypeDescription
    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

    METHOD
    Processes the audio. It's never blocking for real-time usage.
    Parameters
    NameTypeDescription
    inputNumber (pointer in Linear Memory)32-bit interleaved stereo input. Special case: set to 0 to empty all buffered content.
    numberOfFramesNumberNumber of frames to input and output.
    fxSuperpowered.FX objectA Superpowered FX class instance, such as a Filter. fx->process() will be used to pass audio from input to the internal buffer.
    Returns
    TypeDescription
    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

    METHOD
    Processes the audio. It's never blocking for real-time usage.
    Parameters
    NameTypeDefaultDescription
    inputfloat *32-bit interleaved stereo input. Special case: set to 0 to empty all buffered content.
    numberOfFramesintNumber of frames to input and output.
    fxSuperpowered::FX *A Superpowered FX class instance, such as a Filter. fx->process() will be used to pass audio from input to the internal buffer.
    Returns
    TypeDescription
    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().
v2.7.2