forked from striso/striso-control-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fast.lib
64 lines (54 loc) · 1.75 KB
/
fast.lib
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
//fast.lib - Faust functions for fast approximations of various functions
declare name "Faust Fast Approximations Library";
declare author "Piers Titus van der Torren ([email protected])";
declare licence "Apache-2.0";
import("stdfaust.lib");
// 2^x approximation
fastpow2 = ffunction(float fastpow2 (float), "fastpow.h", "");
// integer divide
idiv = ffunction(int idiv (int, int),"fastpow.h","");
// fast midi note to frequency function
note2freq(note) = 8.175798916 * fastpow2(note/12.0);
// tailor approximation of tan for [0,pi/4]
tan0(a) = (((2.033e-01 * a^2) + 3.1755e-01) * a^2 + 1.0) * a;
// biquad filters section
biquad(a0,a1,a2,b1,b2,x) = x : + ~ ((-1)*conv2(b1, b2)) : conv3(a0, a1, a2)
with {
conv2(c0,c1,x) = c0*x+c1*x';
conv3(c0,c1,c2,x) = c0*x+c1*x'+c2*x'';
};
// fast approximation for K in the following biquad filters
K_f0(f0) = tan0(ma.PI * f0 / ma.SR);
// Low Pass Filter
LPF(K, Q) = biquad(a0,a1,a2,b1,b2)
with {
//K = tan(ma.PI * f0 / ma.SR);
norm = 1 / (1 + K / Q + K * K);
a0 = K * K * norm;
a1 = 2 * a0;
a2 = a0;
b1 = 2 * (K * K - 1) * norm;
b2 = (1 - K / Q + K * K) * norm;
};
// High Pass Filter
HPF(K, Q) = biquad(a0,a1,a2,b1,b2)
with {
//K = tan(ma.PI * f0 / ma.SR);
norm = 1 / (1 + K / Q + K * K);
a0 = 1 * norm;
a1 = -2 * a0;
a2 = a0;
b1 = 2 * (K * K - 1) * norm;
b2 = (1 - K / Q + K * K) * norm;
};
// Band Pass Filter
BPF(K, Q) = biquad(a0,a1,a2,b1,b2)
with {
//K = tan(ma.PI * f0 / ma.SR);
norm = 1 / (1 + K / Q + K * K);
a0 = K / Q * norm;
a1 = 0;
a2 = -a0;
b1 = 2 * (K * K - 1) * norm;
b2 = (1 - K / Q + K * K) * norm;
};