console command: nosound 0/1 is very useful, but buggy.
after breaking the ventilation grilles
...
If return 0, SOMETIMES some sounds are not played (for example: steps).
This cvar only affects sounds that are started when it's non-zero. Sounds that are already playing are not affected.
Sounds not playing sometimes when it's 0 is probably caused by something else.
SamVanheer, I meant after switching to 1 you can open the door or shoot in the box and hear the sounds (this should not be).
I think i know why this is the case.
All of those sounds use CHAN_STATIC, which is used when playing sounds that may start and/or stop while outside the player's Potentially Audible Set (PAS). This ensures sounds play even if you enter the PAS after they've started, and also stops them correctly even if you aren't currently able to hear them.
Otherwise long and/or looping sounds won't work properly.
These sounds are stopped by using the exact same code that is used to play it, only with a flag to stop the sound. Because of this S_StartStaticSound does not check this cvar so sounds will work properly even if the cvar is changed.
This can be fixed by adding the cvar check along with a special case that allows the code to run if the flags passed contain SND_STOP.
Note that this has been the case since Quake:
https://github.com/id-Software/Quake/blob/bf4ac424ce754894ac8f1dae6a3981954bc9852d/WinQuake/snd_dma.c#L620-L654
Also note that this can happen in any game, not just CS. @kisak-valve the Counter-Strike label should be removed.
To reproduce bug â„–2:
The second issue happens because this cvar is also checked for in S_PrecacheSound. As a result the engine won't load sounds, but will still reference them when receiving sound play commands from the server. The sound code will ignore the commands because the sounds are null entries. Those sounds won't be loaded into memory as a result.
Only sounds played in a way that results in an S_PrecacheSound call will play.
The fix is simple: don't check the cvar in this function. Since the cvar can be toggled at any time the engine should be prepared to deal with this scenario so it should always load sounds.
If disabling sound loading is desired then it should be moved to its own cvar, or the user should use the -nosound command line parameter to disable sound functionality altogether.
@mikela-valve This should be an easy fix.
Most helpful comment
I think i know why this is the case.
All of those sounds use
CHAN_STATIC, which is used when playing sounds that may start and/or stop while outside the player's Potentially Audible Set (PAS). This ensures sounds play even if you enter the PAS after they've started, and also stops them correctly even if you aren't currently able to hear them.Otherwise long and/or looping sounds won't work properly.
These sounds are stopped by using the exact same code that is used to play it, only with a flag to stop the sound. Because of this
S_StartStaticSounddoes not check this cvar so sounds will work properly even if the cvar is changed.This can be fixed by adding the cvar check along with a special case that allows the code to run if the flags passed contain
SND_STOP.Note that this has been the case since Quake:
https://github.com/id-Software/Quake/blob/bf4ac424ce754894ac8f1dae6a3981954bc9852d/WinQuake/snd_dma.c#L620-L654
https://github.com/id-Software/Quake/blob/bf4ac424ce754894ac8f1dae6a3981954bc9852d/WinQuake/snd_dma.c#L451-L468
Also note that this can happen in any game, not just CS. @kisak-valve the Counter-Strike label should be removed.