tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

all tracks in an AudioGroup play briefly on the first passagerender of the game #127

Closed moates closed 3 years ago

moates commented 3 years ago

Describe the bug. This is a highly specific bug I just ran into. It may also be that I fundamentally don't understand what's behind the scenes for AudioRunner.

I wrote a simple (hacky) background track manager that controls background track transitions using Passage tags. In JS, on each :passagerender I check for any music tags, fade out all old tracks in the audio group :bgmusicgroup, and play the new track.

On the first render of a game page with audio (in both Play and Debug modes), for a fraction of a second, all the tracks in the :bgmusicgroup play at once at a loud volume.

To Reproduce: only-bans-sugarcube-audio-bug-report.txt I'm attaching a minimum reproducible bug story. (Just change the extension from .txt to .html) In StoryInit, you'll need to change the audio sources to whatever test tracks you have access to.

Expected behavior. The AudioRunner.fadeOut docs say

duration: (number) The number of seconds over which the tracks should be faded. fromVol: (optional, number) The starting volume level. If omitted, defaults to the tracks' current volume level

I would expect that the audio group's initial volume is set to zero, and thus when fading out silent tracks there should not be a sudden increase in volume for all tracks.

Project details.

Desktop details.

Thank you! I love and appreciate Sugarcube. Shout out to you, maintainers!

tmedwards commented 3 years ago

I would expect that the audio group's initial volume is set to zero…

Tracks default to 100% volume. Groups are simply a way to collect tracks for ease of issuing actions (commands).

If you want certain tracks to start at any volume other than 100%, then you'll need to set them thus.

moates commented 3 years ago

I may be misunderstanding if there's a difference between the "current volume" and the "volume" property of a given track.

At the beginning of the game, all tracks are manually stopped with AudioRunner.stop. Am I wrong to assume that the volume of a stopped track should be 0? And that the "current volume" of stopped tracks should also be 0?

tmedwards commented 3 years ago

Current volume and volume are generally the same thing.

The volume of a track is not affected by the stop action, which pauses the track and sets its time to zero.

If you want to set the volume at the same time, then you should also issue a volume action.

moates commented 3 years ago

Ah, okay. I was clearly misunderstanding. Thank you for your help and patience!