From 4565611763cbb041384230580f9c7de4fea7da6f Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Sat, 30 Oct 2021 23:56:38 -0500 Subject: Add: square wave and waveform switch interface in godot --- klangfarb/main.gd | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'klangfarb') 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 -- cgit v1.2.3