From 2676bee57d6907a3a55ec6f0f8f6316692ef4a35 Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Tue, 9 Nov 2021 20:51:04 -0600 Subject: Clean: move Osc into a file module --- klangfarbrs/src/lib.rs | 38 +++----------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) (limited to 'klangfarbrs/src/lib.rs') 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, } -- cgit v1.2.3