From 12135f5a67f9d01f652786344b985ce71749ee72 Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Wed, 27 Oct 2021 10:03:37 -0500 Subject: Add: main.gd script that loads the MonoBuffer gdns --- klangfarb/Main.tscn | 8 ++++---- klangfarb/main.gd | 31 +++++++++++++++++++------------ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/klangfarb/Main.tscn b/klangfarb/Main.tscn index 9c58bfd..0a0ad3b 100644 --- a/klangfarb/Main.tscn +++ b/klangfarb/Main.tscn @@ -1,10 +1,10 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://Main.gdns" type="Script" id=1] [ext_resource path="res://main.gd" type="Script" id=2] -[node name="Node" type="Node"] -script = ExtResource( 1 ) +[sub_resource type="AudioStreamGenerator" id=1] +mix_rate = 8000.0 -[node name="Node" type="Node" parent="."] +[node name="Audio" type="AudioStreamPlayer"] +stream = SubResource( 1 ) script = ExtResource( 2 ) diff --git a/klangfarb/main.gd b/klangfarb/main.gd index 96d8cb5..9032787 100644 --- a/klangfarb/main.gd +++ b/klangfarb/main.gd @@ -1,17 +1,24 @@ -extends Node +tool +extends AudioStreamPlayer +var playback: AudioStreamPlayback -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" -onready var data = preload("res://klangfarbrs.gdnlib") -# var buffer = MonoBuffer.new() +var Buff = preload("res://Main.gdns") +var buff_node = Buff.new() -# Called when the node enters the scene tree for the first time. -func _ready(): - print("Poop", data.frames()); +func _create_generator() -> void: + stream = AudioStreamGenerator.new() + stream.mix_rate = 8000.0 # Setting mix rate is only possible before play(). + playback = get_stream_playback() +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. +# _phase = fmod(_phase + frequency() / GDawConfig.sample_rate, 1.0) +# _update_state() + to_fill -= 1 -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass +func _ready() -> void: +# _update_envelope() + _create_generator() -- cgit v1.2.3