aboutsummaryrefslogtreecommitdiff
path: root/site/udo/twist/transforms/cross_processing.udo
blob: 203c39334b48a574fb5dc227910bca7a861fab1d (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
#include "/twist/transform_api.udo"
#include "/mfcc_match.udo"
#include "/fftconvolve.udo"
#include "/chop.udo"


instr twst_tf_crossrearrange
	$TWST_TRANSFORM
	aL, aR, ileft, iright twst_getinput
	kminsamples = twst_param:k("minsamples")
	kmaxsamples = twst_param:k("maxsamples")
	kstereounique = twst_param:k("stereounique")
	krate = twst_param:k("rate")

	ktrig metro krate
	async init 0
	
	if (ktrig == 1) then
		kfnLo, kfnRo twst_getrandombuffers kstereounique
		ktablen = tableng:k(kfnLo)
		klen = min:k(random:k(kminsamples, kmaxsamples), ktablen)
		kstart = random:k(0, ktablen - klen)
		async = 1
	else
		async = 0
	endif

	apos, a_ syncphasor 1 / (klen / sr), async
	areadpos = (apos * klen) + kstart

	if (ileft == 1) then
		aL tablekt areadpos, kfnLo
	endif
	if (iright == 1) then
		aR tablekt areadpos, kfnRo
	endif

	outs aL, aR
endin

instr twst_tf_directconvolve
	$TWST_TRANSFORM
	aL, aR, ileft, iright twst_getinput
	ifnLo, ifnRo twst_tfi_getcrossfn
	kamp = twst_parami("amp")
	isizeratio = twst_parami("sizeratio")
	if (ileft == 1) then
		aL dconv aL * kamp, isizeratio * ftlen(ifnLo), ifnLo
	endif
	if (iright == 1) then
		aR dconv aR * kamp, isizeratio * ftlen(ifnRo), ifnRo
	endif
	outs aL, aR
endin

instr twst_tf_blockconvolve
	$TWST_TRANSFORM
	aL, aR, ileft, iright twst_getinput 
	aLo, aRo, ilefto, irighto twst_getcrossinput 
	ifftsize = twst_parami("fftsize")
	ioverlap = twst_parami("overlap")
	ihopsize = ifftsize / ioverlap

	if (ileft == 1 && ilefto == 1) then
		aL blockconvolve aL, aLo, ifftsize, ihopsize
	endif
	if (iright == 1 && irighto == 1) then
		aR blockconvolve aR, aRo, ifftsize, ihopsize
	endif
	outs aL, aR
endin

/* not in WASM at current
instr twst_tf_tvconv
	$TWST_TRANSFORM
	aL, aR, ileft, iright twst_getinput
	aLo, aRo, ilefto, irighto twst_getcrossinput
	kapply1 = twst_param:k("apply1")
	kapply2 = twst_param:k("apply2")
	imode = twst_parami("mode")
	iparts = twst_parami("parts")
	idftfiltersize = twst_parami("dftfiltersize")
	ifirfiltersize = twst_parami("firfiltersize")

	if (imode == 1) then
		iparts = 1
		ifiltersize = ifirfiltersize
	else
		ifiltersize = idftfiltersize
	endif

	if (ileft == 1 && ilefto == 1) then
		aL tvconv aL, aLo, kapply1, kapply2, iparts, ifiltersize
	endif

	if (iright == 1 && irighto == 1) then
		aR tvconv aR, aRo, kapply1, kapply2, iparts, ifiltersize
	endif
	outs aL, aR
endin
*/

instr twst_tf_crosssynth
	$TWST_TRANSFORM
	fL, fR, aL, aR, ileft, iright twst_getfinput 
	fLo, fRo, ilefto, irighto twst_getfcrossinput 
	kamp1 = twst_param:k("amp1")
	kamp2 = twst_param:k("amp2")

	if (ileft == 1 && ilefto == 1) then
		foutL pvscross fL, fLo, kamp1, kamp2
		aL twst_tf_fresynth foutL
	endif

	if (iright == 1 && irighto == 1) then
		foutR pvscross fR, fRo, kamp1, kamp2
		aR twst_tf_fresynth foutR
	endif
	outs aL, aR
endin


instr twst_tf_morph
	$TWST_TRANSFORM
	fL, fR, aL, aR, ileft, iright twst_getfinput 
	fLo, fRo, ilefto, irighto twst_getfcrossinput 
	kamp = twst_param:k("amp")
	kfreq = twst_param:k("freq")

	if (ileft == 1 && ilefto == 1) then
		foutL pvsmorph fL, fLo, kamp, kfreq
		aL twst_tf_fresynth foutL
	endif

	if (iright == 1 && irighto == 1) then
		foutR pvsmorph fR, fRo, kamp, kfreq
		aR twst_tf_fresynth foutR
	endif
	outs aL, aR
endin

instr twst_tf_mfccmatch
	$TWST_TRANSFORM
	aL, aR, ileft, iright twst_getinput
	ifnoL, ifnoR twst_tfi_getcrossfn
	ifftsize = twst_parami("fftsize")
	ifreqmin = twst_parami("freqmin")
	ifreqmax = twst_parami("freqmax")
	ibands = twst_parami("bands")
	kstretch = twst_param:k("stretch")
	kauditionreadyL init 0
	kauditionreadyR init 0
	ktimek timeinstk
	
	if (ileft == 1) then
		kdone, ifnAnalysisL mfm_analysecorpus ktimek, ifnoL, ifreqmin, ifreqmax, ifftsize, ibands, -1, 1
		if (kdone == 1) then
			kauditionreadyL = 1
			aoutL mfm_matchplay aL, ifnoL, ifnAnalysisL, kstretch, ifreqmin, ifreqmax, ifftsize, ibands
		endif
	else
		kauditionreadyL = 1
	endif
	if (iright == 1) then
		kdone, ifnAnalysisR mfm_analysecorpus ktimek, ifnoR, ifreqmin, ifreqmax, ifftsize, ibands, -1, 1
		if (kdone == 1) then
			kauditionreadyR = 1
			aoutR mfm_matchplay aR, ifnoR, ifnAnalysisR, kstretch, ifreqmin, ifreqmax, ifftsize, ibands
		endif
	else
		kauditionreadyR = 1
	endif

	chnset (kauditionreadyL & kauditionreadyR), "auditionready"
	outs aoutL, aoutR
endin