~pbatch/patchwerk

patchwerk/janet/siren.janet -rw-r--r-- 3.2 KiB
9c265356 — paul plan9 additions from Sigrid 4 months ago
                                                                                
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
(import build/patchwerk :as pw)

(do
  # initialize + allocate
  (var sr 44100)
  (var patch (pw/mkpatch 8 10 64 sr))
  (var sp (pw/sp-create sr))
  (var stack (pw/patch-stack patch))

  # 0.1 1 sine
  (var sine (pw/node-sine patch sp))
  (pw/cable-set-constant
   (pw/node-get-cable sine 0)
   0.1)
  (pw/cable-set-constant
   (pw/node-get-cable sine 1)
   1)

  # 0 1 biscale
  (pw/stack-pop stack)
  (var biscale (pw/node-biscale patch sp))
  (pw/cable-connect
   (pw/node-get-cable sine 2)
   (pw/node-get-cable biscale 0))
  (pw/cable-set-constant (pw/node-get-cable biscale 1) 0)
  (pw/cable-set-constant (pw/node-get-cable biscale 2) 1)

  # bhold 0 cabset
  (var buf (pw/patch-bhold patch))
  (pw/stack-pop stack)
  (var lfo (pw/node-get-cable biscale 3))

  # 0 cabget 100 600 scale

  (pw/stack-push-buffer stack buf)

  (pw/stack-pop stack)
  (var scale (pw/node-scale patch sp))
  (pw/cable-connect lfo (pw/node-get-cable scale 0))
  (pw/cable-set-constant (pw/node-get-cable scale 1) 100)
  (pw/cable-set-constant (pw/node-get-cable scale 2) 600)


  # 0.5 blsaw

  (pw/stack-pop stack)
  (var blsaw (pw/node-blsaw patch sp))
  (pw/cable-connect
   (pw/node-get-cable scale 3)
   (pw/node-get-cable blsaw 0))
  (pw/cable-set-constant (pw/node-get-cable blsaw 1) 0.5)

  # 0 cabget 100 2000 scale

  (pw/stack-push-buffer stack buf)
  (pw/stack-pop stack)

  (set scale (pw/node-scale patch sp))
  (pw/cable-connect lfo (pw/node-get-cable scale 0))
  (pw/cable-set-constant (pw/node-get-cable scale 1) 100)
  (pw/cable-set-constant (pw/node-get-cable scale 2) 2000)

  # butlp

  (pw/stack-pop stack)
  (pw/stack-pop stack)
  (var butlp (pw/node-butlp patch sp))

  (pw/cable-connect
   (pw/node-get-cable blsaw 2)
   (pw/node-get-cable butlp 0))
  (pw/cable-connect
   (pw/node-get-cable scale 2)
   (pw/node-get-cable butlp 1))

  # bdup

  (pw/stack-dup stack)
  # bdup 0.97 10000 revsc
  (pw/stack-dup stack)
  (pw/stack-pop stack)
  (pw/stack-pop stack)

  (var revsc (pw/node-revsc patch sp))
  (pw/cable-connect
   (pw/node-get-cable butlp 2)
   (pw/node-get-cable revsc 0))
  (pw/cable-connect
   (pw/node-get-cable butlp 2)
   (pw/node-get-cable revsc 1))

  (pw/cable-set-constant (pw/node-get-cable revsc 2) 0.97)
  (pw/cable-set-constant (pw/node-get-cable revsc 3) 10000)

  # bdrop

  (pw/stack-pop stack)

  # 0.1 mul

  (var mul (pw/node-mul patch sp))
  (pw/cable-set-constant (pw/node-get-cable mul 0) 0.1)
  (pw/cable-connect
   (pw/node-get-cable revsc 4)
   (pw/node-get-cable mul 1))

  # dcblock

  (pw/stack-pop stack)
  (var dcblock (pw/node-dcblock patch sp))
  (pw/cable-connect
   (pw/node-get-cable mul 2)
   (pw/node-get-cable dcblock 0))

  # add

  (pw/stack-pop stack)
  (var add (pw/node-add patch sp))
  (pw/cable-connect
   (pw/node-get-cable butlp 2)
   (pw/node-get-cable add 0))
  (pw/cable-connect
   (pw/node-get-cable dcblock 1)
   (pw/node-get-cable add 1))

  # 0 cabget bunhold

  (pw/patch-bunhold patch buf)

  # siren.wav wavout bdrop

  (var wavout (pw/node-wavout patch sp "siren.wav"))

  (pw/cable-connect
   (pw/node-get-cable add 2)
   (pw/node-get-cable wavout 0))

  (pw/stack-pop stack)

  # sr 10 * _compute rep

  (for i 0 (* sr 10) (pw/patch-tick patch))

  # cleanup

  (pw/delpatch patch)
  (pw/sp-destroy sp))