OpenShot Audio Library | OpenShotAudio: juce_NoiseGate.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0 |

Loading...
Searching...
No Matches
juce_NoiseGate.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
26namespace juce::dsp
27{
28
35template <typename SampleType>
36 class NoiseGate
37{
38public:
39 //==============================================================================
41 NoiseGate();
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, currentRatio;
101 BallisticsFilter<SampleType> envelopeFilter, RMSFilter;
102
103 double sampleRate = 44100.0;
104 SampleType thresholddB = -100, ratio = 10.0, attackTime = 1.0, releaseTime = 100.0;
105};
106
107} // namespace juce::dsp
juce::dsp::BallisticsFilter
Definition juce_BallisticsFilter.h:44
juce::dsp::NoiseGate::prepare
void prepare(const ProcessSpec &spec)
Definition juce_NoiseGate.cpp:72
juce::dsp::NoiseGate::processSample
SampleType processSample(int channel, SampleType inputValue)
Definition juce_NoiseGate.cpp:95
juce::dsp::NoiseGate::setRelease
void setRelease(SampleType newRelease)
Definition juce_NoiseGate.cpp:64
juce::dsp::NoiseGate::setRatio
void setRatio(SampleType newRatio)
Definition juce_NoiseGate.cpp:48
juce::dsp::NoiseGate::process
void process(const ProcessContext &context) noexcept
Definition juce_NoiseGate.h:66
juce::dsp::NoiseGate::setAttack
void setAttack(SampleType newAttack)
Definition juce_NoiseGate.cpp:57
juce::dsp::NoiseGate::setThreshold
void setThreshold(SampleType newThreshold)
Definition juce_NoiseGate.cpp:41
juce::dsp::NoiseGate::NoiseGate
NoiseGate()
Definition juce_NoiseGate.cpp:31
juce::dsp::NoiseGate::reset
void reset()
Definition juce_NoiseGate.cpp:87
juce::dsp::ProcessSpec
Definition juce_ProcessContext.h:36