Giter Club home page Giter Club logo

Comments (4)

cmr624 avatar cmr624 commented on August 12, 2024

Hi there @DinoMC what godot version did you use to test this?

from godot-game-template.

DinoMC avatar DinoMC commented on August 12, 2024

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)

from godot-game-template.

DinoMC avatar DinoMC commented on August 12, 2024

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

from godot-game-template.

Maaack avatar Maaack commented on August 12, 2024

Thanks for the detailed bug report and suggested fix! I'll try working on it this week.

from godot-game-template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.