-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoise_Filter.dsp
114 lines (94 loc) · 4.27 KB
/
Noise_Filter.dsp
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
declare author "Elodie RABIBISOA";
declare name "Noise Filter";
import("stdfaust.lib");
process = vgroup("Noise Filter", noiseFilter);
noiseFilter = (noise : lowPass) *(volume) : noise_reverb : onOff <:_,_;
onOff = *(checkbox("[1]On / Off"): si.smooth(0.998));
//--- Noise Generator ---
random = +(12345)~*(1103515245);
noise = random/2147483647.0;
//--- Lowpass Filter - Axe X ---
lowPass = fi.lowpass(2,fc)
with{
fc = hslider("Lowpass Filter[hidden:1][acc:0 0 -9 0 8]", 18000, 10, 18000, 0.01):si.smooth(0.999):min(18000):max(10);
};
//--- Volume - Axe Z ---
volume = hslider("Volume[hidden:1][acc:2 1 -8 0 8]", 0, 0, 1, 0.01):si.smooth(0.998);
//--- Reverb ---
noise_reverb =_<:zita_rev3:>_;
zita_rev3(x,y) = zita_rev1_stereo4(rdel,f1,f2,t60dc,t60m,fsmax,x,y) : out_eq
with {
//Reverb parameters:
t60dc = 6; //Low Frequencies Decay Time (in seconds)
t60m = 6; // Mid Frequencies Decay Time (in seconds)
fsmax = 48000.0; // highest sampling rate that will be used
rdel =50;
f1 =500;
f2 = 8000;
out_eq = pareq_stereo(eq1f,eq1l,eq1q) : pareq_stereo(eq2f,eq2l,eq2q)
with {
pareq_stereo (eqf,eql,Q) = fi.peak_eq_cq (eql,eqf,Q) , fi.peak_eq_cq (eql,eqf,Q) ;
eq1f =315;
eq1l =0;
eq1q =3;
eq2f =3000;
eq2l =0;
eq2q =3;
};
};
//---------------------------------------- Zita_Rev1_Stereo4 -------------------------------------
// from effect.lib but with only N=4 for mobilephone application
zita_rev_fdn4(f1,f2,t60dc,t60m,fsmax) =
((si.bus(2*N) :> allpass_combs(N) : feedbackmatrix(N)) ~
(delayfilters(N,freqs,durs) : fbdelaylines(N)))
with {
N = 4;
// Delay-line lengths in seconds:
apdelays = (0.020346, 0.024421, 0.031604, 0.027333, 0.022904, 0.029291, 0.013458, 0.019123); // feedforward delays in seconds
tdelays = ( 0.153129, 0.210389, 0.127837, 0.256891, 0.174713, 0.192303, 0.125000, 0.219991); // total delays in seconds
tdelay(i) = floor(0.5 + ma.SR*ba.take(i+1,tdelays)); // samples
apdelay(i) = floor(0.5 + ma.SR*ba.take(i+1,apdelays));
fbdelay(i) = tdelay(i) - apdelay(i);
// NOTE: Since ma.SR is not bounded at compile time, we can't use it to
// allocate de.delay lines; hence, the fsmax parameter:
tdelaymaxfs(i) = floor(0.5 + fsmax*ba.take(i+1,tdelays));
apdelaymaxfs(i) = floor(0.5 + fsmax*ba.take(i+1,apdelays));
fbdelaymaxfs(i) = tdelaymaxfs(i) - apdelaymaxfs(i);
nextpow2(x) = ceil(log(x)/log(2.0));
maxapdelay(i) = int(2.0^max(1.0,nextpow2(apdelaymaxfs(i))));
maxfbdelay(i) = int(2.0^max(1.0,nextpow2(fbdelaymaxfs(i))));
apcoeff(i) = select2(i&1,0.6,-0.6); // allpass comb-filter coefficient
allpass_combs(N) =
par(i,N,(fi.allpass_comb(maxapdelay(i),apdelay(i),apcoeff(i)))); // filter.lib
fbdelaylines(N) = par(i,N,(de.delay(maxfbdelay(i),(fbdelay(i)))));
freqs = (f1,f2); durs = (t60dc,t60m);
delayfilters(N,freqs,durs) = par(i,N,filter(i,freqs,durs));
feedbackmatrix(N) = ro.hadamard(N); // math.lib
staynormal = 10.0^(-20); // let signals decay well below LSB, but not to zero
special_lowpass(g,f) = si.smooth(p) with {
// unity-dc-gain fi.lowpass needs gain g at frequency f => quadratic formula:
p = mbo2 - sqrt(max(0,mbo2*mbo2 - 1.0)); // other solution is unstable
mbo2 = (1.0 - gs*c)/(1.0 - gs); // NOTE: must ensure |g|<1 (t60m finite)
gs = g*g;
c = cos(2.0*ma.PI*f/float(ma.SR));
};
filter(i,freqs,durs) = lowshelf_lowpass(i)/sqrt(float(N))+staynormal
with {
lowshelf_lowpass(i) = gM*low_shelf1_l(g0/gM,f(1)):special_lowpass(gM,f(2));
low_shelf1_l(G0,fx,x) = x + (G0-1)*fi.lowpass(1,fx,x); // filter.lib
g0 = g(0,i);
gM = g(1,i);
f(k) = ba.take(k,freqs);
dur(j) = ba.take(j+1,durs);
n60(j) = dur(j)*ma.SR; // decay time in samples
g(j,i) = exp(-3.0*log(10.0)*tdelay(i)/n60(j));
};
};
zita_rev1_stereo4(rdel,f1,f2,t60dc,t60m,fsmax) = re.zita_in_delay(rdel) : re.zita_distrib2(N) : zita_rev_fdn4(f1,f2,t60dc,t60m,fsmax) : output2(N)
with {
N = 4;
output2(N) = outmix(N) : *(t1),*(t1);
t1 = 0.37; // zita-rev1 linearly ramps from 0 to t1 over one buffer
outmix(4) = !,ro.butterfly(2),!; // probably the result of some experimenting!
outmix(N) = outmix(N/2),par(i,N/2,!);
};