JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_NoiseGate.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce::dsp
27{
28
29//==============================================================================
30template <typename SampleType>
32{
33 update();
34
35 RMSFilter.setLevelCalculationType (BallisticsFilterLevelCalculationType::RMS);
36 RMSFilter.setAttackTime (static_cast<SampleType> (0.0));
37 RMSFilter.setReleaseTime (static_cast<SampleType> (50.0));
38}
39
40template <typename SampleType>
41void NoiseGate<SampleType>::setThreshold (SampleType newValue)
42{
43 thresholddB = newValue;
44 update();
45}
46
47template <typename SampleType>
48void NoiseGate<SampleType>::setRatio (SampleType newRatio)
49{
50 jassert (newRatio >= static_cast<SampleType> (1.0));
51
52 ratio = newRatio;
53 update();
54}
55
56template <typename SampleType>
57void NoiseGate<SampleType>::setAttack (SampleType newAttack)
58{
59 attackTime = newAttack;
60 update();
61}
62
63template <typename SampleType>
64void NoiseGate<SampleType>::setRelease (SampleType newRelease)
65{
66 releaseTime = newRelease;
67 update();
68}
69
70//==============================================================================
71template <typename SampleType>
73{
74 jassert (spec.sampleRate > 0);
75 jassert (spec.numChannels > 0);
76
77 sampleRate = spec.sampleRate;
78
79 RMSFilter.prepare (spec);
80 envelopeFilter.prepare (spec);
81
82 update();
83 reset();
84}
85
86template <typename SampleType>
88{
89 RMSFilter.reset();
90 envelopeFilter.reset();
91}
92
93//==============================================================================
94template <typename SampleType>
95SampleType NoiseGate<SampleType>::processSample (int channel, SampleType sample)
96{
97 // RMS ballistics filter
98 auto env = RMSFilter.processSample (channel, sample);
99
100 // Ballistics filter
101 env = envelopeFilter.processSample (channel, env);
102
103 // VCA
104 auto gain = (env > threshold) ? static_cast<SampleType> (1.0)
105 : std::pow (env * thresholdInverse, currentRatio - static_cast<SampleType> (1.0));
106
107 // Output
108 return gain * sample;
109}
110
111template <typename SampleType>
113{
114 threshold = Decibels::decibelsToGain (thresholddB, static_cast<SampleType> (-200.0));
115 thresholdInverse = static_cast<SampleType> (1.0) / threshold;
116 currentRatio = ratio;
117
118 envelopeFilter.setAttackTime (attackTime);
119 envelopeFilter.setReleaseTime (releaseTime);
120}
121
122//==============================================================================
123template class NoiseGate<float>;
124template class NoiseGate<double>;
125
126} // namespace juce::dsp
static Type decibelsToGain(Type decibels, Type minusInfinityDb=Type(defaultMinusInfinitydB))
Converts a dBFS value to its equivalent gain level.
A simple noise gate with standard threshold, ratio, attack time and release time controls.
void prepare(const ProcessSpec &spec)
Initialises the processor.
SampleType processSample(int channel, SampleType inputValue)
Performs the processing operation on a single sample at a time.
void setRelease(SampleType newRelease)
Sets the release time in milliseconds of the noise-gate.
void setRatio(SampleType newRatio)
Sets the ratio of the noise-gate (must be higher or equal to 1).
void setAttack(SampleType newAttack)
Sets the attack time in milliseconds of the noise-gate.
void setThreshold(SampleType newThreshold)
Sets the threshold in dB of the noise-gate.
void reset()
Resets the internal state variables of the processor.
#define jassert(expression)
Platform-independent assertion macro.
T pow(T... args)
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...
uint32 numChannels
The number of channels that the process() method will be expected to handle.
double sampleRate
The sample rate that will be used for the data that is sent to the processor.