summaryrefslogtreecommitdiff
path: root/klangfarb
diff options
context:
space:
mode:
authorJacob Lee <jacob@unabridgedsoftware.com>2021-12-04 10:55:23 -0500
committerJacob Lee <jacob@unabridgedsoftware.com>2021-12-04 10:55:23 -0500
commite91c02971c08a180a3b1dc3dee9a0b035a79fa95 (patch)
tree1c1788be9942b72b89a401d7702a1e82badb0a18 /klangfarb
parentb73dde8aa4a5701eb05a5232d907f008dc8f6b00 (diff)
Add oscillator back and allow toggling between instrument and waveform in Godot interface. Still need to work on how we're playing the instrument.
Diffstat (limited to 'klangfarb')
-rw-r--r--klangfarb/Main.tscn1
-rw-r--r--klangfarb/main.gd43
2 files changed, 24 insertions, 20 deletions
diff --git a/klangfarb/Main.tscn b/klangfarb/Main.tscn
index 7b547cd..4d3e135 100644
--- a/klangfarb/Main.tscn
+++ b/klangfarb/Main.tscn
@@ -8,5 +8,6 @@
stream = SubResource( 1 )
volume_db = -13.216
script = ExtResource( 2 )
+play_instrument = true
continuous = false
fm_index = 100.0
diff --git a/klangfarb/main.gd b/klangfarb/main.gd
index 590d45b..433342e 100644
--- a/klangfarb/main.gd
+++ b/klangfarb/main.gd
@@ -4,6 +4,8 @@ extends AudioStreamPlayer
export(String, "sine", "square", "triangle", "sawtooth", "white_noise", "brown_noise") var waveform = "sine"
# controllable frequency interface
export(float, 20, 8000, 5) var freq = 440.0
+# toggle between playing a waveform or an instrument
+export(bool) var play_instrument = false
# bending the waveform
export(bool) var apply_bend = false
export(Vector2) var phasor_bend = Vector2(0.5, 0.5)
@@ -41,34 +43,35 @@ func _fill_buffer() -> void:
# playback stream buffer
playback.push_buffer(synth.frames(to_fill))
-#func _check_waveform():
- #if waveform == "square":
- #synth.square()
- #elif waveform == "sine":
- #synth.sine()
- #elif waveform == "triangle":
- #synth.triangle()
- #elif waveform == "sawtooth":
- #synth.sawtooth()
- #elif waveform == "white_noise":
- #synth.white_noise()
- #elif waveform == "brown_noise":
- #synth.brown_noise()
+func _check_waveform():
+ if waveform == "square":
+ synth.square()
+ elif waveform == "sine":
+ synth.sine()
+ elif waveform == "triangle":
+ synth.triangle()
+ elif waveform == "sawtooth":
+ synth.sawtooth()
+ elif waveform == "white_noise":
+ synth.white_noise()
+ elif waveform == "brown_noise":
+ synth.brown_noise()
func _process(_delta):
if self.is_playing():
-# synth.apply_bend(apply_bend)
-# synth.frequency(freq)
-# synth.phasor_bend(phasor_bend)
+ synth.apply_bend(apply_bend)
+ synth.frequency(freq)
+ synth.phasor_bend(phasor_bend)
synth.frequency_modulation(frequency_modulation)
-# synth.fm_frequency(fm_multiplier * freq)
+ synth.fm_frequency(fm_multiplier * freq)
synth.fm_depth(fm_index)
synth.continuous(continuous)
synth.set_attack(attack)
synth.set_decay(decay)
synth.set_sustain(sustain)
synth.set_release(release)
- # _check_waveform()
+ synth.play_instrument(play_instrument)
+ _check_waveform()
_fill_buffer()
func _ready() -> void:
@@ -79,7 +82,7 @@ func _ready() -> void:
# get our AudioStreamPlayback object
playback = self.get_stream_playback()
# prefill the stream's sample buffer (which feeds DAC)
- #_check_waveform()
+ _check_waveform()
_fill_buffer()
func _input(event):
@@ -89,7 +92,7 @@ func _input(event):
synth.trigger()
elif event is InputEventMouseMotion:
freq = event.position.x
- # synth.frequency(freq)
+ synth.frequency(freq)
# phasor_bend.x = event.position.x / 1024
# phasor_bend.y = event.position.y / 600
fm_multiplier = 600 / (event.position.y + 1)