From 55c3001cc18a0c55096bd3bb04af734df7e8025b Mon Sep 17 00:00:00 2001 From: divverent Date: Fri, 3 Jun 2011 20:18:37 +0000 Subject: [PATCH] new cvars: snd_startloopingsounds, snd_startnonloopingsounds 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 --- cd_shared.c | 6 +----- snd_main.c | 27 +++++++++++++++++++++++++-- sound.h | 1 + 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/cd_shared.c b/cd_shared.c index 7ca41ed6..13634e5b 100644 --- a/cd_shared.c +++ b/cd_shared.c @@ -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 diff --git a/snd_main.c b/snd_main.c index 9265cb68..ec3d172c 100644 --- a/snd_main.c +++ b/snd_main.c @@ -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 37e53b06..9099b9cb 100644 --- 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); -- 2.39.2