From eda6270cdc302a1cca27f70d9b65cd8aff621882 Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Wed, 27 Oct 2021 13:07:56 -0500 Subject: Feature: working audio from rust into godot --- klangfarb/Main.gdns | 8 -------- klangfarb/MonoBuffer.gdns | 8 ++++++++ klangfarb/main.gd | 20 +++++++++++++++----- 3 files changed, 23 insertions(+), 13 deletions(-) delete mode 100644 klangfarb/Main.gdns create mode 100644 klangfarb/MonoBuffer.gdns (limited to 'klangfarb') diff --git a/klangfarb/Main.gdns b/klangfarb/Main.gdns deleted file mode 100644 index e551128..0000000 --- a/klangfarb/Main.gdns +++ /dev/null @@ -1,8 +0,0 @@ -[gd_resource type="NativeScript" load_steps=2 format=2] - -[ext_resource path="res://klangfarbrs.gdnlib" type="GDNativeLibrary" id=1] - -[resource] -resource_name = "MonoBuffer" -class_name = "MonoBuffer" -library = ExtResource( 1 ) diff --git a/klangfarb/MonoBuffer.gdns b/klangfarb/MonoBuffer.gdns new file mode 100644 index 0000000..e551128 --- /dev/null +++ b/klangfarb/MonoBuffer.gdns @@ -0,0 +1,8 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://klangfarbrs.gdnlib" type="GDNativeLibrary" id=1] + +[resource] +resource_name = "MonoBuffer" +class_name = "MonoBuffer" +library = ExtResource( 1 ) diff --git a/klangfarb/main.gd b/klangfarb/main.gd index 9032787..62137bc 100644 --- a/klangfarb/main.gd +++ b/klangfarb/main.gd @@ -1,9 +1,12 @@ tool extends AudioStreamPlayer -var playback: AudioStreamPlayback +var playback: AudioStreamPlayback = null + +var MonoBuffer = preload("res://MonoBuffer.gdns") +var buffer = MonoBuffer.new() +var samples = buffer.frames +var sample_count = samples.size() -var Buff = preload("res://Main.gdns") -var buff_node = Buff.new() func _create_generator() -> void: stream = AudioStreamGenerator.new() @@ -13,12 +16,19 @@ func _create_generator() -> void: func _fill_buffer() -> void: var to_fill = playback.get_frames_available() while to_fill > 0: - playback.push_frame(Vector2.ONE * buff_node.frames) # Audio frames are stereo. + var sample_index = to_fill % 512 + playback.push_frame(Vector2.ONE * samples[sample_index]) # Audio frames are stereo. # _phase = fmod(_phase + frequency() / GDawConfig.sample_rate, 1.0) # _update_state() to_fill -= 1 +func _process(delta): + _fill_buffer() func _ready() -> void: -# _update_envelope() _create_generator() + print(sample_count) + _fill_buffer() + self.play() +# _update_envelope() + -- cgit v1.2.3