-
Notifications
You must be signed in to change notification settings - Fork 1
/
fabricParamSmooth.hpp
58 lines (50 loc) · 1.14 KB
/
fabricParamSmooth.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* One-pole LPF for smooth parameter changes
*
* https://www.musicdsp.org/en/latest/Filters/257-1-pole-lpf-for-smooth-parameter-changes.html
*/
#pragma once
#include <cmath>
class fabricParamSmooth {
public:
fabricParamSmooth() noexcept = default;
void clear() noexcept
{
z = 0.0f;
}
void setSampleRate(float samplingRate) noexcept
{
if (samplingRate != fs) {
fs = samplingRate;
updateCoefficient();
}
}
void setSmoothingT60(float smoothingT60) noexcept
{
if (t60 != smoothingT60) {
t60 = smoothingT60;
updateCoefficient();
}
}
float process(float in) noexcept
{
float b = 1.0f - a;
return z = (in * b) + (z * a);
}
private:
void updateCoefficient() noexcept
{
if (t60 <= 0.0f || fs <= 0.0f) {
a = 0.0f;
return;
}
float twoPi = 6.283185307179586476925286766559f;
float t = t60 * (1.0f / 6.907755278982137f);
a = std::exp(-twoPi / (t * fs));
}
private:
float a {};
float t60 {};
float z {};
float fs {};
};