LMMS
Loading...
Searching...
No Matches
juce_Limiter.h
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
37template <typename SampleType>
39{
40public:
41 //==============================================================================
43 Limiter() = default;
44
45 //==============================================================================
47 void setThreshold (SampleType newThreshold);
48
50 void setRelease (SampleType newRelease);
51
52 //==============================================================================
54 void prepare (const ProcessSpec& spec);
55
57 void reset();
58
59 //==============================================================================
61 template <typename ProcessContext>
62 void process (const ProcessContext& context) noexcept
63 {
64 const auto& inputBlock = context.getInputBlock();
65 auto& outputBlock = context.getOutputBlock();
66 const auto numChannels = outputBlock.getNumChannels();
67 const auto numSamples = outputBlock.getNumSamples();
68
69 jassert (inputBlock.getNumChannels() == numChannels);
70 jassert (inputBlock.getNumSamples() == numSamples);
71
72 if (context.isBypassed)
73 {
74 outputBlock.copyFrom (inputBlock);
75 return;
76 }
77
78 firstStageCompressor.process (context);
79
80 auto secondContext = ProcessContextReplacing<SampleType> (outputBlock);
81 secondStageCompressor.process (secondContext);
82
83 outputBlock.multiplyBy (outputVolume);
84
85 for (size_t channel = 0; channel < numChannels; ++channel)
86 {
87 FloatVectorOperations::clip (outputBlock.getChannelPointer (channel), outputBlock.getChannelPointer (channel),
88 (SampleType) -1.0, (SampleType) 1.0, (int) numSamples);
89 }
90 }
91
92private:
93 //==============================================================================
94 void update();
95
96 //==============================================================================
99
100 double sampleRate = 44100.0;
101 SampleType thresholddB = -10.0, releaseTime = 100.0;
102};
103
104} // namespace dsp
105} // namespace juce
Definition juce_SmoothedValue.h:227
Definition juce_Compressor.h:39
void prepare(const ProcessSpec &spec)
Definition juce_Limiter.cpp:48
void reset()
Definition juce_Limiter.cpp:63
SampleType thresholddB
Definition juce_Limiter.h:101
SmoothedValue< SampleType, ValueSmoothingTypes::Linear > outputVolume
Definition juce_Limiter.h:98
void process(const ProcessContext &context) noexcept
Definition juce_Limiter.h:62
Compressor< SampleType > secondStageCompressor
Definition juce_Limiter.h:97
SampleType releaseTime
Definition juce_Limiter.h:101
void setThreshold(SampleType newThreshold)
Definition juce_Limiter.cpp:33
double sampleRate
Definition juce_Limiter.h:100
Compressor< SampleType > firstStageCompressor
Definition juce_Limiter.h:97
void setRelease(SampleType newRelease)
Definition juce_Limiter.cpp:40
#define jassert(expression)
Definition juce_AudioBlock.h:29
Definition carla_juce.cpp:31
Definition juce_ProcessContext.h:88
Definition juce_ProcessContext.h:38