-
-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add volume_linear
property and getter/setter methods for audio-related classes
#99268
Conversation
I want to note, So my question is, do users need this commonly enough? |
I have a lot of silly code in my commercial game project that wraps |
The two big use cases I see for I really love the power of the tweening engine, and I think it could work very well for fading music in and out, but as it is right now with only Personally, I don't think I can recall a single time where I was writing code to control volume, and actually wanted to work in decibels; the tasks I wanted to accomplish always necessitated converting to and/or from a linear scale anyways. My sentiment on this is very close to what aXu-AP said here - behavior like setting and adjusting a volume percentage feels like something common enough that we shouldn't have to add in a snippet of code to get it on each individual project. I've asked around a little bit for others' experiences on this, and have gotten varied responses: some have said they always use a linear scale and don't know why a decibel property would even be exposed, others said that having both would be the best option, and others yet said they hated linear scale. Most of the pushback I saw to the linear scale seemed to be more in the context of sound effects and dialogue, rather than music or overall audio, which is where I think the linear property would shine the most. As for the general sentiment towards a feature like this: the original proposal post has (at the time of writing this) 18 👍 reactions and only one 👎 reaction. Replies to the proposal supporting it have consistently more positive reactions (22ish) than replies that were dismissive of it (3ish). I'd generally point to the proposal thread for peoples' discussions and opinions on adding such a feature. |
It did occur to me that Oops, looks like the That definitely doesn't make sense 😅 Will have to take a look at that and how to fix it in the future before a potential merge. |
It's because of |
327a06c
to
fefac64
Compare
|
303b852
to
ca56db4
Compare
Remove default value from `volume_linear` property documentation Remove `volume_linear` internal property from `AudioBusLayout` Update doc/classes/AudioEffectAmplify.xml [no ci] Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Make documentation more concise [no ci]
f95806f
to
2f5b97c
Compare
Thanks! |
This PR implements the backend side for godotengine/godot-proposals#1884 (but does not fully close it).
volume_linear
toAudioStreamPlayer
,AudioStreamPlayer2D
,AudioStreamPlayer3D
, andAudioEffectAmplify
(including the setterset_volume_linear
and getterget_volume_linear
).volume_linear
for every bus within anAudioBusLayout
.get_bus_volume_linear
and setterset_bus_volume_linear
toAudioServer
. (Because it requires an argument for the bus index, it can't be made into a property.)Internally, it simply wraps the
volume_db
properties withlinear_to_db
anddb_to_linear
calls. However, having these as properties with built-in getters and setters has some nice benefits:Range.value_changed
signal up toset_volume_linear
.Tween
can be used to smoothly fade music or sounds in and out with anAudioStreamPlayer
:Note
This PR does not implement any frontend/inspector behavior. Users will still only be able to modify the volume in the inspector in dBs. If desired, it would be trivial to expose "Volume Linear" underneath "Volume dB" in the inspector. However this would take up twice as much space in the inspector for what is effectively the same value.
In the long run, I think it'd be best to include a custom input field that can switch between dB and the linear scale, as suggested in the proposal. Because this PR doesn't implement this (currently), I don't feel it would close that proposal.