background music: Tween volume_linear not volume_db #1897
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously we tweened the
volume_dbproperty betweenlinear_to_db(0.00001)andlinear_to_db(1.0). The reason for the strangelower bound was given in a comment but to expand on it:
linear_to_db(0.0)is-inf.linear_to_dbmaps the (logarithmic) decibelscale between -inf and 0.0 onto a linear scale between 0.0 and 1.0. Here
is a table of some sample values that I found helpful, rounded to 1dp:
It's not meaningful to tween a value between 0.0 and -inf: there's no
such thing as "halfway between 0.0 and -inf".
AudioStreamPlayerhas avolume_linearproperty. Setting it just setsvolume_dbto the result oflinear_to_db()on its input. By tweening thisproperty instead, then we can actually tween between the two bounds that
we want.
It also sounds better to my ears than what we were doing before, which
was tweening between 0.0 dB and -100 dB. The human ear perceives a
reduction of 10 dB as a halving of volume. Previously, halfway through
the fade-out (between -0.0 dB and -100 dB) the volume would be -50 dB,
which is a five-fold reduction in volume and means that the sound is
essentially inaudible. With this change, the fade-out is smoother.