summaryrefslogtreecommitdiff
path: root/klangfarbrs/src
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2021-10-26 16:45:01 -0500
committerGrant Shangreaux <grant@unabridgedsoftware.com>2021-10-26 16:45:01 -0500
commit90b491bb0d4ca6ae88495e7fb3f9b936598d83e1 (patch)
tree63e6cbe20a803d800b72e307a164ed7b47b11ca1 /klangfarbrs/src
parent720ec920852a4d124fe004edae314ae14364a98c (diff)
Add: TypedArray for godot buffer frames property
Diffstat (limited to 'klangfarbrs/src')
-rw-r--r--klangfarbrs/src/lib.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/klangfarbrs/src/lib.rs b/klangfarbrs/src/lib.rs
index 1a43aba..9bf1ded 100644
--- a/klangfarbrs/src/lib.rs
+++ b/klangfarbrs/src/lib.rs
@@ -1,20 +1,22 @@
// use gdnative::api::Resource;
use gdnative::prelude::*;
+use gdnative::core_types::TypedArray;
#[derive(NativeClass)]
#[inherit(Node)]
pub struct MonoBuffer {
- frames: [f32; 512]
+ #[property]
+ frames: TypedArray<f32>
}
-pub fn fill_frames() -> [f32; 512] {
+pub fn fill_frames() -> TypedArray<f32> {
let tau = std::f32::consts::FRAC_PI_2;
let frequency = 440.0;
let sample_rate = 8000.0;
- let mut frames = [0.0; 512];
+ let mut frames = TypedArray::new();
for i in 0..512 {
- frames[i] = f32::sin(tau * frequency * i as f32/sample_rate);
+ frames.push(f32::sin(tau * frequency * i as f32/sample_rate));
}
return frames
@@ -26,10 +28,6 @@ impl MonoBuffer {
MonoBuffer { frames: fill_frames() }
}
- fn frames(&self) -> [f32; 512] {
- return self.frames;
- }
-
#[export]
fn _ready(&self, _owner: &Node) {
godot_print!("Whatever, connected.")