-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOP-CenterNode.gd
84 lines (74 loc) · 2.17 KB
/
OP-CenterNode.gd
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
extends GraphNode
#var ar=0 #Attack
#var dr=0 #Decay
#var sr=0 #Sustain
#var rr=0 #Release
#var sl=0 #Sustain level
#var tl=0 #Total level (attenuation)
#var ks=0 #Key scale
#var mul=0 #Frequency multiplier
#var dt=0 #Detune
var hz = 440.0 #Operator frequency. Tuned to A-4 by default
var feedback = 0 #TODO: Figure out if this is OK to use on multiple operators
var connections = {} #This is filled in by the algorithm validator.
var eg = global.Instr.new() #Envelope generator
var old_sample = [0,0] #held values for feedback processing. Move to EG?
#func genwave(n, waveform = gen.waveforms.SINE, duty = 0.5):
## return cgen.call("wave", n, waveform, duty)
# return cgen.wave(n, waveform, duty)
#
#func gensint2(n):
## return cgen.call("sint2", n)
# return cgen.sint2(n)
func _ready():
# print(name, " inputs: ", get_connection_input_count(),\
# " Outputs: ", get_connection_output_count())
pass
##Sample returns a Vec2 of (phase, amplitude). Phase is used to calculate modulation.
#func request_sample(phase:float) -> float:
# var out:float
#
# #TODO: Don't sin-modulate phase at first, add phases together for each
# # Parallel modulator, THEN call modulate on sample before passing back.
#
# var modulator:float
# if connections.size() > 0:
#
# #First, mix the parallel modulators.
# for o in connections.keys():
# modulator += $"..".get_node(o).request_sample(phase)
#
# modulator /= connections.size()
#
# if $Bypass.pressed: return modulator
#
# #Now modulate.
# phase += modulator
# phase *= eg.detune
# phase *= eg.freq_mult
# phase = (gensint2(phase) + 1.0) / 2.0
#
# out = genwave(phase, eg.waveform) #* (1+ eg.dt/500.0)
# out *= eg.tl / 100.0
#
#
# else: #Terminus. No further modulation required.
# if $Bypass.pressed: return 0.0
# phase *= eg.detune
# phase *= eg.freq_mult
#
# out = genwave(phase, eg.waveform) #* (1+ eg.dt/500.0)
#
# #Process feedback
# if eg.feedback > 0:
# var average = (old_sample[0] + old_sample[1]) * 0.5
# var scaled_fb = average / pow(2, 6-eg.feedback)
# old_sample[1] = old_sample[0]
# old_sample[0] = genwave(phase + scaled_fb, eg.waveform)
#
# out = old_sample[0]
#
# out *= eg.tl / 100.0
#
# return out
#