aboutsummaryrefslogtreecommitdiff
path: root/site/udo/feedback.udo
blob: 5f4b7d892d6b4af9aa6984a7f205ae5ee435e237 (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
#ifndef UDO_FEEDBACK
#define UDO_FEEDBACK ##
/*
	No-input mixer modelling

	This file is part of the SONICS UDO collection by Richard Knight 2021
		License: GPL-2.0-or-later
		http://1bpm.net
*/


opcode _arrayfilter, a, ai[]i[]o
	ain, ifreq[], igain[], index xin
	aout pareq ain, ifreq[index], igain[index], 0.775, 0
	if (index < lenarray(ifreq) - 1) then
		aout _arrayfilter aout, ifreq, igain, index+1
	endif
	xout aout
endop


opcode _fbk_componentmodel, a, a
	a1 xin
	ifreqs[] fillarray 30, 60, 100, 300, 600, 1200, 2400, 4800, 8000, 10000, 12000, 16000
	igains[] fillarray 0.4, 0.7, 1, 0.4, 0.6, 0.96, 0.4, 0.7, 0.32, 0.7, 0.8, 0.9
	a1 _arrayfilter a1, ifreqs, igains
	xout a1
endop

opcode _fbk_componentmodel2, a, a
	a1 xin
	iminfreq = 20

	adel delayr 1/iminfreq
	acomb0 deltapi 1/1000

	delayw a1

	aout = a1 - acomb0
	xout aout
endop

/*
	Simulated mixer channel
	aout fbk_channel ain, klowcut, keqlow, keqmid, keqhigh, kcompmodel

	aout		channel output

	ain 		channel input
	klowcut		low cut toggle (1 is on)
	keqlow		eq low (0 to 1)
	keqmid		eq mid (0 to 1)
	keqhigh		eq high (0 to 1)
	kcompmodel	component model (0 is off, 1 is model components)
	
*/
opcode fbk_channel, a, akkkkk
	a1, klowCut, keqlow, keqmid, keqhigh, kcompmodel xin
	a1 += noise(0.01, 0)
	;a1 dcblock a1
	a1 butterhp a1, 0.1
	
	if (klowCut == 1) then
		a1 butterhp a1, 75
	endif 


	a1 pareq a1, 80, keqlow*5, 0.7, 1
	a1 pareq a1, 2500, keqmid*5, 0.7, 0
	a1 pareq a1, 12000, keqhigh*5, 0.7, 2
	;a1 dam a1, 0.99, 0.9, 0.9, 0.01, 0.01
	;a1 limit a1, -0.5, 0.5
	a1 tanh a1
	/*krms rms a1
	if (krms > 1) then
		a1 = a1 * (1/krms)
	endif
*/
	if (kcompmodel == 1) then
		a1 _fbk_componentmodel a1
	endif
	xout a1
endop


/*
	params
		0	low cut
		1	eq low
		2	eq mid
		3	eq high
		4	component model
		5	prefade aux on/off
		6	aux 1 send
		7	aux 2 send
		8	mix level
*/
opcode fbk_mixer2, a, k[]k[]
	kparam1[], kparam2[] xin
	ain1 init 0
	ain2 init 0
	aout1 fbk_channel ain1, kparam1[0], kparam1[1], kparam1[2], kparam1[3], kparam1[4]
	aout2 fbk_channel ain2, kparam2[0], kparam2[1], kparam2[2], kparam2[3], kparam2[4]
	ain1 = 0
	ain2 = 0
	if (kparam1[5] == 1) then
		ain1 += aout1*kparam1[6]
	else
		ain1 += aout1*kparam1[6]*kparam1[8]
	endif
	ain2 += aout1*kparam1[7]*kparam1[8]

	if (kparam2[5] == 1) then
		ain2 += aout1*kparam2[7]
	else
		ain2 += aout1*kparam2[7]*kparam2[8]
	endif
	ain1 += aout2*kparam2[6]*kparam2[8]

	aout = (aout1*kparam1[8]) + (aout2*kparam2[8])
	aout pareq aout, 18000, 0.4, 0.7
	xout aout
endop





opcode fbk_mixer4, a, k[]k[]k[]k[]
	kparam1[], kparam2[], kparam3[], kparam4[] xin
	ain1 init 0
	ain2 init 0
	ain3 init 0
	ain4 init 0
	aout1 fbk_channel ain1, kparam1[0], kparam1[1], kparam1[2], kparam1[3], kparam1[4]
	aout2 fbk_channel ain2, kparam2[0], kparam2[1], kparam2[2], kparam2[3], kparam2[4]
	aout3 fbk_channel ain3, kparam3[0], kparam3[1], kparam3[2], kparam3[3], kparam3[4]
	aout4 fbk_channel ain4, kparam4[0], kparam4[1], kparam4[2], kparam4[3], kparam4[4]
	ain1 = 0
	ain2 = 0
	ain3 = 0
	ain4 = 0
	if (kparam1[5] == 1) then
		ain1 += aout1*kparam1[6]
	else
		ain1 += aout1*kparam1[6]*kparam1[8]
	endif
	ain2 += aout1*kparam1[7]*kparam1[8]

	if (kparam2[5] == 1) then
		ain2 += aout1*kparam2[7]
	else
		ain2 += aout1*kparam2[7]*kparam2[8]
	endif
	ain1 += aout2*kparam2[6]*kparam2[8]

	aout = (aout1*kparam1[8]) + (aout2*kparam2[8])
	aout pareq aout, 18000, 0.4, 2, 0.7
	xout aout
endop


#end