Repository navigation
feat: separate music and sound volumes - #14
Merged
Merged
Conversation
g.MusicVolume(v) and g.SoundVolume(v) set each kind's own volume, 0 to 1 (the default), clamped like Volume (NaN counts as 0). g.Volume stays the master: a player plays at its channel's volume times the master's, so a mute key still silences everything and unmuting brings each channel back where it was. MusicVolume and Volume apply to the playing music at once; SoundVolume applies to every sound started afterwards, like Volume does for effects. The asset cache keeps the three volumes by channel (Master, Music, Sounds) and computes a player's level from them. A sound whose level is 0, from either volume, now returns before any work: no file read, no decoding, no player. Music still starts silently when muted, so raising the volume brings it back. Horde proves it: the pause menu gains "4 MUSIC 100%" and "5 SOUNDS 100%" entries (LB and RB on a pad, with pad prompts, or a click) that cycle each channel through 100, 50 and 0%, under the M master mute.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
g.MusicVolume(v float64): the music's own volume, 0..1 (default 1).g.SoundVolume(v float64): the sound effects' own volume, 0..1 (default 1).g.Volume(v)stays the master and scales both.Design
Volume(0)) still silences everything, and unmuting restores each channel where the settings menu left it, with no bookkeeping in the game.Volume. Clamped to 0..1, NaN counts as 0, callable any time.VolumeandMusicVolumeupdate the playing music at once;SoundVolumeapplies to sounds started afterwards (fire-and-forget effects already playing finish at their old volume, as withVolume).assets.Cachekeeps the three volumes in one array indexed by an internalChannel(Master, Music, Sounds) under its existing mutex;Level(ch)computes the effective value. Internal only: the public API is the three setters. No getters, as withVolume: a game's settings screen owns its values (and persists them withg.Save).Proof
volume_test.go(no audio device): each setter's default 1 and clamping (0.5, -1, 2, 0, 1, NaN, +Inf); levels multiply (0.5 master x 0.4 music = 0.2, x 0.8 sounds = 0.4) and channels keep their value under a master change; muting sounds leaves the music; a windowed game'sSoundon a missing file does nothing withSoundVolume(0)orVolume(0)and panics (tries to load) once audible, proving muted sounds do no work; headless games can call all three fromOnUpdate.examples/horde: the pause overlay gains "4 MUSIC 100%" and "5 SOUNDS 100%" (4/5 keys, LB/RB on a pad with pad prompts, or a click), cycling 100, 50, 0%; a new sound level plays a sample hit. M still mutes everything on top.