aboutsummaryrefslogtreecommitdiff
path: root/site/udo/twist/transforms/spectral.udo
blob: b5f2fab9ffe6471e34a52319ebd59557dd1db944 (plain)
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
#include "/twist/transform_api.udo"
#include "/pvs_tabproc.udo"
#include "/spectral_transforms.udo"
#include "/fx_autoglitch.udo"
#include "/host_platform.udo"
#include "/addsub.udo"

instr twst_tf_tpvinvert
	$TWST_TRANSFORM
	setksmps(64)
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kinvertamp = twst_param:k("invertamp")
	kinvertfreq = twst_param:k("invertfreq")

	if (ileft == 1) then
		kreadyL, itpvdataL tpv_anal fL
		tpv_invert kreadyL, itpvdataL, kinvertamp, kinvertfreq
		fL tpv_resynth itpvdataL, fL
		aL twst_tf_fresynth fL
	endif
	if (iright == 1) then
		kreadyR, itpvdataR tpv_anal fR
		tpv_invert kreadyR, itpvdataR, kinvertamp, kinvertfreq
		fR tpv_resynth itpvdataR, fR
		aR twst_tf_fresynth fR
	endif
	outs aL, aR
endin


instr twst_tf_tpvbubble
	$TWST_TRANSFORM
	setksmps(64)
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kchance = twst_param:k("chance")
	kstereounique = twst_param:k("stereounique")

	if (ileft == 1) then
		kreadyL, itpvdataL tpv_anal fL
		tpv_bubble kreadyL, itpvdataL, kchance, kstereounique
		fL tpv_resynth itpvdataL, fL
		aL twst_tf_fresynth fL
	endif
	if (iright == 1) then
		kreadyR, itpvdataR tpv_anal fR
		tpv_bubble kreadyR, itpvdataR, kchance, kstereounique
		fR tpv_resynth itpvdataR, fR
		aR twst_tf_fresynth fR
	endif
	outs aL, aR
endin

instr twst_tf_tpvsmear
	$TWST_TRANSFORM
	setksmps(64)
	fL, fR, aL, aR, ileft, iright twst_getfinput
	imaxframes = twst_parami("maxframes")
	kframes = twst_param:k("frames")
	kavgfreqs = twst_param:k("avgfreqs")
	kincludeoriginal = twst_param:k("includeoriginal")

	if (ileft == 1) then
		kreadyL, itpvdataL tpv_anal fL
		tpv_smear kreadyL, itpvdataL, imaxframes, kframes, kavgfreqs, kincludeoriginal
		fL tpv_resynth itpvdataL, fL
		aL twst_tf_fresynth fL
	endif
	if (iright == 1) then
		kreadyR, itpvdataR tpv_anal fR
		tpv_smear kreadyR, itpvdataR, imaxframes, kframes, kavgfreqs, kincludeoriginal
		fR tpv_resynth itpvdataR, fR
		aR twst_tf_fresynth fR
	endif
	outs aL, aR
endin


instr twst_tf_tpvscramble
	$TWST_TRANSFORM
	setksmps(64)
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kstep = twst_param:k("step")
	kdoamp = twst_param:k("scrambleamp")
	kdofreq = twst_param:k("scramblefreq")

	if (ileft == 1) then
		kreadyL, itpvdataL tpv_anal fL
		tpv_scramble kreadyL, itpvdataL, kstep, kdoamp, kdofreq
		fL tpv_resynth itpvdataL, fL
		aL twst_tf_fresynth fL
	endif
	if (iright == 1) then
		kreadyR, itpvdataR tpv_anal fR
		tpv_scramble kreadyR, itpvdataR, kstep, kdoamp, kdofreq
		fR tpv_resynth itpvdataR, fR
		aR twst_tf_fresynth fR
	endif
	outs aL, aR
endin

instr twst_tf_tpvthreshold
	$TWST_TRANSFORM
	setksmps(64)
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kthreshold = twst_param:k("threshold")
	kdirection = twst_param:k("direction")

	if (ileft == 1) then
		kreadyL, itpvdataL tpv_anal fL
		tpv_threshold kreadyL, itpvdataL, kthreshold, kdirection
		fL tpv_resynth itpvdataL, fL
		aL twst_tf_fresynth fL
	endif
	if (iright == 1) then
		kreadyR, itpvdataR tpv_anal fR
		tpv_threshold kreadyR, itpvdataR, kthreshold, kdirection
		fR tpv_resynth itpvdataR, fR
		aR twst_tf_fresynth fR
	endif
	outs aL, aR
endin

instr twst_tf_tpvfreeze
	$TWST_TRANSFORM
	setksmps(64)
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kfreeze = twst_param:k("freeze")
	kfreezeamp = twst_param:k("freezeamp")
	kfreezefreq = twst_param:k("freezefreq")
	kcrossfade = twst_param:k("crossfade")

	if (ileft == 1) then
		kreadyL, itpvdataL tpv_anal fL
		tpv_freeze1 kreadyL, itpvdataL, kfreeze, kfreezeamp, kfreezefreq, kcrossfade
		fL tpv_resynth itpvdataL, fL
		aL twst_tf_fresynth fL
	endif
	if (iright == 1) then
		kreadyR, itpvdataR tpv_anal fR
		tpv_freeze1 kreadyR, itpvdataR, kfreeze, kfreezeamp, kfreezefreq, kcrossfade
		fR tpv_resynth itpvdataR, fR
		aR twst_tf_fresynth fR
	endif
	outs aL, aR
endin

instr twst_tf_tpvwrap
	$TWST_TRANSFORM
	setksmps(64)
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kwrapampbin = twst_param:k("wrapampbin")
	kwrapfreqbin = twst_param:k("wrapfreqbin")
	
	if (ileft == 1) then
		i_, inumbins, i_, i_ pvsinfo fL
		kreadyL, itpvdataL tpv_anal fL
		tpv_wrap kreadyL, itpvdataL, kwrapampbin * inumbins, kwrapfreqbin * inumbins
		fL tpv_resynth itpvdataL, fL
		aL twst_tf_fresynth fL
	endif
	if (iright == 1) then
		i_, inumbins, i_, i_ pvsinfo fR
		kreadyR, itpvdataR tpv_anal fR
		tpv_wrap kreadyR, itpvdataR, kwrapampbin * inumbins, kwrapfreqbin * inumbins
		fR tpv_resynth itpvdataR, fR
		aR twst_tf_fresynth fR
	endif
	outs aL, aR
endin

instr twst_tf_tpvswap
	$TWST_TRANSFORM
	setksmps(64)
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kampStart = twst_param:k("ampstart")
	kampLength = twst_param:k("amplength")
	kampTarget = twst_param:k("amptarget")
	kfreqStart = twst_param:k("freqstart")
	kfreqLength = twst_param:k("freqlength")
	kfreqTarget = twst_param:k("freqtarget")
	kwrapmode = twst_param:k("wrapmode")
	
	if (ileft == 1) then
		i_, inumbins, i_, i_ pvsinfo fL
		kreadyL, itpvdataL tpv_anal fL
		tpv_swap kreadyL, itpvdataL, kampStart * inumbins, kampLength * inumbins, kampTarget * inumbins, kfreqStart * inumbins, kfreqLength * inumbins, kfreqTarget * inumbins, kwrapmode
		fL tpv_resynth itpvdataL, fL
		aL twst_tf_fresynth fL
	endif
	if (iright == 1) then
		i_, inumbins, i_, i_ pvsinfo fR
		kreadyR, itpvdataR tpv_anal fR
		tpv_swap kreadyR, itpvdataR, kampStart * inumbins, kampLength * inumbins, kampTarget * inumbins, kfreqStart * inumbins, kfreqLength * inumbins, kfreqTarget * inumbins, kwrapmode
		fR tpv_resynth itpvdataR, fR
		aR twst_tf_fresynth fR
	endif
	outs aL, aR
endin

instr twst_tf_tpvaverage
	$TWST_TRANSFORM
	setksmps(64)
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kmax = twst_param:k("maxframes")
	kavgamp = twst_param:k("avgamp")
	kavgfreq = twst_param:k("avgfreq")
	krate = twst_param:k("rate")

	ktrig metro krate

	if (ileft == 1) then
		kreadyL, itpvdataL tpv_anal fL
		tpv_average kreadyL, itpvdataL, kmax, kavgamp, kavgfreq, ktrig
		fL tpv_resynth itpvdataL, fL
		aL twst_tf_fresynth fL
	endif
	if (iright == 1) then
		kreadyR, itpvdataR tpv_anal fR
		tpv_average kreadyR, itpvdataR, kmax, kavgamp, kavgfreq, ktrig
		fR tpv_resynth itpvdataR, fR
		aR twst_tf_fresynth fR
	endif
	outs aL, aR
endin


/*
instr twst_tf_stencil
	$TWST_TRANSFORM
	Spvx = strcat(host_tempdir(), "twist_stencil.pvx")
	ifftsize = twst_parami("fftsize")
	kran init 0
	ktimek timeinstk
	if (ktimek == 1) then
		ifnL, ifnR, istart, ilen, ileft, iright twst_getcrossdata
		ikcycles = round(ilen / kr)
		kcount = 1
		while (kcount < ikcycles) do
			aLo, aRo, ileft, iright twst_getcrossinput
			if (ileft == 1 && iright == 1) then
				ain = (aLo + aRo) * 0.5
			elseif (ileft == 1) then
				ain = aLo
			elseif (iright == 1) then
				ain = aRo
			endif
			f1 pvsanal ain, ifftsize, ifftsize/4, ifftsize, 1
			pvsfwrite f1, Spvx
			kcount += 1
		od

	elseif (ktimek == 1) then		
		schedulek("_twst_tf_stencilplayback", 0, p3, p4, Spvx) ; TODO : won't work offline
	endif

	aL, aR bus_read "stencilplayback"
	kreleasing init 0
	if (kreleasing == 0 && release:k() == 1) then
		turnoff2 "_twst_tf_stencilplayback", 0, 1
		kreleasing = 1
	endif

	outs aL, aR
endin

instr _twst_tf_stencilplayback
	$TWST_TRANSFORM
	Spvx = strget(p5)
	fL, fR, aL, aR, ileft, iright twst_getfinput
	ifftsize = twst_parami("fftsize")
	kgain = twst_param:k("gain")
	klevel = twst_param:k("level")

	ifn ftgentmp 0, 0, (ifftsize * 2) + 1, 43, Spvx, 1

	if (ileft == 1) then
		fpsL pvstencil fL, kgain, klevel, ifn
		aL twst_tf_fresynth fpsL
	endif
	if (iright == 1) then
		fpsR pvstencil fR, kgain, klevel, ifn
		aR twst_tf_fresynth fpsR
	endif
	bus_mix("stencilplayback", aL, aR)
endin
*/

instr twst_tf_spectralshift
	$TWST_TRANSFORM
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kfreqincr = twst_param:k("freqincr")
	kporttime = twst_param:k("porttime")
	kfreqscale = twst_tf_pitchscale()
	istart = twst_parami("start")
	iend = twst_parami("end")
	ifn = twst_tf_getwaveform()
	
	if (ileft == 1) then
		aL spc_shift fL, kfreqincr, istart, iend, kfreqscale, kporttime, ifn
	endif
	if (iright == 1) then
		aR spc_shift fR, kfreqincr, istart, iend, kfreqscale, kporttime, ifn
	endif
	outs aL, aR
endin

instr twst_tf_spectraldelay
	$TWST_TRANSFORM
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kdeltime = twst_param:k("time")
	kdeladd = twst_param:k("add")
	kporttime = twst_param:k("porttime")
	kfreqscale = twst_tf_pitchscale()
	istart = twst_parami("start")
	iend = twst_parami("end")
	ifn = twst_tf_getwaveform()
	
	if (ileft == 1) then
		aL spc_delay fL, kdeltime, kdeladd, istart, iend, kfreqscale, kporttime, ifn
	endif
	if (iright == 1) then
		aR spc_delay fR, kdeltime, kdeladd, istart, iend, kfreqscale, kporttime, ifn
	endif
	outs aL, aR
endin

instr twst_tf_spectralgate
	$TWST_TRANSFORM
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kthresh = twst_param:k("threshold")
	khold = twst_param:k("hold")
	kporttime = twst_param:k("porttime")
	kfreqscale = twst_tf_pitchscale()
	istart = twst_parami("start")
	iend = twst_parami("end")
	ifn = twst_tf_getwaveform()
	
	if (ileft == 1) then
		aL spc_gate fL, kthresh, khold, istart, iend, kfreqscale, kporttime, ifn
	endif
	if (iright == 1) then
		aR spc_gate fR, kthresh, khold, istart, iend, kfreqscale, kporttime, ifn
	endif
	outs aL, aR
endin

instr twst_tfi_spectralgrain1
	$TWST_TRANSFORM
	ileft, iright, istartsamp, iendsamp, idocut, ilength twst_tf_getstate
	ifnL, ifnR twst_tfi_getfn
	
	ireadmode = twst_parami("readmode")
	if (ireadmode == 0) then
		ktime linseg 0, p3, ilength
	elseif (ireadmode == 1) then
		ktime = twst_param:k("readtime")
		twst_tf_setplayposition ktime
		ktime *= ilength
	elseif (ireadmode == 2) then
		itimescale = twst_parami("timescale")
		p3 = ilength * itimescale
		ktime linseg 0, p3, ilength
	elseif (ireadmode == 3) then
		ktime linseg ilength, p3, 0
	endif

	kgraindur = twst_param:k("graindur")
	ifftsize = twst_parami("fftsize")
	ilayers = twst_parami("layers")
	kporttime = twst_param:k("porttime")
	kfreqscale = twst_tf_pitchscale()
	kfreqrand = twst_param:k("freqrand")
	kdurrand = twst_param:k("durrand")
	kpitchrand = twst_param:k("pitchrand")
	istart = twst_parami("start")
	iend = twst_parami("end")
	ifn = twst_tf_getwaveform()
	twst_setlatencysamples(ifftsize)

	if (ileft == 1) then
		aL spc_grain1 ifnL, ktime, kgraindur, ifftsize, ilayers, istart, iend, kfreqscale, kfreqrand, kdurrand, kpitchrand, kporttime, ifn
	endif
	if (iright == 1) then
		aR spc_grain1 ifnR, ktime, kgraindur, ifftsize, ilayers, istart, iend, kfreqscale, kfreqrand, kdurrand, kpitchrand, kporttime, ifn
	endif
	outs aL, aR
endin

instr twst_tf_spectralread
	$TWST_TRANSFORM
	ileft, iright, istartsamp, iendsamp, idocut, ilength twst_tf_getstate
	ifftsize = twst_parami("fftsize")
	ktime = twst_param:k("readtime") * ilength
	twst_tf_setplayposition ktime
	twst_setlatencysamples(ifftsize)
	
	ktimek timeinstk
	ilensamps = iendsamp - istartsamp
	ikcycles = ilength * kr
	kcount init 0
	if (ktimek == 1) then
		while (kcount < ikcycles) do
			apos linseg 0, ilength, iendsamp
			if (ileft == 1 && iright == 1) then
				aL table3 apos, gitwst_bufferL[gitwst_instanceindex]
				aR table3 apos, gitwst_bufferR[gitwst_instanceindex]
				asig = (aL + aR) * 0.5
			elseif (ileft == 1) then
				asig table3 apos, gitwst_bufferL[gitwst_instanceindex]
			elseif (iright == 1) then
				asig table3 apos, gitwst_bufferR[gitwst_instanceindex]
			endif
			fsig pvsanal asig, ifftsize, ifftsize/4, ifftsize, 1
			ipbuf, k_ pvsbuffer fsig, ilength
			kcount += 1
		od
	else
		if (ileft == 1) then
			fL pvsbufread ktime, ipbuf
			aL twst_tf_fresynth fL
		endif
		if (iright == 1) then
			fR pvsbufread ktime, ipbuf
			aR twst_tf_fresynth fR
		endif
	endif
	outs aL, aR
endin

instr twst_tf_centroidoscillator
	$TWST_TRANSFORM
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kporttime = twst_param:k("porttime")
	kfreqscale = twst_tf_pitchscale()
	kfn twst_tf_getwaveformk

	if (ileft == 1) then
		kcent pvscent fL
		kfreq portk kcent * kfreqscale, kporttime
		aL oscilikt 1, kfreq, kfn
	endif
	if (iright == 1) then
		kcent pvscent fR
		kfreq portk kcent * kfreqscale, kporttime
		aR oscilikt 1, kfreq, kfn
	endif
	outs aL, aR
endin

instr twst_tf_binoscillator
	$TWST_TRANSFORM
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kporttime = twst_param:k("porttime")
	kbin = twst_param:k("bin")
	kfreqscale = twst_tf_pitchscale()
	kfn twst_tf_getwaveformk

	if (ileft == 1) then
		i_, inumbins, i_, i_ pvsinfo fL
		kamp, kfreqbase pvsbin fL, round:k(kbin * inumbins)
		kfreq portk kfreqbase * kfreqscale, kporttime
		aL oscilikt 1, kfreq, kfn
	endif
	if (iright == 1) then
		i_, inumbins, i_, i_ pvsinfo fR
		kamp, kfreqbase pvsbin fL, round:k(kbin * inumbins)
		kfreq portk kfreqbase * kfreqscale, kporttime
		aR oscilikt 1, kfreq, kfn
	endif
	outs aL, aR
endin

opcode _twst_tf_partialreconstruction, a, aikkkikkki
	ain, ifftsize, kthresh, kminpoints, kmaxgap, imaxtracks, kampscale, kfreqscale, kmaxtracks, ifn xin
	ffreq, fphase pvsifd ain, ifftsize, ifftsize/4, 1
	ftrks partials ffreq, fphase, kthresh, kminpoints, kmaxgap, imaxtracks
	aout resyn ftrks, kampscale, kfreqscale, kmaxtracks, ifn
	aout dcblock aout
	xout aout
endop

instr twst_tf_partialreconstruction
	$TWST_TRANSFORM
	aL, aR, ileft, iright twst_getinput
	ifftsize = twst_parami("fftsize")
	kthresh = twst_param:k("threshold")
	kminpoints = twst_param:k("minpoints")
	kmaxgap = twst_param:k("maxgap")
	imaxtracks = round(twst_parami("anlmaxtracks") * ifftsize * 0.5)
	kampscale = twst_param:k("ampscale")
	kfreqscale = twst_tf_pitchscale()
	kmaxtracks = round:k(twst_param:k("resmaxtracks") * ifftsize * 0.5)
	ifn = twst_tf_getwaveform()
	twst_setlatencysamples(ifftsize)

	if (ileft == 1) then
		aL _twst_tf_partialreconstruction aL, ifftsize, kthresh, kminpoints, kmaxgap, imaxtracks, kampscale, kfreqscale, kmaxtracks, ifn
	endif
	if (iright == 1) then
		aR _twst_tf_partialreconstruction aR, ifftsize, kthresh, kminpoints, kmaxgap, imaxtracks, kampscale, kfreqscale, kmaxtracks, ifn
	endif
	outs aL, aR
endin

opcode _twst_tf_residual, a, aii
	ain, ifftsize, ihsize xin
	ffr, fphs pvsifd ain, ifftsize, ihsize, 1
	ftrk partials ffr, fphs, 0, 1, 3, 500
	aout sinsyn ftrk, 2, 500, gifnSine
	asd delayr ifftsize / sr
	asig deltapn ifftsize - ihsize
	delayw  ain
	xout asig - aout
endop

instr twst_tf_residual
	$TWST_TRANSFORM
	aL, aR, ileft, iright twst_getinput
	ifftsize = twst_parami("fftsize")
	twst_setlatencysamples(ifftsize)
	ihsize = ifftsize / 4
	if (ileft == 1) then
		aL _twst_tf_residual aL, ifftsize, ihsize
	endif
	if (iright == 1) then
		aR _twst_tf_residual aR, ifftsize, ihsize
	endif
	outs aL, aR
endin

/* not in WASM
instr twst_tf_trace
	$TWST_TRANSFORM
	fL, fR, aL, aR, ileft, iright twst_getfinput
	inumbins = twst_parami("fftsize") / 2
	kbins = twst_param("bins") * inumbins

	if (ileft == 1) then
		foutL pvstrace fL, kbins
		aL twst_tf_fresynth foutL
	endif
	if (iright == 1) then
		foutR pvstrace fR, kbins
		aR twst_tf_fresynth foutR
	endif
	outs aL, aR
endin
*/

instr twst_tf_isolator
	$TWST_TRANSFORM
	fL, fR, aL, aR, ileft, iright twst_getfinput
	kbin = twst_param("bin")
	kattenuation = twst_param("attenuation")
	kgain = twst_param("accentuation")

	if (ileft == 1) then
		foutL pvsarp fL, kbin, kattenuation, kgain
		aL twst_tf_fresynth foutL
	endif
	if (iright == 1) then
		foutR pvsarp fR, kbin, kattenuation, kgain
		aR twst_tf_fresynth foutR
	endif
	outs aL, aR
endin

instr twst_tf_blur
	$TWST_TRANSFORM
	fL, fR, aL, aR, ileft, iright twst_getfinput
	ktime = twst_param:k("time")
	if (ileft == 1) then
		fL1 pvsblur fL, ktime, 3
		aL twst_tf_fresynth fL1
	endif
	if (iright == 1) then
		fR1 pvsblur fR, ktime, 3
		aR twst_tf_fresynth fR1
	endif
	outs aL, aR
endin

instr twst_tf_spectralautoglitch
	$TWST_TRANSFORM
	aL, aR, ileft, iright twst_getinput
	kchangerate = twst_param:k("changerate")
	kchangechance = twst_param:k("changechance")
	kporttime = twst_param:k("porttime")
	kdo_pitchalter = twst_param:k("pitchalter")
	ifftsize = twst_parami("fftsize")
	
	twst_setlatencysamples ifftsize

	if (ileft == 1) then
		aL fx_spectralautoglitch aL, kchangerate, kchangechance, kdo_pitchalter, kporttime, ifftsize
	endif
	if (iright == 1) then
		aR fx_spectralautoglitch aR, kchangerate, kchangechance, kdo_pitchalter, kporttime, ifftsize
	endif
	outs aL, aR
endin

instr twst_tf_subtractive
	$TWST_TRANSFORM
	aL, aR, ileft, iright twst_getinput
	ifreq = twst_parami("minfreq")
	ifreqmax = twst_parami("maxfreq")
	ifreqstepmult = twst_parami("step")
	ifreqstepmultrand = twst_parami("steprand")
	iamp = twst_parami("amp")
	iampmult = twst_parami("ampmult")

	if (ileft == 1) then
		aL as_subtractive aL, ifreq, ifreqmax, ifreqstepmult, ifreqstepmultrand, iamp, iampmult
	endif
	if (iright == 1) then
		aR as_subtractive aR, ifreq, ifreqmax, ifreqstepmult, ifreqstepmultrand, iamp, iampmult
	endif
	outs aL, aR
endin

instr twst_tf_phasemash
	$TWST_TRANSFORM
	aL, aR, ileft, iright twst_getinput
	ifftsize = twst_parami("fftsize")
	kphasemode = twst_param:k("phasereplace")
	kphasevalue = twst_param:k("phasevalue")
	
	if (kphasemode == 0) then
		kphasevalue *= 7
	else
		kphasevalue = ((kphasevalue * 2) - 1) * 3.141
	endif

	if (ileft == 1) then
		aL spc_phasemash aL, kphasemode, kphasevalue, ifftsize
	endif
	if (iright == 1) then
		aR spc_phasemash aR, kphasemode, kphasevalue, ifftsize
	endif
	outs aL, aR
endin