From 0db43948f5c1b2f66c81577c37807bc80de8f922 Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Thu, 28 Oct 2021 08:54:01 -0400 Subject: Rename MonoBuffer to SineWave and clean up rust code a little bit --- klangfarbrs/src/lib.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'klangfarbrs/src') diff --git a/klangfarbrs/src/lib.rs b/klangfarbrs/src/lib.rs index fd67e21..b0267be 100644 --- a/klangfarbrs/src/lib.rs +++ b/klangfarbrs/src/lib.rs @@ -1,15 +1,17 @@ // use gdnative::api::Resource; use gdnative::prelude::*; use gdnative::core_types::TypedArray; +use std::f32; +use std::f32::consts::TAU; #[derive(NativeClass)] #[inherit(Node)] -pub struct MonoBuffer {} +pub struct SineWave {} #[methods] -impl MonoBuffer { +impl SineWave { fn new(_owner: &Node) -> Self { - MonoBuffer {} + SineWave {} } #[export] @@ -23,7 +25,7 @@ impl MonoBuffer { 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)); + frames.push((TAU * frequency * i as f32/sample_rate).sin()); } return frames @@ -32,8 +34,8 @@ impl MonoBuffer { // Function that registers all exposed classes to Godot fn init(handle: InitHandle) { - // Register the `MonoBuffer` type we declared. - handle.add_class::(); + // Register the `Sine` type we declared. + handle.add_class::(); } // Macro that creates the entry-points of the dynamic library. -- cgit v1.2.3