aboutsummaryrefslogtreecommitdiff
path: root/site/udo/quad.udo
blob: bd9abc352fc1b45d5a5c7b5d3788e7763df1d8eb (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
#ifndef UDO_QUAD
#define UDO_QUAD ##
/*
	Quadrophonic setup and tools

	This file is part of the SONICS UDO collection by Richard Knight 2025
		License: GPL-2.0-or-later
		http://1bpm.net
*/
#define QUAD ##
#include "wavetables.udo"
vbaplsinit 2, 4, 45, 135, 225, 314 ; or 0, 90, 180, 270

opcode cart2apol, ii, ii
	ix, iy xin
	idistance = sqrt(pow(ix, 2) + pow(iy, 2))
	idegrees = taninv(iy / ix) * (180 / (22 / 7)) - 90
	if (qnan(idegrees) == 1) then
		idegrees = 0
	endif
	xout idegrees, idistance
endop

opcode cart2apol, kk, kk
	kx, ky xin
	kdistance = sqrt:k(pow:k(kx, 2) + pow:k(ky, 2))
	kdegrees = taninv:k(ky / kx) * (180 / (22 / 7)) - 90
	if (qnan:k(kdegrees) == 1) then
		kdegrees = 0
	endif
	xout kdegrees, kdistance
endop

opcode quadify, aaaa, akO
	ain, kangle, kbleed xin
	a1, a2, a3, a4 vbap ain, kangle, 0, kbleed * 100
	xout a1, a2, a3, a4
endop

opcode quadify, aaaa, aakOO
	aL, aR, kangle, kspreadangle, kbleed xin
	kbleed *= 100
	aL1, aL2, aL3, aL4 vbap aL, kangle - kspreadangle, 0, kbleed
	aR1, aR2, aR3, aR4 vbap aR, kangle + kspreadangle, 0, kbleed
	xout aL1 + aR1, aL2 + aR2, aL3 + aR3, aL4 + aR4
endop

opcode _quadify_random_params, kk, 0
	kangle init random(0, 359)
	kbleed init random(0, 15)
	ktime init random(1, 10)
	krate = 1 / ktime
	ktrig metro krate
	if (ktrig == 1) then
		ktime = random:k(1, 10)
		kangle = random:k(0, 359)
		kbleed = random:k(0, 15)
	endif

	kanglep portk kangle, ktime
	kbleedp portk kbleed, ktime
	xout kanglep, kbleedp
endop

opcode quadify_random, aaaa, a
	ain xin
	kangle, kbleed _quadify_random_params
	a1, a2, a3, a4 quadify ain, kangle, kbleed
	xout a1, a2, a3, a4
endop

opcode quadify_random, aaaa, aa
	aL, aR xin
	kangle, kbleed _quadify_random_params
	a1, a2, a3, a4 quadify aL, aR, kangle, kbleed
	xout a1, a2, a3, a4
endop

#end