diff options
author | Grant Shangreaux <grant@unabridgedsoftware.com> | 2021-10-30 23:56:38 -0500 |
---|---|---|
committer | Grant Shangreaux <grant@unabridgedsoftware.com> | 2021-10-30 23:56:38 -0500 |
commit | 4565611763cbb041384230580f9c7de4fea7da6f (patch) | |
tree | 9d983f4da2dc60a578379958eda028242412ae71 /klangfarbrs/src | |
parent | b9559897c05b8c2f67e34372685952d586af5c3d (diff) |
Add: square wave and waveform switch interface in godot
Diffstat (limited to 'klangfarbrs/src')
-rw-r--r-- | klangfarbrs/src/lib.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/klangfarbrs/src/lib.rs b/klangfarbrs/src/lib.rs index a418995..7954eb2 100644 --- a/klangfarbrs/src/lib.rs +++ b/klangfarbrs/src/lib.rs @@ -23,9 +23,9 @@ pub struct Osc { } /// The various waveforms the `Osc` can generate. -enum Waveform { +pub enum Waveform { Sine, - // Square, + Square, // Triangle, // Saw, // Noise, @@ -36,6 +36,13 @@ fn generate_sample(osc: &Osc) -> f32 { match osc.waveform { Waveform::Sine => { (TAU * osc.phase).sin() + }, + Waveform::Square => { + if osc.phase < 0.5 { + -1.0 + } else { + 1.0 + } } } } @@ -79,6 +86,16 @@ impl Osc { } #[export] + fn sine(&mut self, _owner: &Node) { + self.waveform = Waveform::Sine + } + + #[export] + fn square(&mut self, _owner: &Node) { + self.waveform = Waveform::Square + } + + #[export] pub fn set_sample_rate(&mut self, _owner: &Node, sample_rate: f32) { self.sample_rate = sample_rate; } |