Closed DinoMC closed 1 month ago
Hi there @DinoMC what godot version did you use to test this?
Pretty sure this was 4.2.2 stable. Just tried again with 4.3.beta3 and the issue is still there.
Looking at the code, it seems to me like it's not implemented, so issue should be the same in all Godot versions :
Audio menu calls AppSettings.set_bus_volume_from_linear which just take the slider's value and set the bus volume to that, completely ignoring the default bus value (AudioServer.get_bus_volume_db() is never used)
Strangely, when starting the game, AppSettings.set_audio_from_config does get the default bus volume with AudioServer.get_bus_volume_db() ... and then discard it after having done nothing with it.
Actually looking into this, I just realized there's another (bigger?) bug. If you have any Audio Bus set to a volume that's above 0db and start the game, AppConfig will immediately set it back to 0db, so it's impossible to have any volume above 0db as long as you have Maaack Menus Template installed. Even if you skip the main menu altogether (since it's the autoload that does it).
This part is due to AppSettings.set_audio_from_config(), if the bus doesn't have a value saved in the config file (ie. the slider was never moved in option menu), then bus_volume = 1.0 (0.0db), at line 115 in AppSettings.gd
bus_volume = Config.get_config(AUDIO_SECTION, bus_name, bus_volume)
if is_nan(bus_volume):
bus_volume = 1.0
Config.set_config(AUDIO_SECTION, bus_name, bus_volume)
bus_volume_db = linear_to_db(bus_volume)
AudioServer.set_bus_volume_db(bus_iter, bus_volume_db)
I was trying to make a pull request to fix this but I'm not sure how to go about a specific part, so instead here's some code, I hope it can help you.
For AppSettings.set_audio_from_config(), I think it can be fixed like this. I tried running a few test cases and it all seemed to work :
static func set_audio_from_config():
for bus_iter in AudioServer.bus_count:
var bus_name : String = AudioServer.get_bus_name(bus_iter).to_pascal_case()
var bus_volume_db : float = AudioServer.get_bus_volume_db(bus_iter)
var base_bus_volume : float = db_to_linear(bus_volume_db)
var bus_volume : float
bus_volume = Config.get_config(AUDIO_SECTION, bus_name, bus_volume)
if is_nan(bus_volume):
bus_volume = 1.0
Config.set_config(AUDIO_SECTION, bus_name, bus_volume)
bus_volume_db = linear_to_db(base_bus_volume * bus_volume)
AudioServer.set_bus_volume_db(bus_iter, bus_volume_db)
var mute_audio_flag : bool = is_muted()
mute_audio_flag = Config.get_config(AUDIO_SECTION, MUTE_SETTING, mute_audio_flag)
set_mute(mute_audio_flag)
Basically, multiply the new value by the default value (works well since it's linear values). So if the user set the slider to 80%, but the bus default value is already 0.8, then the final value will be 0.64.
Problem is once the config is done loading, it seems like the bus default volume is just gone, it's not saved anywhere. So when the user then move the slider again in the Audio menu, you don't have anything to multiply it with.
Possible fixes :
Do some maths. Change the "slider change" signal to send both the old and new value, so if the user change the slider from 0.8 to 0.6 in the above option, you can the current volume of 0.64, divide it by 0.8, multiply by 0.6 and end up with the expected final volume of 0.48 Issues : Rounding errors, and I don't know if the slider can actually send the old value.
Something else I tried is, when the setting is changed, I load the default values back and then apply the new volume. It's possible to set all bus to their default volume by running :
if ResourceLoader.exists(ProjectSettings.get_setting("audio/buses/default_bus_layout")):
AudioServer.set_bus_layout(load(ProjectSettings.get_setting("audio/buses/default_bus_layout")))
Problem being, it sets ALL buses to default and it doesn't seem like that can be changed. So when one slider change, you would have to loop through all buses and reapply the corresponding option.
On project run, save all default bus values somewhere so that you can use them on slider change. Pretty easy to do, but I don't know where I should store that array in the addon's structure so I refrained. (AppSettings doesn't use any var)
Vaguely related, but I would also suggest another small change. Right now, when starting the game for the first time, all sliders are at 100%, meaning that the user can lower the volume if the default is too high, but can't raise it if it's too low. This could be easily fixed by changing the HSlider.max_value to 1.5 rather than 1.0
Thanks for the detailed bug report and suggested fix! I'll try working on it this week.
Hi, I think I found a bug with the way volume is handled. Once you touch the slider for a bus in the Audio Options menu, the default value for the bus seems to be erased :
Go in the Audio tab (bottom) in Godot Editor, change bus volume slider (eg. -10 db)
Start the game, go to Options -> Audio and lower that bus volume a bit.
Volume doesn't change as expected (in -10db example, it instead goes up a lot.) I assume it's being reset to 0db, and then lowered by whatever amount you set in the option menu.
If you exit and start the game again, the volume will still be at 0db as the setting is saved, there's no way to "reset" it.
Instead I think 100% volume (in audio option) should be the value set in the Editor, and then go down from that if lowered. Edit : Or convert the bus default volume to a % and set the slider to start at that % rather than 100%, so that when you move it the volume doesn't suddenly jump. Not sure if that'd work for default volume above 0db tho. Would require lowering all other sliders and raising the "overall" volume to compensate, not sure if there's a function for that.