Media audio can be very loud on room entry and scene changes #5550
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.
When you enter a room with audio or video media there can be a short period of very load audio output. The principle reason for this is that when the HTML Audio and Video elements are created there can be a delay before the various audio systems adopt them and start controlling their volumes. This has been addressed by setting the volume to zero by default and then reseting it to one once control has been passed over.
A secondary issue is that the default audio gain for the THREE sources is one and volume is interpolated to it's proper value over time using
setTargetAtTime
. If the gain is set to zero by default then the audio will fade up rather than down, which is less jarring.The last issue is that before the room is entered, the player is positioned at the scene preview camera position and the audio will be set accordingly. This PR does not address this issue because it is not clear what the desired behaviour is.
Here is a test room that demonstrates all of these elements: https://dev.reticulum.io/2D9w2Y4. Without the PR applied you will hear a loud blast on first load, followed by the volume decreasing because the preview position in near the audio source, then on scene entry the volume will drop to being low. With the PR you will not have the initial blast of sound and instead jump straight to the volume of the preview sound.
Note that you might need to click the page a bit during load to tell the browser you are happy to hear audio at all. While this would appear to make the PR less relevant, remember that this approval is already given in the case of scene changes or fast room switching, where the sound blast can be significant.
I'm happy to take advice on whether I'm using the right properties in the right places, but I hope the underlying principles are sound.