summaryrefslogtreecommitdiff
path: root/klangfarb/main.gd
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2021-11-07 00:37:27 -0500
committerGrant Shangreaux <grant@unabridgedsoftware.com>2021-11-07 00:37:27 -0500
commitef7fcf7a878143627af178a23d75e0301a40d677 (patch)
treebdf50a24e6c358a06cae6f8fe20025cceefa97a1 /klangfarb/main.gd
parent715f8440e68fea6a7cfcedd409053d0579523e14 (diff)
Feature: frequency modulation MVP implemented :loud-sound:
Diffstat (limited to 'klangfarb/main.gd')
-rw-r--r--klangfarb/main.gd36
1 files changed, 22 insertions, 14 deletions
diff --git a/klangfarb/main.gd b/klangfarb/main.gd
index 95c0f8f..4397a7e 100644
--- a/klangfarb/main.gd
+++ b/klangfarb/main.gd
@@ -18,11 +18,16 @@ export(float, 0.0, 1.0, 0.1) var sustain = 0.5
#Cutoff
export(float, 20, 8000, 5) var cutoff = 6000
+# Frequency Modulation
+export(bool) var frequency_modulation = false
+export(float, 0.0, 100.0, 0.1) var fm_frequency = 1.0
+export(float, 0.0, 10.0, 0.1) var fm_amplitude = 0.1
+
# load the GDNative script connected to the rust lib
var MonoSynth = preload("res://MonoSynth.gdns")
# make an instance of our one "class" in rust lib
-var wave = MonoSynth.new()
+var synth = MonoSynth.new()
# initialize the Godot stream we fill up with samples
var playback: AudioStreamPlayback = null
@@ -32,25 +37,28 @@ func _fill_buffer() -> void:
var to_fill = playback.get_frames_available()
if to_fill > 0:
# ask Rust to generate N frames at freq
- # Array<Vector2> gets pushed to the
+ # Array<Vector2> gets pushed to the
# playback stream buffer
- playback.push_buffer(wave.frames(to_fill))
+ playback.push_buffer(synth.frames(to_fill))
func _check_waveform():
if waveform == "square":
- wave.square()
+ synth.square()
elif waveform == "sine":
- wave.sine()
+ synth.sine()
elif waveform == "triangle":
- wave.triangle()
+ synth.triangle()
elif waveform == "sawtooth":
- wave.sawtooth()
+ synth.sawtooth()
func _process(_delta):
if self.is_playing():
- wave.apply_bend(apply_bend)
- wave.frequency(freq)
- wave.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_frequency)
+ synth.fm_depth(fm_amplitude)
_check_waveform()
_fill_buffer()
@@ -58,7 +66,7 @@ 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)
+ synth.set_sample_rate(self.stream.mix_rate)
# get our AudioStreamPlayback object
playback = self.get_stream_playback()
# prefill the stream's sample buffer (which feeds DAC)
@@ -70,6 +78,6 @@ func _input(event):
if event is InputEventMouseButton:
print("Mouse Click/Unclick at: ", event.position)
elif event is InputEventMouseMotion:
-# freq = event.position.x
- phasor_bend.x = event.position.x / 1024
- phasor_bend.y = event.position.y / 600
+ freq = event.position.x
+# phasor_bend.x = event.position.x / 1024
+# phasor_bend.y = event.position.y / 600