diff options
author | Grant Shangreaux <grant@unabridgedsoftware.com> | 2021-10-30 23:56:38 -0500 |
---|---|---|
committer | Grant Shangreaux <grant@unabridgedsoftware.com> | 2021-10-30 23:56:38 -0500 |
commit | 4565611763cbb041384230580f9c7de4fea7da6f (patch) | |
tree | 9d983f4da2dc60a578379958eda028242412ae71 /klangfarb | |
parent | b9559897c05b8c2f67e34372685952d586af5c3d (diff) |
Add: square wave and waveform switch interface in godot
Diffstat (limited to 'klangfarb')
-rw-r--r-- | klangfarb/main.gd | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/klangfarb/main.gd b/klangfarb/main.gd index f91dbb7..8abf461 100644 --- a/klangfarb/main.gd +++ b/klangfarb/main.gd @@ -1,10 +1,13 @@ extends AudioStreamPlayer # controllable frequency interface -export(float, 20, 8000, 10) var freq = 440.0 +export(float, 20, 8000, 5) var freq = 440.0 +# control wave form +export(String, "sine", "square") var waveform = "sine" # load the GDNative script connected to the rust lib var Osc = preload("res://Osc.gdns") + # make an instance of our one "class" in rust lib var wave = Osc.new() @@ -20,10 +23,18 @@ func _fill_buffer() -> void: # playback stream buffer playback.push_buffer(wave.frames(freq, to_fill)) -func _process(_delta): - _fill_buffer() +func _process(delta): + if waveform == "square": + wave.square() + playback.clear_buffer() + else: + wave.sine() + playback.clear_buffer() + _fill_buffer() func _ready() -> void: + # buffer length of 100ms gives us ~realtime response to input changes + self.stream.buffer_length = 0.1 # ensure Godot/Sine have the same sample rate wave.set_sample_rate(self.stream.mix_rate) # get our AudioStreamPlayback object |