LMMS
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
27{
28namespace dsp
29{
30
31//==============================================================================
32template <typename SampleType>
34{
35 update();
36
38 RMSFilter.setAttackTime (static_cast<SampleType> (0.0));
39 RMSFilter.setReleaseTime (static_cast<SampleType> (50.0));
40}
41
42template <typename SampleType>
43void NoiseGate<SampleType>::setThreshold (SampleType newValue)
44{
45 thresholddB = newValue;
46 update();
47}
48
49template <typename SampleType>
50void NoiseGate<SampleType>::setRatio (SampleType newRatio)
51{
52 jassert (newRatio >= static_cast<SampleType> (1.0));
53
54 ratio = newRatio;
55 update();
56}
57
58template <typename SampleType>
59void NoiseGate<SampleType>::setAttack (SampleType newAttack)
60{
61 attackTime = newAttack;
62 update();
63}
64
65template <typename SampleType>
66void NoiseGate<SampleType>::setRelease (SampleType newRelease)
67{
68 releaseTime = newRelease;
69 update();
70}
71
72//==============================================================================
73template <typename SampleType>
75{
76 jassert (spec.sampleRate > 0);
77 jassert (spec.numChannels > 0);
78
80
81 RMSFilter.prepare (spec);
82 envelopeFilter.prepare (spec);
83
84 update();
85 reset();
86}
87
88template <typename SampleType>
90{
91 RMSFilter.reset();
92 envelopeFilter.reset();
93}
94
95//==============================================================================
96template <typename SampleType>
97SampleType NoiseGate<SampleType>::processSample (int channel, SampleType sample)
98{
99 // RMS ballistics filter
100 auto env = RMSFilter.processSample (channel, sample);
101
102 // Ballistics filter
103 env = envelopeFilter.processSample (channel, env);
104
105 // VCA
106 auto gain = (env > threshold) ? static_cast<SampleType> (1.0)
107 : std::pow (env * thresholdInverse, currentRatio - static_cast<SampleType> (1.0));
108
109 // Output
110 return gain * sample;
111}
112
113template <typename SampleType>
115{
116 threshold = Decibels::decibelsToGain (thresholddB, static_cast<SampleType> (-200.0));
117 thresholdInverse = static_cast<SampleType> (1.0) / threshold;
119
120 envelopeFilter.setAttackTime (attackTime);
121 envelopeFilter.setReleaseTime (releaseTime);
122}
123
124//==============================================================================
125template class NoiseGate<float>;
126template class NoiseGate<double>;
127
128} // namespace dsp
129} // namespace juce
static Type decibelsToGain(Type decibels, Type minusInfinityDb=Type(defaultMinusInfinitydB))
Definition juce_Decibels.h:42
Definition juce_NoiseGate.h:39
void prepare(const ProcessSpec &spec)
Definition juce_NoiseGate.cpp:74
SampleType thresholddB
Definition juce_NoiseGate.h:106
SampleType processSample(int channel, SampleType inputValue)
Definition juce_NoiseGate.cpp:97
void setRelease(SampleType newRelease)
Definition juce_NoiseGate.cpp:66
BallisticsFilter< SampleType > RMSFilter
Definition juce_NoiseGate.h:103
SampleType releaseTime
Definition juce_NoiseGate.h:106
void setRatio(SampleType newRatio)
Definition juce_NoiseGate.cpp:50
SampleType thresholdInverse
Definition juce_NoiseGate.h:102
SampleType ratio
Definition juce_NoiseGate.h:106
SampleType attackTime
Definition juce_NoiseGate.h:106
BallisticsFilter< SampleType > envelopeFilter
Definition juce_NoiseGate.h:103
double sampleRate
Definition juce_NoiseGate.h:105
SampleType currentRatio
Definition juce_NoiseGate.h:102
SampleType threshold
Definition juce_NoiseGate.h:102
void setAttack(SampleType newAttack)
Definition juce_NoiseGate.cpp:59
void setThreshold(SampleType newThreshold)
Definition juce_NoiseGate.cpp:43
NoiseGate()
Definition juce_NoiseGate.cpp:33
void reset()
Definition juce_NoiseGate.cpp:89
void update()
Definition juce_NoiseGate.cpp:114
#define jassert(expression)
Definition juce_AudioBlock.h:29
@ RMS
Definition juce_BallisticsFilter.h:34
Definition carla_juce.cpp:31
Definition juce_ProcessContext.h:38
uint32 numChannels
Definition juce_ProcessContext.h:46
double sampleRate
Definition juce_ProcessContext.h:40
signed int sample
Definition tap_dynamics_m.c:41