diff options
author | Grant Shangreaux <grant@unabridgedsoftware.com> | 2021-11-09 20:51:04 -0600 |
---|---|---|
committer | Grant Shangreaux <grant@unabridgedsoftware.com> | 2021-11-09 20:51:40 -0600 |
commit | 2676bee57d6907a3a55ec6f0f8f6316692ef4a35 (patch) | |
tree | fa86929751f21ec8d4e1e31e2c1b8d312d33910f /klangfarbrs | |
parent | ab84f222a91fa6fa8453a7b91c86e43ab1938b20 (diff) |
Clean: move Osc into a file module
Diffstat (limited to 'klangfarbrs')
-rw-r--r-- | klangfarbrs/src/lib.rs | 38 | ||||
-rw-r--r-- | klangfarbrs/src/osc.rs | 37 |
2 files changed, 40 insertions, 35 deletions
diff --git a/klangfarbrs/src/lib.rs b/klangfarbrs/src/lib.rs index 2721e2f..a96393f 100644 --- a/klangfarbrs/src/lib.rs +++ b/klangfarbrs/src/lib.rs @@ -11,7 +11,9 @@ use gdnative::prelude::*; use gdnative::core_types::TypedArray; -use std::f32::consts::TAU; + +mod osc; +use osc::{Osc}; /// Aliasing some types to distinguish various audio properties. type Sample = f32; @@ -56,40 +58,6 @@ pub struct MonoSynth { fm_phasor: Phasor, } -pub struct Osc {} - -impl Osc { - pub fn generate_sample(waveform: &Waveform, phase: Phase) -> Sample { - let phase = phase; - - match waveform { - Waveform::Sine => { - (TAU * phase).sin() - }, - - Waveform::Square => { - if phase < 0.5 { - -1.0 - } else { - 1.0 - } - }, - - Waveform::Triangle => { - if phase < 0.5 { - 4.0 * phase - 1.0 - } else { - 4.0 * (1.0 - phase) - 1.0 - } - }, - - Waveform::Sawtooth => { - 2.0 * phase - 1.0 - } - } - } -} - pub struct Phasor { pub phase: Phase, } diff --git a/klangfarbrs/src/osc.rs b/klangfarbrs/src/osc.rs new file mode 100644 index 0000000..9e3b147 --- /dev/null +++ b/klangfarbrs/src/osc.rs @@ -0,0 +1,37 @@ +use std::f32::consts::TAU; +use crate::{Waveform, Phase, Sample}; + +pub struct Osc {} + +impl Osc { + pub fn generate_sample(waveform: &Waveform, phase: Phase) -> Sample { + let phase = phase; + + match waveform { + Waveform::Sine => { + (TAU * phase).sin() + }, + + Waveform::Square => { + if phase < 0.5 { + -1.0 + } else { + 1.0 + } + }, + + Waveform::Triangle => { + if phase < 0.5 { + 4.0 * phase - 1.0 + } else { + 4.0 * (1.0 - phase) - 1.0 + } + }, + + Waveform::Sawtooth => { + 2.0 * phase - 1.0 + } + } + } +} + |