Noise Gate
Overview
A noise gate is an audio tool that reduces unwanted noise by muting or attenuating signals below specified thresholds. It is typically used to eliminate background noise or hum. The noise_gate class implements a Q-flavored noise gate processor following Q’s Dynamic processor design. Unlike typical noise gates, noise_gate has no parameters for attack and release and does not process audio waveform samples directly. Instead, it operates on the envelope of the audio signal. The objective is separation of concerns and the flexibility to use various envelope followers.
There are two thresholds. On onsets, the noise_gate opens up if the signal envelope goes above the specified onset threshold. On note release, the noise_gate turns off if the signal goes below a specified release threshold.
Declaration
struct noise_gate
{
noise_gate(decibel onset_threshold, decibel release_threshold);
noise_gate(decibel release_threshold);
bool operator()(float env);
bool operator()() const;
void onset_threshold(decibel onset_threshold);
void onset_threshold(float onset_threshold);
void release_threshold(decibel release_threshold);
void release_threshold(float release_threshold);
float onset_threshold() const;
float release_threshold() const;
};
Expressions
Notation
g,a,b-
Objects of type
noise_gate. env-
Floating point value for the current envelope value.
ot,rt-
Object of type
decibelrepresenting onset and release thresholds, respectively. v-
Floating point value for a threshold as a linear value.
Constructors and Assignment
| Expression | Semantics |
|---|---|
|
Construct a |
|
Construct a |
|
Copy construct a |
|
Assign |
| C++ brace initialization may also be used. |
Function Call
| Expression | Semantics | Return Type |
|---|---|---|
|
Process the input envelope |
|
|
Get the current state. |
|
The noise_gate state is a boolean flag that is true if the noise_gate is open or false if the noise_gate is closed.
Mutators
| Expression | Semantics | Return Type |
|---|---|---|
|
Set the |
|
|
Set the |
|
|
Set the |
|
|
Set the |
|
Accessors
| Expression | Semantics | Return Type |
|---|---|---|
|
Get the |
|
|
Get the |
|
Example
Gate the input samples in, at sps samples per second, with an onset
threshold of -33 dB and a release threshold of -45 dB:
#include <q/fx/envelope.hpp> // For peak_envelope_follower
namespace q = cycfi::q;
using namespace q::literals;
auto env = q::peak_envelope_follower{30_ms, sps};
auto gate = q::noise_gate{-33_dB, -45_dB}; (1)
for (auto& s : in)
{
if (!gate(env(std::abs(s)))) (2)
s = 0.0f;
}
| 1 | Construct a noise gate with a -33 dB onset threshold and a -45 dB release threshold. |
| 2 | Follow the envelope of the sample, process it through the gate, and mute the sample while the gate is closed. |