OpenShot Audio Library | OpenShotAudio 0.4.0

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