OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_Compressor.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 Compressor
37{
38 public:
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
95 private:
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
juce::dsp::BallisticsFilter
Definition juce_BallisticsFilter.h:44
juce::dsp::Compressor
Definition juce_Compressor.h:37
juce::dsp::Compressor::reset
void reset()
Definition juce_Compressor.cpp:83
juce::dsp::Compressor::setThreshold
void setThreshold(SampleType newThreshold)
Definition juce_Compressor.cpp:38
juce::dsp::Compressor::processSample
SampleType processSample(int channel, SampleType inputValue)
Definition juce_Compressor.cpp:90
juce::dsp::Compressor::process
void process(const ProcessContext &context) noexcept
Definition juce_Compressor.h:66
juce::dsp::Compressor::prepare
void prepare(const ProcessSpec &spec)
Definition juce_Compressor.cpp:69
juce::dsp::Compressor::setAttack
void setAttack(SampleType newAttack)
Definition juce_Compressor.cpp:54
juce::dsp::Compressor::setRelease
void setRelease(SampleType newRelease)
Definition juce_Compressor.cpp:61
juce::dsp::Compressor::setRatio
void setRatio(SampleType newRatio)
Definition juce_Compressor.cpp:45
juce::dsp::Compressor::Compressor
Compressor()
Definition juce_Compressor.cpp:31
juce::dsp::ProcessSpec
Definition juce_ProcessContext.h:36