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_Compressor.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>
35
36//==============================================================================
37template <typename SampleType>
39{
40 thresholddB = newThreshold;
41 update();
42}
43
44template <typename SampleType>
46{
47 jassert (newRatio >= static_cast<SampleType> (1.0));
48
49 ratio = newRatio;
50 update();
51}
52
53template <typename SampleType>
55{
56 attackTime = newAttack;
57 update();
58}
59
60template <typename SampleType>
62{
63 releaseTime = newRelease;
64 update();
65}
66
67//==============================================================================
68template <typename SampleType>
70{
71 jassert (spec.sampleRate > 0);
72 jassert (spec.numChannels > 0);
73
74 sampleRate = spec.sampleRate;
75
76 envelopeFilter.prepare (spec);
77
78 update();
79 reset();
80}
81
82template <typename SampleType>
84{
85 envelopeFilter.reset();
86}
87
88//==============================================================================
89template <typename SampleType>
90SampleType Compressor<SampleType>::processSample (int channel, SampleType inputValue)
91{
92 // Ballistics filter with peak rectifier
93 auto env = envelopeFilter.processSample (channel, inputValue);
94
95 // VCA
97 : std::pow (env * thresholdInverse, ratioInverse - static_cast<SampleType> (1.0));
98
99 // Output
100 return gain * inputValue;
101}
102
103template <typename SampleType>
105{
106 threshold = Decibels::decibelsToGain (thresholddB, static_cast<SampleType> (-200.0));
107 thresholdInverse = static_cast<SampleType> (1.0) / threshold;
108 ratioInverse = static_cast<SampleType> (1.0) / ratio;
109
110 envelopeFilter.setAttackTime (attackTime);
111 envelopeFilter.setReleaseTime (releaseTime);
112}
113
114//==============================================================================
115template class Compressor<float>;
116template class Compressor<double>;
117
118} // namespace juce::dsp
static Type decibelsToGain(Type decibels, Type minusInfinityDb=Type(defaultMinusInfinitydB))
Converts a dBFS value to its equivalent gain level.
A simple compressor with standard threshold, ratio, attack time and release time controls.
void reset()
Resets the internal state variables of the processor.
void setThreshold(SampleType newThreshold)
Sets the threshold in dB of the compressor.
SampleType processSample(int channel, SampleType inputValue)
Performs the processing operation on a single sample at a time.
void prepare(const ProcessSpec &spec)
Initialises the processor.
void setAttack(SampleType newAttack)
Sets the attack time in milliseconds of the compressor.
void setRelease(SampleType newRelease)
Sets the release time in milliseconds of the compressor.
void setRatio(SampleType newRatio)
Sets the ratio of the compressor (must be higher or equal to 1).
#define jassert(expression)
Platform-independent assertion macro.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
T pow(T... args)
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...