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.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::dsp
27{
28
35template <typename SampleType>
37{
38public:
39 //==============================================================================
41 Compressor();
42
43 //==============================================================================
45 void setThreshold (SampleType newThreshold);
46
48 void setRatio (SampleType newRatio);
49
51 void setAttack (SampleType newAttack);
52
54 void setRelease (SampleType newRelease);
55
56 //==============================================================================
58 void prepare (const ProcessSpec& spec);
59
61 void reset();
62
63 //==============================================================================
65 template <typename ProcessContext>
66 void process (const ProcessContext& context) noexcept
67 {
68 const auto& inputBlock = context.getInputBlock();
69 auto& outputBlock = context.getOutputBlock();
70 const auto numChannels = outputBlock.getNumChannels();
71 const auto numSamples = outputBlock.getNumSamples();
72
73 jassert (inputBlock.getNumChannels() == numChannels);
74 jassert (inputBlock.getNumSamples() == numSamples);
75
76 if (context.isBypassed)
77 {
78 outputBlock.copyFrom (inputBlock);
79 return;
80 }
81
82 for (size_t channel = 0; channel < numChannels; ++channel)
83 {
84 auto* inputSamples = inputBlock .getChannelPointer (channel);
85 auto* outputSamples = outputBlock.getChannelPointer (channel);
86
87 for (size_t i = 0; i < numSamples; ++i)
88 outputSamples[i] = processSample ((int) channel, inputSamples[i]);
89 }
90 }
91
93 SampleType processSample (int channel, SampleType inputValue);
94
95private:
96 //==============================================================================
97 void update();
98
99 //==============================================================================
100 SampleType threshold, thresholdInverse, ratioInverse;
101 BallisticsFilter<SampleType> envelopeFilter;
102
103 double sampleRate = 44100.0;
104 SampleType thresholddB = 0.0, ratio = 1.0, attackTime = 1.0, releaseTime = 100.0;
105};
106
107} // namespace juce::dsp
A processor to apply standard attack / release ballistics to an input signal.
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 process(const ProcessContext &context) noexcept
Processes the input and output samples supplied in the processing context.
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
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...