-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.dsp
79 lines (67 loc) · 1.85 KB
/
lib.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
/*
Quelques fonctions utiles que j'ai fabriquées
*/
import("stdfaust.lib");
/*
Impulsion with a specified duration. Can be retriggered.
*/
mpulse(smps_dur, trig) = pulsation
with {
count = ba.countdown(smps_dur, trig);
//count = -(1)~_, smps_dur : select2(trig);
pulsation = 0, 1 : select2(count > 0);
};
mpulse_dur(duration, trig) = mpulse(ba.sec2samp(duration), trig);
/*
Euclidian function. Generates an euclidian rythm with 0;1 triggers
*/
euclidian(onset, div, pulses, rotation, phasor) = (eucval' != eucval) & (kph' != kph)
with {
kph = int( (( (phasor + rotation) * div) % 1) * pulses);
eucval = int((onset / pulses) * kph);
};
dur_smps_euclidian(onset, div, pulses, rotation, smps_dur, phasor) = euclidian(onset, div, pulses, rotation, phasor) : mpulse(smps_dur);
/*
Wavefolder.
*/
wavefolder(lim, sig) = 4 * (abs(lim * sig + lim - rnd(lim * sig + lim))-lim)
with {
rnd(sig) = floor(sig), ceil(sig) : select2( (sig -floor(sig)) > 0.5 );
};
/*
Limit to range
*/
range(vmin, vmax, sig) = res
with {
low = vmin, sig : select2(sig >= vmin) ;
res = vmax, low : select2(low <= vmax);
};
/*
Returns 0 if below th.
*/
threshold(th, sig) = sig, 0 : select2(sig <= th);
/*
Capture movement on a signal - outputs signal between 0 and 1
*/
capture_mov(th, release_time, sig) = res
letrec {
'diff = abs(sig' - sig);
'threshed = diff : threshold(th);
'inc = threshed;
'is_moving = threshed > 0;
'dec = (res / (release_time * ma.SR)) : *(-1) : ba.sAndH(is_moving);
'mv = dec, inc : select2(is_moving);
'res = (_:range(0,1))~+(mv);
};
/*
Linear interpolation of a signal
*/
line(time, sig) = res
letrec {
'changed = (sig' != sig) | (time' != time);
'steps = ma.SR * time;
'cntup = ba.countup(steps ,changed);
'diff = ( sig - res);
'inc = diff / steps : ba.sAndH(changed);
'res = res, res + inc : select2(cntup < steps);
};