Skip to content

Conversation

@wjt
Copy link
Member

@wjt wjt commented Feb 9, 2026

Previously we tweened the volume_db property between
linear_to_db(0.00001) and linear_to_db(1.0). The reason for the strange
lower bound was given in a comment but to expand on it:
linear_to_db(0.0) is -inf. linear_to_db maps the (logarithmic) decibel
scale 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:

x linear_to_db(x)
0.0 -inf
0.00001 -100.0
0.05 -26.0
0.1 -20.0
0.25 -12.0
0.5 -6.0
0.75 -2.5
1.0 0.0

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".

AudioStreamPlayer has a volume_linear property. Setting it just sets
volume_db to the result of linear_to_db() on its input. By tweening this
property 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.

Previously we tweened the `volume_db` property between
linear_to_db(0.00001) and linear_to_db(1.0). The reason for the strange
lower bound was given in a comment but to expand on it:
linear_to_db(0.0) is -inf. linear_to_db maps the (logarithmic) decibel
scale 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:

| x       | linear_to_db(x) |
| ------- | --------------- |
| 0.0     | -inf            |
| 0.00001 | -100.0          |
| 0.05    |  -26.0          |
| 0.1     |  -20.0          |
| 0.25    |  -12.0          |
| 0.5     |   -6.0          |
| 0.75    |   -2.5          |
| 1.0     |    0.0          |

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".

AudioStreamPlayer has a volume_linear property. Setting it just sets
volume_db to the result of linear_to_db() on its input. By tweening this
property 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.
@wjt wjt requested a review from a team as a code owner February 9, 2026 17:26
@github-actions
Copy link

github-actions bot commented Feb 9, 2026

Play this branch at https://play.threadbare.game/branches/endlessm/wjt/background-music-tween-volume-linear-not-volume-db.

(This launches the game from the start, not directly at the change(s) in this pull request.)

Copy link
Collaborator

@manuq manuq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds better to my ears as well.

@manuq manuq merged commit 27f8327 into main Feb 10, 2026
6 checks passed
@manuq manuq deleted the wjt/background-music-tween-volume-linear-not-volume-db branch February 10, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants