OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_BallisticsFilter.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
29 enum class BallisticsFilterLevelCalculationType
30{
31 peak,
32 RMS
33};
34
42 template <typename SampleType>
43 class BallisticsFilter
44{
45 public:
46 //==============================================================================
47 using LevelCalculationType = BallisticsFilterLevelCalculationType;
48
49 //==============================================================================
51 BallisticsFilter();
52
53 //==============================================================================
59 void setAttackTime (SampleType attackTimeMs);
60
67 void setReleaseTime (SampleType releaseTimeMs);
68
81 void setLevelCalculationType (LevelCalculationType newCalculationType);
82
83 //==============================================================================
85 void prepare (const ProcessSpec& spec);
86
88 void reset();
89
91 void reset (SampleType initialValue);
92
93 //==============================================================================
95 template <typename ProcessContext>
96 void process (const ProcessContext& context) noexcept
97 {
98 const auto& inputBlock = context.getInputBlock();
99 auto& outputBlock = context.getOutputBlock();
100 const auto numChannels = outputBlock.getNumChannels();
101 const auto numSamples = outputBlock.getNumSamples();
102
103 jassert (inputBlock.getNumChannels() <= yold.size());
104 jassert (inputBlock.getNumChannels() == numChannels);
105 jassert (inputBlock.getNumSamples() == numSamples);
106
107 if (context.isBypassed)
108 {
109 outputBlock.copyFrom (inputBlock);
110 return;
111 }
112
113 for (size_t channel = 0; channel < numChannels; ++channel)
114 {
115 auto* inputSamples = inputBlock .getChannelPointer (channel);
116 auto* outputSamples = outputBlock.getChannelPointer (channel);
117
118 for (size_t i = 0; i < numSamples; ++i)
119 outputSamples[i] = processSample ((int) channel, inputSamples[i]);
120 }
121
122 #if JUCE_DSP_ENABLE_SNAP_TO_ZERO
123 snapToZero();
124 #endif
125 }
126
128 SampleType processSample (int channel, SampleType inputValue);
129
134 void snapToZero() noexcept;
135
136private:
137 //==============================================================================
138 SampleType calculateLimitedCte (SampleType) const noexcept;
139
140 //==============================================================================
141 std::vector<SampleType> yold;
142 double sampleRate = 44100.0, expFactor = -0.142;
143 SampleType attackTime = 1.0, releaseTime = 100.0, cteAT = 0.0, cteRL = 0.0;
144 LevelCalculationType levelType = LevelCalculationType::peak;
145};
146
147} // namespace juce::dsp
juce::dsp::BallisticsFilter
Definition juce_BallisticsFilter.h:44
juce::dsp::BallisticsFilter::processSample
SampleType processSample(int channel, SampleType inputValue)
Definition juce_BallisticsFilter.cpp:89
juce::dsp::BallisticsFilter::reset
void reset()
Definition juce_BallisticsFilter.cpp:76
juce::dsp::BallisticsFilter::BallisticsFilter
BallisticsFilter()
Definition juce_BallisticsFilter.cpp:31
juce::dsp::BallisticsFilter::setAttackTime
void setAttackTime(SampleType attackTimeMs)
Definition juce_BallisticsFilter.cpp:38
juce::dsp::BallisticsFilter::prepare
void prepare(const ProcessSpec &spec)
Definition juce_BallisticsFilter.cpp:59
juce::dsp::BallisticsFilter::setReleaseTime
void setReleaseTime(SampleType releaseTimeMs)
Definition juce_BallisticsFilter.cpp:45
juce::dsp::BallisticsFilter::process
void process(const ProcessContext &context) noexcept
Definition juce_BallisticsFilter.h:96
juce::dsp::BallisticsFilter::snapToZero
void snapToZero() noexcept
Definition juce_BallisticsFilter.cpp:110
juce::dsp::BallisticsFilter::setLevelCalculationType
void setLevelCalculationType(LevelCalculationType newCalculationType)
Definition juce_BallisticsFilter.cpp:52
juce::dsp::ProcessSpec
Definition juce_ProcessContext.h:36