-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADSRmodule.binstr
291 lines (285 loc) · 9.93 KB
/
ADSRmodule.binstr
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<instrument type='blue.orchestra.BlueSynthBuilder' editEnabled='true'>
<name>ADSRmodule</name>
<comment>
DESCRIPTION:
The Tremolo Module works in realtime. Produces a control signal.
- multiply an Attack Decay Sustain Release envelope to the soundsignal.</comment>
<globalOrc/>
<globalSco/>
<instrumentText>; no inputs, 1 control signal output
;============================ADSR amplitude Module==============================
if (<ADSR ON> == 1) then
aret init 1
agte = linseg:a(1, p3 - i(<ADSR release>), 1, 0, 0, i(<ADSR release>), 0)
aampdsr adsr140 agte, aret, <ADSR attack>, <ADSR decay>, <ADSR sustain>, <ADSR release>
else
aampdsr = 1
endif
;;==============================================================================
;multiply ADSR with output signal of the instrument:
;blueMixerOut asig1 * aampdsr , asig2 * aampdsr</instrumentText>
<alwaysOnInstrumentText></alwaysOnInstrumentText>
<graphicInterface editEnabled='false'>
<gridSettings>
<width>10</width>
<height>10</height>
<gridStyle>DOT</gridStyle>
<snapGridEnabled>true</snapGridEnabled>
</gridSettings>
<bsbObject type='blue.orchestra.blueSynthBuilder.BSBGroup'>
<objectName></objectName>
<x>0</x>
<y>0</y>
<groupName>Group</groupName>
<backgroundColor>0x00000033</backgroundColor>
<borderColor>0x000000ff</borderColor>
<labelTextColor>0xffffffff</labelTextColor>
<titleEnabled>true</titleEnabled>
<width>20</width>
<height>20</height>
<font>
<name>Roboto</name>
<size>12.0</size>
<style>0</style>
</font>
<bsbObject type='blue.orchestra.blueSynthBuilder.BSBGroup'>
<objectName></objectName>
<x>0</x>
<y>0</y>
<comment>4 envelopes for amplitude</comment>
<groupName>ADSR</groupName>
<backgroundColor>0x282828ff</backgroundColor>
<borderColor>0x000000ff</borderColor>
<labelTextColor>0xffffffff</labelTextColor>
<titleEnabled>true</titleEnabled>
<width>20</width>
<height>117</height>
<font>
<name>Roboto</name>
<size>12.0</size>
<style>2</style>
</font>
<bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
<objectName>ADSR release</objectName>
<x>225</x>
<y>10</y>
<automationAllowed>true</automationAllowed>
<minimum>0.0</minimum>
<maximum>1.0</maximum>
<value>0.25149683596018546</value>
<knobWidth>50</knobWidth>
<randomizable>true</randomizable>
<valueDisplayEnabled>true</valueDisplayEnabled>
<label>release</label>
<labelEnabled>true</labelEnabled>
<font>
<name>Roboto</name>
<size>12.0</size>
<style>0</style>
</font>
</bsbObject>
<bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
<objectName>ADSR decay</objectName>
<x>90</x>
<y>10</y>
<automationAllowed>true</automationAllowed>
<minimum>0.0</minimum>
<maximum>2.0</maximum>
<value>0.47579679080059833</value>
<knobWidth>50</knobWidth>
<randomizable>true</randomizable>
<valueDisplayEnabled>true</valueDisplayEnabled>
<label>decay</label>
<labelEnabled>true</labelEnabled>
<font>
<name>Roboto</name>
<size>12.0</size>
<style>0</style>
</font>
</bsbObject>
<bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
<objectName>ADSR sustain</objectName>
<x>155</x>
<y>10</y>
<automationAllowed>true</automationAllowed>
<minimum>0.0</minimum>
<maximum>1.0</maximum>
<value>0.9993813053987427</value>
<knobWidth>50</knobWidth>
<randomizable>true</randomizable>
<valueDisplayEnabled>true</valueDisplayEnabled>
<label>sustain</label>
<labelEnabled>true</labelEnabled>
<font>
<name>Roboto</name>
<size>12.0</size>
<style>0</style>
</font>
</bsbObject>
<bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
<objectName>ADSR ON</objectName>
<x>5</x>
<y>10</y>
<comment>ON/OFF</comment>
<automationAllowed>true</automationAllowed>
<label/>
<selected>true</selected>
<randomizable>true</randomizable>
</bsbObject>
<bsbObject type='blue.orchestra.blueSynthBuilder.BSBKnob' version='2'>
<objectName>ADSR attack</objectName>
<x>25</x>
<y>10</y>
<automationAllowed>true</automationAllowed>
<minimum>0.0</minimum>
<maximum>3.0</maximum>
<value>0.0</value>
<knobWidth>50</knobWidth>
<randomizable>true</randomizable>
<valueDisplayEnabled>true</valueDisplayEnabled>
<label>attack</label>
<labelEnabled>true</labelEnabled>
<font>
<name>Roboto</name>
<size>12.0</size>
<style>0</style>
</font>
</bsbObject>
</bsbObject>
</bsbObject>
</graphicInterface>
<parameterList>
<parameter uniqueId='-1585864625' name='ADSR sustain' label='' min='0.0' max='1.0' bdresolution='-1' automationEnabled='false' value='0.9993813053987427'>
<line name='' version='2' max='1.0' min='0.0' bdresolution='-1' color='-8355712' rightBound='false' endPointsLinked='false'>
<linePoint x='0.0' y='0.9993813053987427'/>
</line>
</parameter>
<parameter uniqueId='-1585864623' name='ADSR release' label='' min='0.0' max='1.0' bdresolution='-1' automationEnabled='false' value='0.25149683596018546'>
<line name='' version='2' max='1.0' min='0.0' bdresolution='-1' color='-8355712' rightBound='false' endPointsLinked='false'>
<linePoint x='0.0' y='0.25149683596018546'/>
</line>
</parameter>
<parameter uniqueId='-1585864621' name='ADSR ON' label='' min='0.0' max='1.0' bdresolution='1' automationEnabled='false' value='1.0'>
<line name='' version='2' max='1.0' min='0.0' bdresolution='1' color='-8355712' rightBound='false' endPointsLinked='false'>
<linePoint x='0.0' y='1.0'/>
</line>
</parameter>
<parameter uniqueId='-1585864619' name='ADSR decay' label='' min='0.0' max='2.0' bdresolution='-1' automationEnabled='false' value='0.47579679080059833'>
<line name='' version='2' max='2.0' min='0.0' bdresolution='-1' color='-8355712' rightBound='false' endPointsLinked='false'>
<linePoint x='0.0' y='0.47579679080059833'/>
</line>
</parameter>
<parameter uniqueId='-1585864617' name='ADSR attack' label='' min='0.0' max='3.0' bdresolution='-1' automationEnabled='false' value='0.0'>
<line name='' version='2' max='3.0' min='0.0' bdresolution='-1' color='-8355712' rightBound='false' endPointsLinked='false'>
<linePoint x='0.0' y='0.0'/>
</line>
</parameter>
</parameterList>
<presetGroup name='Presets'/>
<opcodeList>
<udo>
<opcodeName>adsr140_calc_coef</opcodeName>
<outTypes>k</outTypes>
<inTypes>kk</inTypes>
<codeBody>
knum_samps, kratio xin
xout exp( -log((1.0 + kratio) / kratio) / knum_samps)
</codeBody>
<comments></comments>
</udo>
<udo>
<opcodeName>adsr140</opcodeName>
<outTypes>a</outTypes>
<inTypes>aakkkk</inTypes>
<codeBody>agate, aretrig, kattack, kdecay, ksustain, krelease xin
kstate init 0 ; 0 = attack, 1 = decay, 2 = sustain
klasttrig init -1
kval init 0.0
asig init 0
kindx = 0
kattack_base init 0
kdecay_base init 0
krelease_base init 0
kattack_samps init 0
kdecay_samps init 0
krelease_samps init 0
kattack_coef init 0
kdecay_coef init 0
ksustain_coef init 0
klast_attack init -1
klast_decay init -1
klast_release init -1
if (klast_attack != kattack) then
klast_attack = kattack
if(kattack > 0) then
kattack_samps = kattack * sr
kattack_coef = adsr140_calc_coef(kattack_samps, 0.3)
kattack_base = (1.0 + 0.3) * (1 - kattack_coef)
else
kattack_samps = 0
kattack_coef = 0
kattack_base = 0
endif
endif
if (klast_decay != kdecay) then
klast_decay = kdecay
kdecay_samps = kdecay * sr
kdecay_coef = adsr140_calc_coef(kdecay_samps, 0.0001)
kdecay_base = (ksustain - 0.0001) * (1.0 - kdecay_coef)
endif
if (klast_release != krelease) then
klast_release = krelease
krelease_samps = krelease * sr
krelease_coef = adsr140_calc_coef(krelease_samps, 0.0001)
krelease_base = -0.0001 * (1.0 - krelease_coef)
endif
while (kindx < ksmps) do
if (agate[kindx] > 0) then
kretrig = aretrig[kindx]
if (kretrig > 0 && klasttrig <= 0) then
kstate = 0
endif
klasttrig = kretrig
if (kstate == 0) then
if(kattack <= 0) then
kval = 1.0
kstate = 1
else
kval = kattack_base + (kval * kattack_coef)
if(kval >= 1.0) then
kval = 1.0
kstate = 1
endif
asig[kindx] = kval
endif
elseif (kstate == 1) then
kval = kdecay_base + (kval * kdecay_coef)
if(kval <= ksustain) then
kval = ksustain
kstate = 2
endif
asig[kindx] = kval
else
asig[kindx] = ksustain
endif
else ; in a release state
kstate = 0
if (kval == 0.0) then
asig[kindx] = 0
else
; releasing
kval = krelease_base + (kval * krelease_coef)
if(kval <= 0.0) then
kval = 0.0
endif
asig[kindx] = kval
endif
endif
kindx += 1
od
xout asig
</codeBody>
<comments></comments>
</udo>
</opcodeList>
</instrument>