2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
23 ==============================================================================
32 A simple limiter with standard threshold and release time controls, featuring
33 two compressors and a hard clipper at 0 dB.
37 template <typename SampleType
>
41 //==============================================================================
45 //==============================================================================
46 /** Sets the threshold in dB of the limiter.*/
47 void setThreshold (SampleType newThreshold
);
49 /** Sets the release time in milliseconds of the limiter.*/
50 void setRelease (SampleType newRelease
);
52 //==============================================================================
53 /** Initialises the processor. */
54 void prepare (const ProcessSpec
& spec
);
56 /** Resets the internal state variables of the processor. */
59 //==============================================================================
60 /** Processes the input and output samples supplied in the processing context. */
61 template <typename ProcessContext
>
62 void process (const ProcessContext
& context
) noexcept
64 const auto& inputBlock
= context
.getInputBlock();
65 auto& outputBlock
= context
.getOutputBlock();
66 const auto numChannels
= outputBlock
.getNumChannels();
67 const auto numSamples
= outputBlock
.getNumSamples();
69 jassert (inputBlock
.getNumChannels() == numChannels
);
70 jassert (inputBlock
.getNumSamples() == numSamples
);
72 if (context
.isBypassed
)
74 outputBlock
.copyFrom (inputBlock
);
78 firstStageCompressor
.process (context
);
80 auto secondContext
= ProcessContextReplacing
<SampleType
> (outputBlock
);
81 secondStageCompressor
.process (secondContext
);
83 outputBlock
.multiplyBy (outputVolume
);
85 for (size_t channel
= 0; channel
< numChannels
; ++channel
)
87 FloatVectorOperations::clip (outputBlock
.getChannelPointer (channel
), outputBlock
.getChannelPointer (channel
),
88 (SampleType
) -1.0, (SampleType
) 1.0, (int) numSamples
);
93 //==============================================================================
96 //==============================================================================
97 Compressor
<SampleType
> firstStageCompressor
, secondStageCompressor
;
98 SmoothedValue
<SampleType
, ValueSmoothingTypes::Linear
> outputVolume
;
100 double sampleRate
= 44100.0;
101 SampleType thresholddB
= -10.0, releaseTime
= 100.0;