-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdlib.sth
59 lines (45 loc) · 2.33 KB
/
stdlib.sth
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
decay_exp f t = (exp (-5 * t)),
sine f t = (sin (2 * pi * f * t)),
sine_decay f t = (sine f t) * (decay_exp f t),
sign x = if x > 0 then 1 else (if x < 0 then -1 else 0 end) end,
# if X then A else B end
# case X of 1 -> A, 0 -> B end
# sign x = case x > 0 of 1 -> 1, 0 -> (case x < 0 of 1 -> -1, 0 -> 0 end) end,
square f t = (sign (sine f t)),
square_decay f t = (square f t) * (decay_exp f t),
# triangle f t = let p = 1 / f in
triangle f t = 2 * f * ((abs ((t % (1 / f)) - (1 / (2 * f)))) - (1 / (4 * f))),
triangle_decay f t = (triangle f t) * (decay_exp f t),
saw f t = 2 * (f * t - (floor (1 / 2 + f * t))),
saw_decay f t = (saw f t) * (decay_exp f t),
bell f t = let w = 2 * pi * f, c = w * t, mt = (inv t) in
.100 * (exp mt / 1.000) * (sin (0.56 * c))
+ .067 * (exp mt / 0.900) * (sin (0.56 * c))
+ .100 * (exp mt / 0.650) * (sin (0.92 * c))
+ .180 * (exp mt / 0.550) * (sin (0.92 * c))
+ .267 * (exp mt / 0.325) * (sin (1.19 * c))
+ .167 * (exp mt / 0.350) * (sin (1.70 * c))
+ .146 * (exp mt / 0.250) * (sin (2.00 * c))
+ .133 * (exp mt / 0.200) * (sin (2.74 * c))
+ .133 * (exp mt / 0.150) * (sin (3.00 * c))
+ .100 * (exp mt / 0.100) * (sin (3.76 * c))
+ .133 * (exp mt / 0.075) * (sin (4.07 * c)),
kick f t = (sin f * ((sqrt t) * 0.6 + 0.4)) * (exp -3.5 * t),
bd f t = let decay_strength = -7,
attack = 0.3,
function = triangle,
decay t = (exp decay_strength * t),
base f t = (function (f / (2 * pi)) ((sqrt t) * attack + (1 - attack)))
# harmonic n f t =
# case n of
# 0 -> 0,
# _ -> (harmonic (n - 1) f t) + (((base (n * f)) t) / n)
# end
in ((base f t) + (base (2 * f) t) + (base (3 * f) t)) * (decay t),
pianish_aux1 f t = 0.6 * (sin (1.0 * 2 * pi * f * t)) * (exp (-0.0008 * 2 * pi * f * t))
+ 0.3 * (sin (2.0 * 2 * pi * f * t)) * (exp (-0.0010 * 2 * pi * f * t))
+ 0.1 * (sin (4.0 * 2 * pi * f * t)) * (exp (-0.0015 * 2 * pi * f * t)),
pianish_aux2 f t = (pianish_aux1 f t) + 0.2 * ((pianish_aux1 f t) ^ 3),
pianish_aux3 f t = (pianish_aux2 f t) * (0.9 + 0.1 * (cos (70 * t))),
pianish f t = 2 * (pianish_aux3 f t) * (exp (-22 * t)) + (pianish_aux3 f t),
tremolo f t = cos (2 * pi * (f * t + 40 * (sin (2 * pi * t)) / (2 * pi)))