diff options
author | Jacob Lee <jacob@unabridgedsoftware.com> | 2021-10-27 22:46:58 -0400 |
---|---|---|
committer | Jacob Lee <jacob@unabridgedsoftware.com> | 2021-10-27 22:46:58 -0400 |
commit | ffacb1c96b02507f1bdd612bd71b6bcc7d114505 (patch) | |
tree | b79a7b9f4a9afe4f1a9cf4d3e2f0d853bf14f5d9 /klangfarbrs/src/lib.rs | |
parent | 7bd9dd418ac6215094feb87087fcb59499c3aa69 (diff) |
Clean up
Diffstat (limited to 'klangfarbrs/src/lib.rs')
-rw-r--r-- | klangfarbrs/src/lib.rs | 32 |
1 files changed, 14 insertions, 18 deletions
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<f32> -} - -pub fn fill_frames() -> TypedArray<f32> { - 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<f32> { + 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 |