FX Class: Gate
Interactive example
Overview
The Gate effect creates periodic attenuation of the audio signal.
The wet
property allows you to control the strength of the effect with values between 0 and 1, while the bpm
and beats
property allow you to control the rhythm to open and close the gate.
It doesn't allocate any internal buffers and needs just a few bytes of memory.
Implementation example
class SuperpoweredFlangerProcessor extends SuperpoweredWebAudio.AudioWorkletProcessor {// Called when the AudioWorklet is ready to start processing audioonReady() {this.gate = new this.Superpowered.Gate(this.samplerate, // The initial sample rate in Hz.);this.gate.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.gate.destruct();}// messages are received from the main scope through this method.onMessageFromMainScope(message) {if (typeof message.wet !== 'undefined') this.gate.wet = message.wet;if (typeof message.beats !== 'undefined') this.gate.beats = message.beats;if (typeof message.bpm !== 'undefined') this.gate.bpm = message.bpm;if (typeof message.enabled !== 'undefined') this.gate.enabled = Boolean(message.enabled);}processAudio(inputBuffer, outputBuffer, buffersize, parameters) {// Ensure the samplerate is in sync on every audio processing callbackthis.gate.samplerate = this.samplerate;// Render the output buffersif (!this.gate.process(inputBuffer.pointer, outputBuffer.pointer, buffersize)) {for (let n = 0; n < buffersize * 2 ; n++) outputBuffer.array[n] = inputBuffer.array[n];}}}
#include "SuperpoweredGate.h"void initGateEffect() {const unsigned int sampleRate = 44100;gate = new Superpowered::Gate(sampleRate);gate->enabled = true;}void configureGateEffect() {gate->wet = 0.5;gate->bpm = 128;gate->beats = 1;}void processAudio(float *interleavedInput, float *interleavedOutput, unsigned int numberOfFrames, unsigned int samplerate) {// Ensure the samplerate is in sync on every audio processing callbackgate->samplerate = samplerate;// Render the output buffersbool outputChanged = gate->process(interleavedInput, interleavedOutput, numberOfFrames);...}
Properties
beats
PROPERTYThe rhythm in beats to open and close the "gate".
Type | Min | Max | Default | Number | 0.015625 (1/64) | 4 | 1 |
---|
beats
PROPERTYThe rhythm in beats to open and close the "gate".
Type | Min | Max | Default | float | 0.015625 (1/64) | 4 | 1 |
---|
bpm
PROPERTYThe bpm of the current audio, defines the speed of the gate.
Type | Min | Max | Default | Number | 40 | 250 | 40 |
---|
bpm
PROPERTYThe bpm of the current audio, defines the speed of the gate.
Type | Min | Max | Default | double | 40 | 250 | 40 |
---|
wet
PROPERTYThe dominance of the effect.
Type | Min | Max | Default | Number | 0 | 1 | 0.5 |
---|
wet
PROPERTYThe dominance of the effect.
Type | Min | Max | Default | float | 0 | 1 | 0.5 |
---|
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 | 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.
Type | Min | Max | Default | Number |
---|
samplerate
PROPERTYThe sample rate of the audio context, you must update if it changes.
Type | Min | Max | Default | unsigned int |
---|
Methods
constructor
METHODCreates an instance of the Gate class.ParametersReturnsName Type Description samplerate Number
The initial sample rate in Hz. Type Description Superpowered.Gate
The constructed instance. constructor
METHODCreates an instance of the Gate class.ParametersReturnsName Type Default Description samplerate unsigned int
The initial sample rate in Hz. Type Description Superpowered::Gate
The constructed instance.
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).