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
|
#include "/twist/transform_api.udo"
#include "/frequency_tools.udo"
opcode _twst_tf_normalise_analyse, i, iii
ifn, istartsamp, iendsamp xin
iscale = 0
imaxpos = 0
imaxneg = 0
while (istartsamp < iendsamp) do
ival table istartsamp, ifn
if (ival > 0 && ival > imaxpos) then
imaxpos = ival
elseif (ival < 0 && ival < imaxneg) then
imaxneg = ival
endif
istartsamp += 1
od
iscale = ((1 / max(abs(imaxneg), abs(imaxpos))))
xout iscale
endop
instr twst_tf_normalise
$TWST_TRANSFORM
i_, i_, istartsamp, iendsamp, idocut, ilength twst_tf_getstate
aL, aR, ileft, iright twst_getinput
istereoequal = twst_parami("equal")
kuserscale = twst_param:k("scale")
if (ileft == 1) then
iscalingL _twst_tf_normalise_analyse gitwst_bufferL[gitwst_instanceindex], istartsamp, iendsamp
endif
if (iright == 1) then
iscalingR _twst_tf_normalise_analyse gitwst_bufferR[gitwst_instanceindex], istartsamp, iendsamp
endif
if (istereoequal == 1 && ileft == 1 && iright == 1) then
iscaling = min(iscalingL, iscalingR)
aL *= iscaling * kuserscale
aR *= iscaling * kuserscale
elseif (ileft == 1) then
aL *= iscalingL * kuserscale
elseif (iright == 1) then
aR *= iscalingR * kuserscale
endif
outs aL, aR
endin
instr twst_tf_amplitude
$TWST_TRANSFORM
aL, aR, ileft, iright twst_getinput
kgain = twst_param:k("gain")
kbalance = twst_param:k("balance")
if (ileft == 1) then
kb = max:k(1, (1 - kbalance) * 2)
aL *= kgain * kb
endif
if (iright == 1) then
kb = max:k(1, kbalance * 2)
aR *= kgain * kb
endif
outs aL, aR
endin
instr twst_tf_strobe
$TWST_TRANSFORM
aL, aR, ileft, iright twst_getinput
krate = twst_param:k("rate")
kholdtime = twst_param:k("holdtime")
kwindowed = twst_param:k("windowed")
ktrig metro krate
ktrig trighold ktrig, kholdtime
kamp = 1 - ktrig
if (kwindowed == 1) then
kenv portk kamp, kholdtime * 0.5
else
kenv = kamp
endif
if (ileft == 1) then
aL *= kenv
endif
if (iright == 1) then
aR *= kenv
endif
outs aL, aR
endin
instr twst_tf_bitcrush
$TWST_TRANSFORM
aL, aR, ileft, iright twst_getinput
kcrush = twst_param:k("crush")
if (ileft == 1) then
aL bitcrush aL, kcrush
elseif (iright == 1) then
aR bitcrush aR, kcrush
endif
outs aL, aR
endin
instr twst_tf_suppress
$TWST_TRANSFORM
aL, aR, ileft, iright twst_getinput
kmode = twst_param:k("mode")
kthreshold = twst_param:k("threshold")
if (ileft == 1) then
if (kmode == 0) then
aL limit aL, -kthreshold, kthreshold
elseif (kmode == 1) then
aL wrap aL, -kthreshold, kthreshold
elseif (kmode == 2) then
aL mirror aL, -kthreshold, kthreshold
endif
endif
if (iright == 1) then
if (kmode == 0) then
aR limit aR, -kthreshold, kthreshold
elseif (kmode == 1) then
aR wrap aR, -kthreshold, kthreshold
elseif (kmode == 2) then
aR mirror aR, -kthreshold, kthreshold
endif
endif
outs aL, aR
endin
instr twst_tf_pdclip
$TWST_TRANSFORM
aL, aR, ileft, iright twst_getinput
kwidth = twst_param:k("width")
kcentre = twst_param:k("centre")
ibipolar = twst_parami("bipolar")
ifullscale = twst_parami("fullscale")
if (ileft == 1) then
aL pdclip aL, kwidth, kcentre, ibipolar, ifullscale
endif
if (iright == 1) then
aR pdclip aR, kwidth, kcentre, ibipolar, ifullscale
endif
outs aL, aR
endin
instr twst_tf_distort
$TWST_TRANSFORM
aL, aR, ileft, iright twst_getinput
kamount = twst_param:k("amount")
ihp = twst_parami("halfpower")
ifn twst_tf_getwaveform
if (ileft == 1) then
aL distort aL, kamount, ifn, ihp
endif
if (iright == 1) then
aL distort aR, kamount, ifn, ihp
endif
outs aL, aR
endin
instr twst_tf_distort1
$TWST_TRANSFORM
aL, aR, ileft, iright twst_getinput
kpregain = twst_param:k("pregain")
kpostgain = twst_param:k("postgain")
kshape1 = twst_param:k("shape1")
kshape2 = twst_param:k("shape2")
if (ileft == 1) then
aL distort1 aL, kpregain, kpostgain, kshape1, kshape2, 1
endif
if (iright == 1) then
aL distort1 aR, kpregain, kpostgain, kshape1, kshape2, 1
endif
outs aL, aR
endin
|