1 #include "PeakFallSmooth.hpp"
2 
3 START_NAMESPACE_DISTRHO
4 
PeakFallSmooth()5 PeakFallSmooth::PeakFallSmooth() : fHistory(0.0f),
6                                    fValue(0.0f)
7 {
8 }
9 
PeakFallSmooth(const float value)10 PeakFallSmooth::PeakFallSmooth(const float value) : fHistory(0.0f),
11                                                     fValue(value),
12                                                     fCoeff(0.0f)
13 {
14 }
15 
calculateCoeff(const float frequency,const double sampleRate)16 void PeakFallSmooth::calculateCoeff(const float frequency, const double sampleRate)
17 {
18     fCoeff = std::exp(-2.0 * M_PI * frequency / sampleRate);
19 }
20 
setValue(const float value)21 void PeakFallSmooth::setValue(const float value)
22 {
23     if (fHistory < value)
24         fHistory = value;
25 
26     fValue = value;
27 }
28 
getRawValue() const29 float PeakFallSmooth::getRawValue() const
30 {
31     return fValue;
32 }
33 
getSmoothedValue()34 float PeakFallSmooth::getSmoothedValue()
35 {
36     float result = fValue + fCoeff * (fHistory - fValue);
37     fHistory = result;
38 
39     return result;
40 }
41 
42 END_NAMESPACE_DISTRHO