WE Core
Loading...
Searching...
No Matches
AREnvelopeFollowerBase.h
Go to the documentation of this file.
1/*
2 * File: AREnveloperFollowerBase.h
3 *
4 * Created: 27/05/2017
5 *
6 * This file is part of WECore.
7 *
8 * WECore is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * WECore is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with WECore. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
25#include "ModulationSource.h"
26#include "TPTSVFilter.h"
27
28namespace WECore::AREnv {
34 public:
35 AREnvelopeFollowerBase() : _attackTimeMs(Parameters::ATTACK_MS.defaultValue),
36 _releaseTimeMs(Parameters::RELEASE_MS.defaultValue),
37 _filterEnabled(Parameters::FILTER_ENABLED.defaultValue) {
38 // call this here rather than setting it in initialiser list so that the coefficients get
39 // setup
40 reset();
41 setSampleRate(44100);
42
47 }
48
49 virtual ~AREnvelopeFollowerBase() override = default;
50
60 inline void setSampleRate(double sampleRate);
61
69 inline void setAttackTimeMs(double time);
70
78 inline void setReleaseTimeMs(double time);
79
87 void setFilterEnabled(bool isEnabled) { _filterEnabled = isEnabled; }
88
96 void setLowCutHz(double freq) { _lowCutFilter.setCutoff(freq); }
97
105 void setHighCutHz(double freq) { _highCutFilter.setCutoff(freq); }
114 double getAttackTimeMs() const { return _attackTimeMs; }
115
119 double getReleaseTimeMs() const { return _releaseTimeMs; }
120
124 bool getFilterEnabled() const { return _filterEnabled; }
125
129 double getLowCutHz() const { return _lowCutFilter.getCutoff(); }
130
134 double getHighCutHz() const { return _highCutFilter.getCutoff(); }
137 protected:
138 double _envVal;
139
142
145
149
151
155 inline double _getNextOutputImpl(double inSample) override;
156
157 virtual inline double _envGetNextOutputImpl(double inSample) = 0;
158
159 inline void _resetImpl() override;
160
161 double _calcCoef(double timeMs) {
162 return exp(log(0.01) / (timeMs * _sampleRate * 0.001));
163 }
164 };
165
167 _sampleRate = sampleRate;
170
171 _lowCutFilter.setSampleRate(sampleRate);
172 _highCutFilter.setSampleRate(sampleRate);
173 }
174
179
184
186 if (_filterEnabled) {
187 _lowCutFilter.processBlock(&inSample, 1);
188 _highCutFilter.processBlock(&inSample, 1);
189 }
190
191 return _envGetNextOutputImpl(inSample);
192 }
193
199}
double _getNextOutputImpl(double inSample) override
virtual ~AREnvelopeFollowerBase() override=default
virtual double _envGetNextOutputImpl(double inSample)=0
TPTSVF::TPTSVFilter< double > _lowCutFilter
TPTSVF::TPTSVFilter< double > _highCutFilter
void setCutoff(double val)
void processBlock(T *inSamples, size_t numSamples)
void setSampleRate(double val)
const ParameterDefinition::RangedParameter< double > RELEASE_MS(0.1, 10000, 200)
const ParameterDefinition::RangedParameter< double > HIGH_CUT(TPTSVF::Parameters::CUTOFF.minValue, TPTSVF::Parameters::CUTOFF.maxValue, 20000)
const ParameterDefinition::RangedParameter< double > LOW_CUT(TPTSVF::Parameters::CUTOFF.minValue, TPTSVF::Parameters::CUTOFF.maxValue, 0)
const ParameterDefinition::RangedParameter< double > ATTACK_MS(0.1, 10000, 20)