ruffle
ruffle copied to clipboard
web: Allow modifying stage volume via JS
It was requested by folks on Discord a couple times. Would also come in handy if we ever add a volume slider to extension or context menu.
Downside: this is not a master player volume, it's the stage volume - it can be overridden by the movie with a simple AS new Sound().setVolume(100);
. In the future, we might want the Player API to be able to set both "stage-visible volume" and "master player (invisible to AS) volume" independently.
Now that #4273 is in, wouldn't it be straightforward to wire in a master volume to Mixer
? AFAIK all sound now goes through that.
I'll be honest, I have absolutely no idea how to interact with Mixer stuff. Meanwhile, the "stage sound transform" is something I can totally grok :) And having it linked to AS visible sound transform is something that might actually be preferred for some uses.
I have absolutely no idea how to interact with Mixer stuff.
Maybe something like this could do it?...
https://github.com/ruffle-rs/ruffle/commit/1e1810c4e6b6cc3fa49bcd8bfc2b3e5e6091d623
Don't ask why both AudioMixer
and AudioMixerProxy
have a new field - this is how I got it to work first.
Also, how would one could pipe setters to these fields from all the way from JS...
I'll be honest, I have absolutely no idea how to interact with Mixer stuff. Meanwhile, the "stage sound transform" is something I can totally grok :) And having it linked to AS visible sound transform is something that might actually be preferred for some uses.
Personally it feels odd to me that JS API would affect AS-observable values. Imagine a SWF that queries new Sound().getVolume()
and displays some sort of graphic accordingly - in that case I wouldn't expect setting volume
from outside would change the graphic. This is quite an exterme example, but I cannot think of an example where this behavior will be actually desirable. Can you please elaborate on a counter example?
Due to this, I support adding an additional global sound transform like @torokati44 suggested. It can be put in AudioMixer
, but I think AudioManager
might be a place for it, next to global_sound_transform
.
I agree, let's instead add an additional global master volume independent from AS. I'm also thinking ahead to the desktop player which would want a similar setting.
AudioBackend::volume
and set_volume
could be added and the volume can be multiplied onto the output sample in AudioMixer::mix_audio
.