/
ringmod.udo
73 lines (52 loc) · 1.27 KB
/
ringmod.udo
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
/*
Implementation of Julian Parker’s digital model of a Ring
Modulator.
http://kunstmusik.com/2013/09/07/julian-parker-ring-modulator/
UDO version by Steven Yi
Original: 2013.09.07
Revised: 2015.04.07
*/
opcode ringmod,a,aa
ain, acarrier xin
itab chnget "ringmod.table"
; TABLE INIT
if(itab == 0) then
; generate table according to formula 2 in document
itablen = 2^16
itab ftgen 0, 0, itablen, -2, 0
i_vb = 0.2
i_vl = 0.4
i_h = .1
i_vl_vb_denom = ((2 * i_vl) - (2 * i_vb))
i_vl_add = i_h * ( ((i_vl - i_vb)^2) / i_vl_vb_denom)
i_h_vl = i_h * i_vl
indx = 0
chnset itab, "ringmod.table"
ihalf = itablen / 2
until (indx >= itablen) do
iv = (indx - ihalf) / ihalf
iv = abs(iv)
if(iv <= i_vb) then
tableiw 0, indx, itab, 0, 0, 2
elseif(iv <= i_vl) then
ival = i_h * ( ((iv - i_vb)^2) / i_vl_vb_denom)
tableiw ival, indx, itab, 0, 0, 2
else
ival = (i_h * iv) - i_h_vl + i_vl_add
tableiw ival, indx, itab, 0, 0, 2
endif
indx += 1
od
endif
; END TABLE INIT
ain1 = (ain * .5)
acar2 = acarrier + ain1
ain2 = acarrier - ain1
asig1 table3 acar2, itab, 1, 0.5
asig2 table3 -acar2, itab, 1, 0.5
asig3 table3 ain2, itab, 1, 0.5
asig4 table3 -ain2, itab, 1, 0.5
asiginv = -(asig3 + asig4)
aout sum asig1, asig2, asiginv
xout aout
endop