forked from s-e-a-m/faust-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seam.filters.lib
157 lines (154 loc) · 5.26 KB
/
seam.filters.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// ---
// description: SEAM Math Library
// ---
//
// <!-- LICENSE: GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 -->
//
// # gerzon.lib
//
// ```text
declare name "SEAM Filters - Library";
declare version "0.1";
declare author "Giuseppe Silvi";
declare license "CC3";
sfi = library("seam.filters.lib");
//================================================================== FILTERS ===
//==============================================================================
//------------------------------------------ COMPUTER MUSIC TUTORIAL ALLPASS ---
cmtap(D,g) = (+ <: de.delay((ma.SR/2),int(D-1)),*(-g)) ~ *(g) : +;
cmtapm(D,g) = (+ <: de.delay((ma.SR/2),int(D-1)),*(-g)) ~ *(g) : mem,_ : +;
//
//----------------------------------------------------- EXPONENTIAL AVERAGER ---
// https://www.dsprelated.com/showarticle/182.php
// > eavga is a two-multiply exponential averager
// > eavgb is a one-multiply exponential averager
// > the two averagers have identical performance
// used to test acor formula in seam.math.lib
//
// process = os.impulse <: eavg(acor(1000)), eavg1(acor(1000));
eavg(a) = *(a) : +~*(1-a);
eavg1(a) = +(+*(a))~z
with{
z = _<:_,*(-1);
};
//---------------------- EXPONENTIAL AVERAGER -3dB CUTOFF FREQUENCY UP TO SR ---
// https://www.dsprelated.com/showarticle/182.php
aapp(fc) = 1-pow(eu, -omega(fc));
acor(fc) = cos(omega(fc))-1+sqrt(cosq(omega(fc))-4*cos(omega(fc))+3);
// process = eavg(acor);
//
//------------------------------------------ ALL-PASS FILTER COEF CALCULATOR ---
//
// REFERENCES:
// https://www.dsprelated.com/showcode/182.php
//
// The following Matlab function generates allpass coefficients for an IIR
// filter. In this design, the magnitude response is unchanged but the phase
// response is very different. This code only supports 1st order or 2nd order
// variants.
//
// 1st order allpass filters shift the phase by 180 degrees, while the 2nd order
// shifts the phase by 360 degrees. The "center frequency" of Fc defines where
// the phase response should be halfway to the max shift.
//
// For example,
// If order=2 and Fc = 2000Hz, there would be a 180deg shift at 2kHz
// If order=1 and Fc = 5000Hz, there would be a 90deg shift at 5kHz
//
// Returns allpass filter coefficients.
// Currently only 1st and 2nd orders are supported.
// N is the order of the allpass
// FC is the frequency a the 90deg phase shift point
// FS is the sampling rate
// Q is quality factor describing the slope of phase shift
//
// Bilinear transform
// g(fc) = tan(ma.PI*(fc/ma.SR));
//
// process = (ap1coeff(freq,qq) : ap1inspec),
// (ap2coeff(freq,qq) : ap2inspec) :> _ *(0.00001);
//
ap2coeff(fc,q) = g(fc), b0(fc,q), b1(fc,q), b2, a1(fc,q), a2(fc,q)
with{
g(fc) = tan(ma.PI*(fc/ma.SR));
d(q) = 1/q;
k(fc,q) = 1/(1 + (d(q)*g(fc)) + (g(fc)*g(fc)));
b0(fc,q) = (1 - (g(fc)*d(q)) + (g(fc)*g(fc))) * k(fc,q);
b1(fc,q) = 2 * ((g(fc)*g(fc)) - 1) * k(fc,q);
b2 = 1;
a1 = b1;
a2 = b0;
};
//
ap1coeff(fc,q) = g(fc), b0(fc,q), b1, b2, a1(fc,q), a2
with{
g(fc) = tan(ma.PI*(fc/ma.SR));
b0(fc,q) = (g(fc)-1)/(g(fc)+1);
b1 = 1;
b2 = 0;
a1 = b0;
a2 = 0;
};
//
//freq = hslider("[01]Center Frequency", 2000,1,24000,1);
//qq = hslider("[02]Q slope", 1,0.01,2,0.001);
//
//graph_g(x) = hgroup("[03]COEFFICIENTS",x);
//ap1inspec = graph_g(vgroup("[01]1st ORDER ALLPASS",
// hbargraph("[00]g[style:numerical]", 0,10),
// hbargraph("[01]b0[style:numerical]", -2,2),
// hbargraph("[02]b1[style:numerical]", -2,2),
// hbargraph("[03]b2[style:numerical]", -2,2),
// hbargraph("[04]a1[style:numerical]", -2,2),
// hbargraph("[05]a2[style:numerical]", -2,2)));
//
// ap2inspec = graph_g(vgroup("[02]2nd ORDER ALLPASS",
// hbargraph("[00]g[style:numerical]", 0,10),
// hbargraph("[01]b0[style:numerical]", -2,2),
// hbargraph("[02]b1[style:numerical]", -2,2),
// hbargraph("[03]b2[style:numerical]", -2,2),
// hbargraph("[04]a1[style:numerical]", -2,2),
// hbargraph("[05]a2[style:numerical]", -2,2)));
//
//------------------------------ SIMPLE RC-FILTER USED INTO SEAM.REVERBS.LIB ---
rcfilter = wd.buildtree(tree_lowpass)
with{
vs1(i) = wd.u_voltage(i,_);
r1(i) = wd.resistor(i, 47*10^3);
c1(i) = wd.capacitor_Vout(i, 10*10^-9);
tree_lowpass = vs1 : wd.series : (r1, c1);
};
//process = no.noise : rcfilter;
aa = library("aanl.lib");
sf = library("all.lib");
an = library("analyzers.lib");
ba = library("basics.lib");
co = library("compressors.lib");
de = library("delays.lib");
dm = library("demos.lib");
dx = library("dx7.lib");
en = library("envelopes.lib");
fd = library("fds.lib");
fi = library("filters.lib");
ho = library("hoa.lib");
it = library("interpolators.lib");
ma = library("maths.lib");
mi = library("mi.lib");
ef = library("misceffects.lib");
os = library("oscillators.lib");
no = library("noises.lib");
pf = library("phaflangers.lib");
pl = library("platform.lib");
pm = library("physmodels.lib");
qu = library("quantizers.lib");
rm = library("reducemaps.lib");
re = library("reverbs.lib");
ro = library("routes.lib");
sp = library("spats.lib");
si = library("signals.lib");
so = library("soundfiles.lib");
sy = library("synths.lib");
ve = library("vaeffects.lib");
vl = library("version.lib");
wa = library("webaudio.lib");
wd = library("wdmodels.lib");