summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2021-11-07 20:44:12 -0600
committerGrant Shangreaux <grant@unabridgedsoftware.com>2021-11-07 20:44:12 -0600
commitbbaff2f4c5d379276034976503ce026dbd153132 (patch)
tree79f66b1ff367297ad430490a00fac1113c531f25
parentef7fcf7a878143627af178a23d75e0301a40d677 (diff)
Fix: frequency modulation implementation to be correct :|
-rw-r--r--klangfarb/main.gd9
-rw-r--r--klangfarbrs/src/lib.rs4
2 files changed, 7 insertions, 6 deletions
diff --git a/klangfarb/main.gd b/klangfarb/main.gd
index 4397a7e..9f4ffae 100644
--- a/klangfarb/main.gd
+++ b/klangfarb/main.gd
@@ -20,8 +20,8 @@ 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
+export(float, 0.0, 50.0, 0.1) var fm_multiplier = 1.0
+export(float, 0.0, 1000.0, 1.0) var fm_index = 1.0
# load the GDNative script connected to the rust lib
var MonoSynth = preload("res://MonoSynth.gdns")
@@ -57,8 +57,8 @@ func _process(_delta):
synth.frequency(freq)
synth.phasor_bend(phasor_bend)
synth.frequency_modulation(frequency_modulation)
- synth.fm_frequency(fm_frequency)
- synth.fm_depth(fm_amplitude)
+ synth.fm_frequency(fm_multiplier * freq)
+ synth.fm_depth(fm_index)
_check_waveform()
_fill_buffer()
@@ -81,3 +81,4 @@ func _input(event):
freq = event.position.x
# phasor_bend.x = event.position.x / 1024
# phasor_bend.y = event.position.y / 600
+ fm_multiplier = 600 / (event.position.y + 1)
diff --git a/klangfarbrs/src/lib.rs b/klangfarbrs/src/lib.rs
index 07e9cc7..fafb5c0 100644
--- a/klangfarbrs/src/lib.rs
+++ b/klangfarbrs/src/lib.rs
@@ -157,7 +157,7 @@ impl MonoSynth {
release: 0,
cutoff: 0.0,
frequency_modulation: false,
- fm_frequency: 30000.0,
+ fm_frequency: 10.0,
fm_depth: 0.1,
fm_phasor: Phasor { phase: 0.0 }
}
@@ -234,7 +234,7 @@ impl MonoSynth {
if self.frequency_modulation {
let modulation_value = Osc::generate_sample(&Waveform::Sine, self.fm_phasor.phase) * self.fm_depth;
self.fm_phasor.phase = self.fm_phasor.next_phase(self.fm_frequency, self.sample_rate);
- next_phase = self.phasor.next_phase(self.frequency * modulation_value, self.sample_rate);
+ next_phase = self.phasor.next_phase(self.frequency + modulation_value, self.sample_rate);
} else {
next_phase = self.phasor.next_phase(self.frequency, self.sample_rate);
}