From 223f36ffdd5d78d7b968bece99b9eaa298ed6119 Mon Sep 17 00:00:00 2001 From: hpham474 Date: Sun, 14 Nov 2021 00:30:18 -0600 Subject: [PATCH] Sounds no longer scale linearly --- godot_ship/scenes/AudioController.tscn | 3 +++ godot_ship/scenes/Options.tscn | 15 ++++++--------- godot_ship/script/options/Options.gd | 9 ++++++--- godot_ship/script/options/OptionsController.gd | 8 ++++---- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/godot_ship/scenes/AudioController.tscn b/godot_ship/scenes/AudioController.tscn index c4112e2..d130143 100644 --- a/godot_ship/scenes/AudioController.tscn +++ b/godot_ship/scenes/AudioController.tscn @@ -26,12 +26,15 @@ bus = "SFX" [node name="shipHitSFX" type="AudioStreamPlayer" parent="."] stream = ExtResource( 4 ) +volume_db = -10.0 bus = "SFX" [node name="shipMissedSFX" type="AudioStreamPlayer" parent="."] stream = ExtResource( 5 ) +volume_db = -5.0 bus = "SFX" [node name="shipSunkSFX" type="AudioStreamPlayer" parent="."] stream = ExtResource( 6 ) +volume_db = -10.0 bus = "SFX" diff --git a/godot_ship/scenes/Options.tscn b/godot_ship/scenes/Options.tscn index 2b22f13..2ed6077 100644 --- a/godot_ship/scenes/Options.tscn +++ b/godot_ship/scenes/Options.tscn @@ -58,10 +58,9 @@ focus_neighbour_top = NodePath("../../../Back") focus_neighbour_bottom = NodePath("../../Volume Setting/Volume Slider") focus_next = NodePath("../../Volume Setting/Volume Slider") focus_previous = NodePath("../../../Back") -min_value = -25.0 -max_value = 0.0 +max_value = 1.0 +step = 0.05 tick_count = 10 -ticks_on_borders = true __meta__ = { "_edit_use_anchors_": false } @@ -90,10 +89,9 @@ focus_neighbour_top = NodePath("../../SFX Setting/SFX Slider") focus_neighbour_bottom = NodePath("../../../Buttons/Dark") focus_next = NodePath("../../../Buttons/Dark") focus_previous = NodePath("../../SFX Setting/SFX Slider") -min_value = -50.0 -max_value = 0.0 +max_value = 1.0 +step = 0.05 tick_count = 10 -ticks_on_borders = true __meta__ = { "_edit_use_anchors_": false } @@ -117,10 +115,9 @@ margin_left = 64.0 margin_top = 48.0 margin_right = 208.0 margin_bottom = 64.0 -min_value = -50.0 -max_value = 0.0 +max_value = 1.0 +step = 0.05 tick_count = 10 -ticks_on_borders = true __meta__ = { "_edit_use_anchors_": false } diff --git a/godot_ship/script/options/Options.gd b/godot_ship/script/options/Options.gd index 09e1bf9..d4e927b 100644 --- a/godot_ship/script/options/Options.gd +++ b/godot_ship/script/options/Options.gd @@ -10,9 +10,9 @@ onready var theme_buttons = find_node("Buttons", true, true).get_children() func _ready(): OptionsController.load_options() find_next_valid_focus().grab_focus() - master_slider.value = OptionsController.get_mas_volume() - music_slider.value = OptionsController.get_mus_volume() - sound_slider.value = OptionsController.get_sfx_volume() + master_slider.value = db2linear(OptionsController.get_mas_volume()) + music_slider.value = db2linear(OptionsController.get_mus_volume()) + sound_slider.value = db2linear(OptionsController.get_sfx_volume()) func _on_Button_pressed(): AudioBus.emit_signal("button_clicked") @@ -20,14 +20,17 @@ func _on_Button_pressed(): #MessageBus.emit_signal("change_scene", "Title") func _on_Master_Slider_value_changed(value): + value = linear2db(value) AudioBus.emit_signal("button_clicked") OptionsController.set_vol(value, "mas_vol") func _on_Music_Slider_value_changed(value): + value = linear2db(value) AudioBus.emit_signal("button_clicked") OptionsController.set_vol(value, "mus_vol") func _on_SFX_Slider_value_changed(value): + value = linear2db(value) AudioBus.emit_signal("button_clicked") OptionsController.set_vol(value, "sfx_vol") diff --git a/godot_ship/script/options/OptionsController.gd b/godot_ship/script/options/OptionsController.gd index a9fd620..eaefae4 100644 --- a/godot_ship/script/options/OptionsController.gd +++ b/godot_ship/script/options/OptionsController.gd @@ -8,9 +8,9 @@ signal change_theme (theme) var f = File.new() var options_file = "user://options.save" var theme = "dark" -var mas_vol = 0 -var mus_vol = 0 -var sfx_vol = 0 +var mas_vol = linear2db(1) +var mus_vol = linear2db(1) +var sfx_vol = linear2db(1) func _ready(): load_options() @@ -62,7 +62,7 @@ func load_options(): mus_vol = f.get_var() sfx_vol = f.get_var() f.close() - AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), mus_vol) + AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), mas_vol) AudioServer.set_bus_volume_db(AudioServer.get_bus_index("BGM"), mus_vol) AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SFX"), sfx_vol)