aboutsummaryrefslogtreecommitdiff
path: root/site/udo/twist/transforms/granular.udo
blob: c25a5179b0d690e5e577c22e0228c25fbde0b538 (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
#include "/twist/transform_api.udo"
#include "/fx_autoglitch.udo"
#include "/sample_level.udo"

instr twst_tfi_rearrange
	$TWST_TRANSFORM
	ileft, iright, istartsamp, iendsamp, idocut, ilength twst_tf_getstate
	istereounique = twst_parami("stereounique")
	ichops = twst_parami("chopnumber")
	ichopmin = twst_parami("chopmin")
	ichopmax = twst_parami("chopmax")
	ifnL, ifnR twst_tfi_getfn
	if (ileft == 1 && iright == 1) then
		if (istereounique == 1) then
			aL smp_rearrange ichops, ichopmin, ichopmax, ifnL
			aR smp_rearrange ichops, ichopmin, ichopmax, ifnR
		else
			aL, aR smp_rearrange ichops, ichopmin, ichopmax, ifnL, ifnR
		endif
	elseif (ileft == 1) then
		aL smp_rearrange ichops, ichopmin, ichopmax, ifnL
	elseif (iright == 1) then
		aR smp_rearrange ichops, ichopmin, ichopmax, ifnR
	endif
	outs aL, aR
endin

instr twst_tfi_grain
	$TWST_TRANSFORM
	ileft, iright, istartsamp, iendsamp, idocut, ilength twst_tf_getstate
	kamp = twst_param:k("amp")
	kpitch = twst_tf_pitchscale()
	kdensity = twst_param:k("density")
	kgrainsize = twst_param:k("grainsize")
	kampvar = twst_param:k("ampvar")
	kpitchvar = twst_param:k("pitchvar")
	irandom = twst_parami("randomread")
	ifnWindow = twst_tf_getwintype()
	
	ifnL, ifnR twst_tfi_getfn

	kpitch *= (sr / ftlen(ifnL))

	if (ileft == 1) then
		aL grain kamp, kpitch, kdensity, kampvar, kpitchvar, kgrainsize, ifnL, ifnWindow, 0.5, irandom
	endif
	if (iright == 1) then
		aR grain kamp, kpitch, kdensity, kampvar, kpitchvar, kgrainsize, ifnR, ifnWindow, 0.5, irandom
	endif
	outs aL, aR
endin

instr twst_tfi_syncgrain
	$TWST_TRANSFORM
	ileft, iright, istartsamp, iendsamp, idocut, ilength twst_tf_getstate
	kamp = twst_param:k("amp")
	kfreq = twst_param:k("frequency")
	kpitch = twst_tf_pitchscale()
	kgrsize = twst_param:k("grainsize")
	ioverlaps = twst_parami("overlaps")
	itimescale = twst_parami("timescale")
	ifnWindow = twst_tf_getwintype()

	iprate = (1 / ioverlaps) * itimescale
	p3 = ilength * itimescale

	ifnL, ifnR twst_tfi_getfn

	if (ileft == 1) then
		aL syncgrain kamp, kfreq, kpitch, kgrsize, iprate, ifnL, ifnWindow, ioverlaps
	endif
	if (iright == 1) then
		aR syncgrain kamp, kfreq, kpitch, kgrsize, iprate, ifnR, ifnWindow, ioverlaps
	endif
	outs aL, aR
endin

instr twst_tf_autoglitch
	$TWST_TRANSFORM
	aL, aR, ileft, iright twst_getinput
	kminratio = twst_param:k("minratio")
	kchangerate = twst_param:k("changerate")
	kchangechance = twst_param:k("changechance")
	kporttime = twst_param:k("porttime")
	kdo_distortion = twst_param:k("distortion")
	kdo_ampchange = twst_param:k("ampchange")
	ibuflens = twst_parami("buflens")
	kreadmode = twst_param:k("readmode")
	istereounique = twst_parami("stereounique")

	twst_setlatencyseconds ibuflens

	if (ileft == 1 && iright == 1) then
		aL, aR fx_autoglitch aL, aR, kminratio, kchangerate, kchangechance, kporttime, kdo_distortion, kdo_ampchange, ibuflens, istereounique, kreadmode 
	elseif (ileft == 1) then
		aL fx_autoglitch aL, kminratio, kchangerate, kchangechance, kporttime, kdo_distortion, kdo_ampchange, ibuflens, kreadmode 
	elseif (iright == 1) then
		aR fx_autoglitch aR, kminratio, kchangerate, kchangechance, kporttime, kdo_distortion, kdo_ampchange, ibuflens, kreadmode 
	endif
	outs aL, aR
endin

instr twst_tfi_retriglitch
	$TWST_TRANSFORM
	ileft, iright, istartsamp, iendsamp, idocut, ilength twst_tf_getstate
	ktriglen = twst_param:k("triglen")
	kpitchscale = twst_tf_pitchscale()
	kapplywindowing = twst_param:k("applywindowing")
	ireadmode = twst_parami("readmode")
	kwintype twst_tf_getwintypek 

	p3 = ilength
	if (ireadmode == 0) then
		atime linseg 0, p3, ilength
	elseif (ireadmode == 1) then
		ktime = twst_param:k("readtime")
		twst_tf_setplayposition ktime
		atime = a(ktime * ilength)
	elseif (ireadmode == 2) then
		itimescale = twst_parami("timescale")
		p3 = ilength * itimescale
		atime linseg 0, p3, ilength
	elseif (ireadmode == 3) then
		atime linseg ilength, p3, 0
	elseif (ireadmode == 4) then
		atime init -1
	endif

	ifnL, ifnR twst_tfi_getfn

	if (ileft == 1) then
		aL fx_retrigglitch ifnL, ktriglen, atime, kpitchscale, kapplywindowing, kwintype
	endif
	if (iright == 1) then
		aR fx_retrigglitch ifnR, ktriglen, atime, kpitchscale, kapplywindowing, kwintype
	endif
	outs aL, aR
endin