]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
new cvars: snd_startloopingsounds, snd_startnonloopingsounds
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 3 Jun 2011 20:18:37 +0000 (20:18 +0000)
committerRudolf Polzer <divverent@xonotic.org>
Fri, 3 Jun 2011 20:15:01 +0000 (22:15 +0200)
Use cases:
1. playing mods with bugs where looping sounds never end, annoying
2. implementing demo seeking via cfg file tricks (turn off non-looping sounds
   during high slowmo values used for seeking)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11177 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=55c3001cc18a0c55096bd3bb04af734df7e8025b

cd_shared.c
snd_main.c
sound.h

index 7ca41ed60079493485e6ad7db7323fdf94f30e32..13634e5b1a2e4d2805e2504e063368fd129316ea 100644 (file)
@@ -324,13 +324,9 @@ void CDAudio_Play_byName (const char *trackname, qboolean looping, qboolean tryr
        }
        if (FS_FileExists(filename) && (sfx = S_PrecacheSound (filename, false, true)))
        {
-               faketrack = S_StartSound_StartPosition (-1, 0, sfx, vec3_origin, cdvolume, 0, startposition);
+               faketrack = S_StartSound_StartPosition_Flags (-1, 0, sfx, vec3_origin, cdvolume, 0, startposition, (looping ? CHANNELFLAG_FORCELOOP : 0) | CHANNELFLAG_FULLVOLUME | CHANNELFLAG_LOCALSOUND);
                if (faketrack != -1)
                {
-                       if (looping)
-                               S_SetChannelFlag (faketrack, CHANNELFLAG_FORCELOOP, true);
-                       S_SetChannelFlag (faketrack, CHANNELFLAG_FULLVOLUME, true);
-                       S_SetChannelFlag (faketrack, CHANNELFLAG_LOCALSOUND, true); // not pausable
                        if(track >= 1)
                        {
                                if(cdaudio.integer != 0) // we don't need these messages if only fake tracks can be played anyway
index 9265cb68b12bae154fdae8fad98c37a1b658c9b7..ec3d172c2614d5f23ff11bb7b118848a5bdf3ef2 100644 (file)
@@ -229,6 +229,9 @@ static cvar_t snd_speed = {CVAR_SAVE, "snd_speed", "48000", "sound output freque
 static cvar_t snd_width = {CVAR_SAVE, "snd_width", "2", "sound output precision, in bytes (1 and 2 supported)"};
 static cvar_t snd_channels = {CVAR_SAVE, "snd_channels", "2", "number of channels for the sound output (2 for stereo; up to 8 supported for 3D sound)"};
 
+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"};
+
 // Ambient sounds
 static sfx_t* ambient_sfxs [2] = { NULL, NULL };
 static const char* ambient_names [2] = { "sound/ambience/water1.wav", "sound/ambience/wind2.wav" };
@@ -827,6 +830,9 @@ void S_Init(void)
        Cvar_RegisterVariable(&snd_channels);
        Cvar_RegisterVariable(&snd_mutewhenidle);
 
+       Cvar_RegisterVariable(&snd_startloopingsounds);
+       Cvar_RegisterVariable(&snd_startnonloopingsounds);
+
 // COMMANDLINEOPTION: Sound: -nosound disables sound (including CD audio)
        if (COM_CheckParm("-nosound"))
        {
@@ -1560,6 +1566,18 @@ void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int flags,
                Con_Printf("S_PlaySfxOnChannel called with NULL??\n");
                return;
        }
+
+       if ((sfx->loopstart < sfx->total_length) || (flags & CHANNELFLAG_FORCELOOP))
+       {
+               if(!snd_startloopingsounds.integer)
+                       return;
+       }
+       else
+       {
+               if(!snd_startnonloopingsounds.integer)
+                       return;
+       }
+
        // Initialize the channel
        // a crash was reported on an in-use channel, so check here...
        if (target_chan->sfx)
@@ -1600,7 +1618,7 @@ void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int flags,
 }
 
 
-int S_StartSound_StartPosition (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float startposition)
+int S_StartSound_StartPosition_Flags (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float startposition, int flags)
 {
        channel_t *target_chan, *check, *ch;
        int             ch_idx, startpos;
@@ -1653,11 +1671,16 @@ int S_StartSound_StartPosition (int entnum, int entchannel, sfx_t *sfx, vec3_t o
                }
        }
 
-       S_PlaySfxOnChannel (sfx, target_chan, CHANNELFLAG_NONE, origin, fvol, attenuation, false, entnum, entchannel, startpos);
+       S_PlaySfxOnChannel (sfx, target_chan, flags, origin, fvol, attenuation, false, entnum, entchannel, startpos);
 
        return (target_chan - channels);
 }
 
+int S_StartSound_StartPosition (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float startposition)
+{
+       return S_StartSound_StartPosition_Flags(entnum, entchannel, sfx, origin, fvol, attenuation, startposition, CHANNELFLAG_NONE);
+}
+
 int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
 {
        return S_StartSound_StartPosition(entnum, entchannel, sfx, origin, fvol, attenuation, 0);
diff --git a/sound.h b/sound.h
index 37e53b06f1e541983304a6a8e68603ca43184759..9099b9cb46d56adedb33bf6e8813dd9c224c91a3 100644 (file)
--- a/sound.h
+++ b/sound.h
@@ -76,6 +76,7 @@ qboolean S_IsSoundPrecached (const sfx_t *sfx);
 // S_StartSound returns the channel index, or -1 if an error occurred
 int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation);
 int S_StartSound_StartPosition (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float startposition);
+int S_StartSound_StartPosition_Flags (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float startposition, int flags);
 qboolean S_LocalSound (const char *s);
 
 void S_StaticSound (sfx_t *sfx, vec3_t origin, float fvol, float attenuation);