diff --git a/test/audio_renderer.gd b/scripts/audio_renderer.gd similarity index 99% rename from test/audio_renderer.gd rename to scripts/audio_renderer.gd index ddbfce4..373bee5 100644 --- a/test/audio_renderer.gd +++ b/scripts/audio_renderer.gd @@ -23,6 +23,8 @@ onready var waiting_for_viewport: Array = [] onready var done_first_draw: bool = false func _ready() -> void: + self.material = ShaderMaterial.new() + self.material.shader = preload('res://shaders/audio_renderer.gdshader') match self.render_mode: RENDER_MODE.BATCH, RENDER_MODE.DYNAMIC: self._update_viewport(4096, 4096) diff --git a/scripts/loaders/SoundLoader.gd b/scripts/loaders/SoundLoader.gd index 08f4187..4222cd9 100644 --- a/scripts/loaders/SoundLoader.gd +++ b/scripts/loaders/SoundLoader.gd @@ -45,6 +45,10 @@ var instrument_samples = [] var instrument_samples_HACK_EXTENDED_LOOPS = [] var sfx_samples = [] +var audio_renderer_viewport: Viewport +var audio_renderer: Node + + func read_rom_address(buffer: StreamPeerBuffer) -> int: # Read a 3-byte little-endian address and wrap the bank to ROM space return buffer.get_u16() + ((buffer.get_u8() & 0x3F) << 16) @@ -274,4 +278,18 @@ func parse_rom(snes_data: Dictionary, buffer: StreamPeerBuffer): emit_signal('audio_samples_loaded') func _ready() -> void: - add_child(player) + self.player.name = 'player' # Easier to see in the debugger + add_child(self.player) + audio_renderer_viewport = Viewport.new() + audio_renderer_viewport.name = 'audio_renderer_viewport' + audio_renderer_viewport.size_override_stretch = true + audio_renderer_viewport.transparent_bg = true + audio_renderer_viewport.handle_input_locally = false + audio_renderer_viewport.hdr = false + audio_renderer_viewport.render_target_update_mode = Viewport.UPDATE_ALWAYS + # add_child(self.audio_renderer_viewport) + + audio_renderer = preload('res://scripts/audio_renderer.gd').new() + audio_renderer.name = 'audio_renderer' + audio_renderer_viewport.add_child(audio_renderer) + get_parent().call_deferred('add_child', audio_renderer_viewport) diff --git a/test/audio_system.gd b/test/audio_system.gd index 7be3138..c953064 100644 --- a/test/audio_system.gd +++ b/test/audio_system.gd @@ -5,7 +5,7 @@ const MusicPlayer := preload('res://scripts/MusicPlayer.gd') const MusicRenderer := preload('res://scripts/MusicRenderer.gd') var MusicLoader := preload('res://scripts/loaders/snes/music_ff5.gd').new() onready var bgm_titles := Common.load_glyph_table('res://data/5/bgm_titles.txt') -onready var audio_renderer := $'%audio_renderer' +onready var audio_renderer: Node = SoundLoader.audio_renderer onready var audio_player := $audio_player var prerendered_bgms := {} var prerendered_bgm_start_and_end_loops := {} diff --git a/test/audio_system.tscn b/test/audio_system.tscn index 1388965..683f03f 100644 --- a/test/audio_system.tscn +++ b/test/audio_system.tscn @@ -1,37 +1,10 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=2 format=2] [ext_resource path="res://test/audio_system.gd" type="Script" id=1] -[ext_resource path="res://test/audio_renderer.gd" type="Script" id=3] -[ext_resource path="res://shaders/audio_renderer.gdshader" type="Shader" id=4] - -[sub_resource type="ShaderMaterial" id=2] -shader = ExtResource( 4 ) -shader_param/instrument_samples_size = Vector2( 2048, 128 ) -shader_param/INT_OUTPUT_WIDTH = 4096 -shader_param/OUTPUT_FRAMEBUFFER_SIZE = Vector2( 4096, 4096 ) -shader_param/reference_note = 71.0 -shader_param/output_mixrate = 32000.0 -shader_param/midi_events_size = Vector2( 2048, 16 ) -shader_param/tempo_scale_thousandths = 1000 [node name="audio_system" type="Node2D"] script = ExtResource( 1 ) -[node name="viewport_audio_renderer" type="Viewport" parent="."] -size = Vector2( 4096, 4096 ) -size_override_stretch = true -transparent_bg = true -handle_input_locally = false -hdr = false -render_target_update_mode = 3 - -[node name="audio_renderer" type="Control" parent="viewport_audio_renderer"] -unique_name_in_owner = true -material = SubResource( 2 ) -margin_right = 40.0 -margin_bottom = 40.0 -script = ExtResource( 3 ) - [node name="inst_buttons" type="ReferenceRect" parent="."] margin_right = 384.0 margin_bottom = 118.0