1declare id     "low_highpass";
2declare name   "low high pass";
3declare shortname "L/H/Filter";
4declare category "Tone Control";
5declare groups ".low_high_pass.lhp[low_highpass], .low_high_pass.lhc[low_highcutoff]";
6
7declare version 	"0.01";
8declare author 		"brummer";
9declare license 	"BSD";
10declare copyright 	"(c)brummer 2008";
11
12import("stdfaust.lib");
13import("guitarix.lib");
14
15//-speaker emulation
16sbp1    		= vslider("lowfreq[name:low freq][tooltip:low-freq cutoff Hz]",130,20,1000,10);
17sbp2    		= vslider("highfreq[name:high freq][tooltip:high-freq cutoff Hz]",5000,1000,12000,10);
18switch1 		= checkbox("onoff[name:low highcutoff]");
19sbp 			= hgroup(".low_high_pass.lhc", bypass(switch1, +(anti_denormal_ac) : ef.speakerbp(sbp1,sbp2)));
20
21//------------------------------ low/high-passfilters --------------------------------------
22
23tf1N(b0,b1,a1) = _ <: *(b0), (mem : *(b1)) :> + ~ *(0-a1);
24
25tf2N(b0,b1,b2,a1,a2) = sub ~ conv2(a1,a2) : conv3(b0,b1,b2)
26with {
27  conv3(k0,k1,k2,x)     = k0*x + k1*x' + k2*x'';
28  conv2(k0,k1,x)        = k0*x + k1*x';
29  sub(x,y)              = y-x;
30};
31
32tf1sN(b1,b0,a0,w1) = tf1N(b0d,b1d,a1d)
33with {
34  c   = 1/tan((w1)*0.5/ma.SR); // bilinear-transform scale-factor
35  d   = a0 + c;
36  b1d = (b0 - b1*c) / d;
37  b0d = (b0 + b1*c) / d;
38  a1d = (a0 - c) / d;
39};
40
41tf2sN(b2,b1,b0,a1,a0,w1) = tf2N(b0d,b1d,b2d,a1d,a2d)
42with {
43  c   = 1/tan((w1)*0.5/ma.SR); // bilinear-transform scale-factor
44  csq = c*c;
45  d   = a0 + a1 * c + csq;
46  b0d = (b0 + b1 * c + b2 * csq)/d;
47  b1d = 2 * (b0 - b2 * csq)/d;
48  b2d = (b0 - b1 * c + b2 * csq)/d;
49  a1d = 2 * (a0 - csq)/d;
50  a2d = (a0 - a1*c + csq)/d;
51};
52
53lowpassN(N,fc) = lowpass0_highpass1N(0,N,fc);
54highpassN(N,fc) = lowpass0_highpass1N(1,N,fc);
55lowpass0_highpass1N(s,N,fc) = lphpr(s,N,N,fc)
56with {
57  lphpr(s,0,N,fc) = _;
58  lphpr(s,1,N,fc) = tf1sN(s,1-s,1,2*ma.PI*fc);
59  lphpr(s,O,N,fc) = lphpr(s,(O-2),N,fc) : tf2sN(s,0,1-s,a1s,1,w1) with {
60    parity = N % 2;
61    S = (O-parity)/2; // current section number
62    a1s = -2*cos(-ma.PI + (1-parity)*ma.PI/(2*N) + (S-1+parity)*ma.PI/N);
63    w1 = 2*ma.PI*fc;
64  };
65};
66
67//-low and fi.highpass
68
69lowpassfreq  	= nentry("low_freq[name:low freq]", 5000, 20, 12000, 10);
70highpassfreq 	= nentry("high_freq[name:high freq]", 130, 20, 7040, 10);
71switch       	= checkbox("on_off[name:low fi.highpass]");
72passo 		 	= +(anti_denormal_ac) : lowpassN(1,lowpassfreq) : highpassN(1,highpassfreq);
73pass 		 	= hgroup(".low_high_pass.lhp", bypass(switch, passo));
74
75process 		=  pass  : sbp ;
76