summaryrefslogtreecommitdiff
path: root/klangfarb
diff options
context:
space:
mode:
Diffstat (limited to 'klangfarb')
-rw-r--r--klangfarb/main.gd17
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