ruffle icon indicating copy to clipboard operation
ruffle copied to clipboard

web: Allow modifying stage volume via JS

Open adrian17 opened this issue 2 years ago • 4 comments

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.

adrian17 avatar Aug 02 '22 16:08 adrian17

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.

torokati44 avatar Aug 02 '22 21:08 torokati44

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.

adrian17 avatar Aug 02 '22 22:08 adrian17

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

torokati44 avatar Aug 02 '22 23:08 torokati44

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.

relrelb avatar Aug 06 '22 08:08 relrelb

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.

Herschel avatar Aug 15 '22 01:08 Herschel