From ffacb1c96b02507f1bdd612bd71b6bcc7d114505 Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Wed, 27 Oct 2021 22:46:58 -0400 Subject: Clean up --- klangfarbrs/src/lib.rs | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'klangfarbrs/src/lib.rs') diff --git a/klangfarbrs/src/lib.rs b/klangfarbrs/src/lib.rs index 9638690..fd67e21 100644 --- a/klangfarbrs/src/lib.rs +++ b/klangfarbrs/src/lib.rs @@ -4,34 +4,30 @@ use gdnative::core_types::TypedArray; #[derive(NativeClass)] #[inherit(Node)] -pub struct MonoBuffer { - #[property] - frames: TypedArray -} - -pub fn fill_frames() -> TypedArray { - let frequency = 440.0; - let sample_rate = 44100.0; - let duration = sample_rate * 3.0; - let mut frames = TypedArray::new(); - - for i in 0..duration as i32 { - frames.push(f32::sin(std::f32::consts::TAU * frequency * i as f32/sample_rate)); - } - - return frames -} +pub struct MonoBuffer {} #[methods] impl MonoBuffer { fn new(_owner: &Node) -> Self { - MonoBuffer { frames: fill_frames() } + MonoBuffer {} } #[export] fn _ready(&self, _owner: &Node) { godot_print!("Whatever, connected.") } + + #[export] + pub fn frames(&self, _owner: &Node, frequency: f32, sample_rate: f32, duration: i32) -> TypedArray { + let mut frames = TypedArray::new(); + let calculated_duration = sample_rate * duration as f32; + + for i in 0..calculated_duration as i32 { + frames.push(f32::sin(std::f32::consts::TAU * frequency * i as f32/sample_rate)); + } + + return frames + } } // Function that registers all exposed classes to Godot -- cgit v1.2.3