changes to sound mixing

This commit is contained in:
betalars 2023-03-03 13:07:55 +01:00
parent f2a6cc5975
commit 3a93b4fb2a
3 changed files with 46 additions and 41 deletions

View file

@ -2,11 +2,11 @@ tool
extends Node extends Node
enum themes{ enum themes{
NONE, NONE,
BASE, BASE,
THEME_1, THEME_1,
THEME_2, THEME_2,
THEME_3, THEME_3,
} }
export (themes) var current_theme: int = themes.BASE setget set_theme export (themes) var current_theme: int = themes.BASE setget set_theme
@ -18,41 +18,41 @@ var transition_state:float = 1
var max_volume = 0.5 var max_volume = 0.5
func _ready(): func _ready():
for i in range(themes.size()): for i in range(themes.size()):
if i > 0: if i > 0:
AudioServer.set_bus_volume_db(i, linear2db(0)) AudioServer.set_bus_volume_db(i, linear2db(0))
AudioServer.set_bus_mute(i, true) AudioServer.set_bus_mute(i, true)
if not current_theme == 0: if not current_theme == 0:
AudioServer.set_bus_volume_db(current_theme, linear2db(max_volume)) AudioServer.set_bus_volume_db(current_theme, linear2db(max_volume))
AudioServer.set_bus_mute(current_theme, false) AudioServer.set_bus_mute(current_theme, false)
if autoplay and not playing: if autoplay and not playing:
set_playing(true) set_playing(true)
func _process(delta): func _process(delta):
if last_theme != -1: if last_theme != -1:
transition_state += delta/transition_time transition_state += delta/transition_time
if transition_state > 1: if transition_state > 1:
transition_state = 1 transition_state = 1
if not last_theme == 0: AudioServer.set_bus_mute(last_theme, true) if not last_theme == 0: AudioServer.set_bus_mute(last_theme, true)
last_theme = -1 last_theme = -1
if not current_theme == 0: AudioServer.set_bus_volume_db(current_theme, linear2db(transition_state*max_volume)) if not current_theme == 0: AudioServer.set_bus_volume_db(current_theme, linear2db(transition_state*max_volume))
if not last_theme == 0: AudioServer.set_bus_volume_db(last_theme, linear2db((1-transition_state)*max_volume)) if not last_theme == 0: AudioServer.set_bus_volume_db(last_theme, linear2db((1-transition_state)*max_volume))
func set_theme(new_theme): func set_theme(new_theme):
if last_theme == -1: if last_theme == -1:
last_theme = current_theme last_theme = current_theme
current_theme = new_theme current_theme = new_theme
AudioServer.set_bus_mute(new_theme, false) AudioServer.set_bus_mute(new_theme, false)
transition_state = 0 transition_state = 0
func set_playing(play_input): func set_playing(play_input):
if is_inside_tree(): if is_inside_tree():
$Base.playing = play_input $Base.playing = play_input
$Theme1.playing = play_input $Theme1.playing = play_input
$Theme2.playing = play_input $Theme2.playing = play_input
$Theme3.playing = play_input $Theme3.playing = play_input
playing = play_input playing = play_input
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.

View file

@ -515,7 +515,6 @@ unit_size = 10.0
[node name="theme switcher" type="Node" parent="."] [node name="theme switcher" type="Node" parent="."]
script = ExtResource( 5 ) script = ExtResource( 5 )
current_theme = 2
[node name="Base" type="AudioStreamPlayer" parent="theme switcher"] [node name="Base" type="AudioStreamPlayer" parent="theme switcher"]
stream = ExtResource( 8 ) stream = ExtResource( 8 )

View file

@ -3,15 +3,15 @@
[resource] [resource]
bus/1/name = "base" bus/1/name = "base"
bus/1/solo = false bus/1/solo = false
bus/1/mute = true bus/1/mute = false
bus/1/bypass_fx = false bus/1/bypass_fx = false
bus/1/volume_db = -67.9895 bus/1/volume_db = -6.0206
bus/1/send = "Master" bus/1/send = "Master"
bus/2/name = "theme 1" bus/2/name = "theme 1"
bus/2/solo = false bus/2/solo = false
bus/2/mute = false bus/2/mute = true
bus/2/bypass_fx = false bus/2/bypass_fx = false
bus/2/volume_db = -6.0206 bus/2/volume_db = inf_neg
bus/2/send = "Master" bus/2/send = "Master"
bus/3/name = "theme 2" bus/3/name = "theme 2"
bus/3/solo = false bus/3/solo = false
@ -25,9 +25,15 @@ bus/4/mute = true
bus/4/bypass_fx = false bus/4/bypass_fx = false
bus/4/volume_db = inf_neg bus/4/volume_db = inf_neg
bus/4/send = "Master" bus/4/send = "Master"
bus/5/name = "gewitter" bus/5/name = "inside"
bus/5/solo = false bus/5/solo = false
bus/5/mute = false bus/5/mute = false
bus/5/bypass_fx = false bus/5/bypass_fx = false
bus/5/volume_db = -6.57885 bus/5/volume_db = -2.71024
bus/5/send = "Master" bus/5/send = "Master"
bus/6/name = "outside"
bus/6/solo = false
bus/6/mute = false
bus/6/bypass_fx = false
bus/6/volume_db = 0.0
bus/6/send = "Master"