-
Notifications
You must be signed in to change notification settings - Fork 10
/
krajeski_flt.h
89 lines (66 loc) · 2.1 KB
/
krajeski_flt.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#ifndef KRAJESKI_LADDER_H
#define KRAJESKI_LADDER_H
/*
This class implements Tim Stilson's MoogVCF filter
using 'compromise' poles at z = -0.3
Several improments are built in, such as corrections
for cutoff and resonance parameters, removal of the
necessity of the separation table, audio rate update
of cutoff and resonance and a smoothly saturating
tanh() function, clamping output and creating inherent
nonlinearities.
This code is Unlicensed (i.e. public domain); in an email exchange on
4.21.2018 Aaron Krajeski stated: "That work is under no copyright.
You may use it however you might like."
Source: http://song-swap.com/MUMT618/aaron/Presentation/demo.html
*/
class KrajeskiMoog
{
public:
KrajeskiMoog() {}
KrajeskiMoog(float sampleRate)
{
for (int i = 0; i < 5; i++) {
state[i] = delay[i] = 0;
}
gComp = 1.0;
SetDrive(0.0f);
SetCutoff(1000.0f);
SetResonance(0.1f);
}
virtual ~KrajeskiMoog() { }
inline float Process(float sample) ;
inline void Init(float samplerate) {
gComp = 1.0;
sampleRate = samplerate;
SetDrive(0.0f);
SetCutoff(1000.0f);
SetResonance(0.1f);
}
inline void SetResonance(float r)
{
resonance = r*1.3f;
gRes = (float)( resonance * (1.0029f + 0.0526f * wc - 0.926f * wc*wc + 0.0218f * wc*wc*wc));
}
virtual void SetCutoff(float c)
{
cutoff = c;
wc = (float)(TWOPI * cutoff * DIV_SAMPLE_RATE);
g = (float)(0.9892f * wc - 0.4342f * wc*wc + 0.1381f * wc*wc*wc - 0.0202f * wc*wc*wc*wc);
}
inline void SetDrive(float dr) {
drive = dr * 2.0f + 1.0f;
}
private:
// volatile is a workaround because of random NANs during Process()???
float state[5];
float delay[5];
float wc; // The angular frequency of the cutoff.
float g; // A derived parameter for the cutoff frequency
float gRes; // A similar derived parameter for resonance.
float gComp; // Compensation factor.
float drive; // A parameter that controls intensity of nonlinearities.
float sampleRate, cutoff, resonance;
};
#endif