]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
provide cvars to change identical sound randomization
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 4 Oct 2011 07:35:35 +0000 (07:35 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 4 Oct 2011 07:35:35 +0000 (07:35 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11389 d7cf8633-e32d-0410-b094-e92efae38249

snd_main.c

index d0a1011c4cf1f64ffd7b25c94e60f99efb2d42bb..f232e165f78d1cf04f801702d25dc44c53ed6d49 100644 (file)
@@ -241,6 +241,10 @@ static cvar_t snd_channels = {CVAR_SAVE, "snd_channels", "2", "number of channel
 static cvar_t snd_startloopingsounds = {0, "snd_startloopingsounds", "1", "whether to start sounds that would loop (you want this to be 1); existing sounds are not affected"};
 static cvar_t snd_startnonloopingsounds = {0, "snd_startnonloopingsounds", "1", "whether to start sounds that would not loop (you want this to be 1); existing sounds are not affected"};
 
+// randomization
+static cvar_t snd_identicalsoundrandomization_time = {0, "snd_identicalsoundrandomization_time", "-0.1", "how much seconds to randomly skip (positive) or delay (negative) sounds when multiple identical sounds are started on the same frame"};
+static cvar_t snd_identicalsoundrandomization_tics = {0, "snd_identicalsoundrandomization_tics", "0", "if nonzero, how many tics to limit sound randomization as defined by snd_identicalsoundrandomization_time"};
+
 // Ambient sounds
 static sfx_t* ambient_sfxs [2] = { NULL, NULL };
 static const char* ambient_names [2] = { "sound/ambience/water1.wav", "sound/ambience/wind2.wav" };
@@ -851,6 +855,9 @@ void S_Init(void)
        Cvar_RegisterVariable(&snd_startloopingsounds);
        Cvar_RegisterVariable(&snd_startnonloopingsounds);
 
+       Cvar_RegisterVariable(&snd_identicalsoundrandomization_time);
+       Cvar_RegisterVariable(&snd_identicalsoundrandomization_tics);
+
 // COMMANDLINEOPTION: Sound: -nosound disables sound (including CD audio)
        if (COM_CheckParm("-nosound"))
        {
@@ -1677,8 +1684,18 @@ int S_StartSound_StartPosition_Flags (int entnum, int entchannel, sfx_t *sfx, ve
                                continue;
                        if (check->sfx == sfx && check->position == 0 && check->basespeed == fspeed)
                        {
+                               // calculate max offset
+                               float maxtime = snd_identicalsoundrandomization_time.value;
+                               float maxtics = snd_identicalsoundrandomization_tics.value;
+                               float maxticsdelta = ((cls.state == ca_connected) ? (maxtics * (cl.mtime[0] - cl.mtime[1])) : 0);
+                               float maxdelta = 0;
+                               if(maxtics == 0 || fabs(maxticsdelta) > fabs(maxtime))
+                                       maxdelta = maxtime;
+                               else
+                                       maxdelta = fabs(maxticsdelta) * ((maxtime > 0) ? 1 : -1);
+
                                // use negative pos offset to delay this sound effect
-                               startpos = lhrandom(0, -0.1 * sfx->format.speed);
+                               startpos = lhrandom(0, maxdelta * sfx->format.speed);
                                break;
                        }
                }