summaryrefslogtreecommitdiff
path: root/klangfarbrs/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'klangfarbrs/src/lib.rs')
-rw-r--r--klangfarbrs/src/lib.rs38
1 files changed, 3 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,
}