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_Limiter.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>
31void Limiter<SampleType>::setThreshold (SampleType newThreshold)
32{
33 thresholddB = newThreshold;
34 update();
35}
36
37template <typename SampleType>
38void Limiter<SampleType>::setRelease (SampleType newRelease)
39{
40 releaseTime = newRelease;
41 update();
42}
43
44//==============================================================================
45template <typename SampleType>
47{
48 jassert (spec.sampleRate > 0);
49 jassert (spec.numChannels > 0);
50
51 sampleRate = spec.sampleRate;
52
53 firstStageCompressor.prepare (spec);
54 secondStageCompressor.prepare (spec);
55
56 update();
57 reset();
58}
59
60template <typename SampleType>
62{
63 firstStageCompressor.reset();
64 secondStageCompressor.reset();
65
66 outputVolume.reset (sampleRate, 0.001);
67}
68
69//==============================================================================
70template <typename SampleType>
72{
73 firstStageCompressor.setThreshold ((SampleType) -10.0);
74 firstStageCompressor.setRatio ((SampleType) 4.0);
75 firstStageCompressor.setAttack ((SampleType) 2.0);
76 firstStageCompressor.setRelease ((SampleType) 200.0);
77
78 secondStageCompressor.setThreshold (thresholddB);
79 secondStageCompressor.setRatio ((SampleType) 1000.0);
80 secondStageCompressor.setAttack ((SampleType) 0.001);
81 secondStageCompressor.setRelease (releaseTime);
82
83 auto ratioInverse = (SampleType) (1.0 / 4.0);
84
85 auto gain = (SampleType) std::pow (10.0, 10.0 * (1.0 - ratioInverse) / 40.0);
86 gain *= Decibels::decibelsToGain (-thresholddB, (SampleType) -100.0);
87
88 outputVolume.setTargetValue (gain);
89}
90
91//==============================================================================
92template class Limiter<float>;
93template class Limiter<double>;
94
95} // namespace juce::dsp
static Type decibelsToGain(Type decibels, Type minusInfinityDb=Type(defaultMinusInfinitydB))
Converts a dBFS value to its equivalent gain level.
A simple limiter with standard threshold and release time controls, featuring two compressors and a h...
void setThreshold(SampleType newThreshold)
Sets the threshold in dB of the limiter.
void prepare(const ProcessSpec &spec)
Initialises the processor.
void setRelease(SampleType newRelease)
Sets the release time in milliseconds of the limiter.
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.