coop-deluxe / sm64coopdx

An official continuation of https://github.com/djoslin0/sm64ex-coop on sm64coopdx for the enhancements and progress it already has.
https://sm64coopdx.com
408 stars 73 forks source link

Make Lua audio samples silent for specific sound configuration #391

Open Flower35 opened 4 weeks ago

Flower35 commented 4 weeks ago

Lua audio samples (music streams and sound effects) are no longed playing, while the game window has no focus and the config option "Mute When Window Unfocused" is set to True.

This behaves similar to the check in buffer_audio() from src/pc/pc_main.c.

You might still hear a sample that is already playing while the player clicks out of the window, but no more audio samples will be audible as long as the focus is lost.

Isaac0-dev commented 2 weeks ago

this looks like it will stop all audio streams and samples without starting them again when you tab back that would cause some mods to have their music completely stopped, which will sound like a bug.

AgentXLP commented 2 weeks ago

This just makes it so when audio sample/stream play is called while the window is unfocused, it sets the volume to 0. More efficiently, it could just not be played at all, but this solution still works. Ideally, the audio would be able to change back and forth in realtime, but that would require either updating the volume every frame, or having it update the audio when the window focus status changes and setup an event for that in the window managers. Maybe that would be something worth looking into.

Isaac0-dev commented 2 weeks ago

having it update when tabbing in would be best because the audio could be restored to its original volume