LMMS
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
27{
28namespace dsp
29{
30
31//==============================================================================
32template <typename SampleType>
33void Limiter<SampleType>::setThreshold (SampleType newThreshold)
34{
35 thresholddB = newThreshold;
36 update();
37}
38
39template <typename SampleType>
40void Limiter<SampleType>::setRelease (SampleType newRelease)
41{
42 releaseTime = newRelease;
43 update();
44}
45
46//==============================================================================
47template <typename SampleType>
49{
50 jassert (spec.sampleRate > 0);
51 jassert (spec.numChannels > 0);
52
54
55 firstStageCompressor.prepare (spec);
56 secondStageCompressor.prepare (spec);
57
58 update();
59 reset();
60}
61
62template <typename SampleType>
64{
67
68 outputVolume.reset (sampleRate, 0.001);
69}
70
71//==============================================================================
72template <typename SampleType>
74{
75 firstStageCompressor.setThreshold ((SampleType) -10.0);
76 firstStageCompressor.setRatio ((SampleType) 4.0);
77 firstStageCompressor.setAttack ((SampleType) 2.0);
78 firstStageCompressor.setRelease ((SampleType) 200.0);
79
81 secondStageCompressor.setRatio ((SampleType) 1000.0);
82 secondStageCompressor.setAttack ((SampleType) 0.001);
84
85 auto ratioInverse = (SampleType) (1.0 / 4.0);
86
87 auto gain = (SampleType) std::pow (10.0, 10.0 * (1.0 - ratioInverse) / 40.0);
88 gain *= Decibels::decibelsToGain (-thresholddB, (SampleType) -100.0);
89
90 outputVolume.setTargetValue (gain);
91}
92
93//==============================================================================
94template class Limiter<float>;
95template class Limiter<double>;
96
97} // namespace dsp
98} // namespace juce
static Type decibelsToGain(Type decibels, Type minusInfinityDb=Type(defaultMinusInfinitydB))
Definition juce_Decibels.h:42
Definition juce_Limiter.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
Compressor< SampleType > secondStageCompressor
Definition juce_Limiter.h:97
SampleType releaseTime
Definition juce_Limiter.h:101
void setThreshold(SampleType newThreshold)
Definition juce_Limiter.cpp:33
void update()
Definition juce_Limiter.cpp:73
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:38
uint32 numChannels
Definition juce_ProcessContext.h:46
double sampleRate
Definition juce_ProcessContext.h:40