diff options
-rw-r--r-- | klangfarb/SineWave.gdns (renamed from klangfarb/MonoBuffer.gdns) | 4 | ||||
-rwxr-xr-x | klangfarb/libklangfarbrs.so | bin | 20147240 -> 20146328 bytes | |||
-rw-r--r-- | klangfarb/main.gd | 4 | ||||
-rw-r--r-- | klangfarbrs/src/lib.rs | 14 |
4 files changed, 12 insertions, 10 deletions
diff --git a/klangfarb/MonoBuffer.gdns b/klangfarb/SineWave.gdns index e551128..e220a2e 100644 --- a/klangfarb/MonoBuffer.gdns +++ b/klangfarb/SineWave.gdns @@ -3,6 +3,6 @@ [ext_resource path="res://klangfarbrs.gdnlib" type="GDNativeLibrary" id=1] [resource] -resource_name = "MonoBuffer" -class_name = "MonoBuffer" +resource_name = "SineWave" +class_name = "SineWave" library = ExtResource( 1 ) diff --git a/klangfarb/libklangfarbrs.so b/klangfarb/libklangfarbrs.so Binary files differindex 280cd61..5dfe32e 100755 --- a/klangfarb/libklangfarbrs.so +++ b/klangfarb/libklangfarbrs.so diff --git a/klangfarb/main.gd b/klangfarb/main.gd index 806850d..568af36 100644 --- a/klangfarb/main.gd +++ b/klangfarb/main.gd @@ -1,8 +1,8 @@ extends AudioStreamPlayer var playback: AudioStreamPlayback = null -var MonoBuffer = preload("res://MonoBuffer.gdns") -var buffer = MonoBuffer.new() +var SineWave = preload("res://SineWave.gdns") +var buffer = SineWave.new() var duration = 3 var samples = buffer.frames(440.0, 44100.0, duration) var sample_count = samples.size() 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::<MonoBuffer>(); + // Register the `Sine` type we declared. + handle.add_class::<SineWave>(); } // Macro that creates the entry-points of the dynamic library. |