// Start a sound effect
// =======================================================================
-void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
+int S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
{
channel_t *target_chan, *check;
int vol;
size_t skip;
if (!sound_started || !sfx || !sfx->fetcher || nosound.integer)
- return;
+ return -1;
vol = fvol*255;
// pick a channel to play on
target_chan = SND_PickChannel(entnum, entchannel);
if (!target_chan)
- return;
+ return -1;
// spatialize
memset (target_chan, 0, sizeof(*target_chan));
if (!S_LoadSound (sfx, true))
{
target_chan->sfx = NULL;
- return; // couldn't load the sound's data
+ return -1; // couldn't load the sound's data
}
target_chan->sfx = sfx;
break;
}
}
+
+ return (channels - target_chan);
}
void S_StopSound(int entnum, int entchannel)
S_StopAllSounds(true);
}
+void S_PauseGameSounds (void)
+{
+ unsigned int i;
+
+ for (i = 0; i < total_channels; i++)
+ {
+ channel_t *ch;
+
+ ch = &channels[i];
+ if (ch->sfx != NULL && ! (ch->flags & CHANNELFLAG_LOCALSOUND))
+ ch->flags |= CHANNELFLAG_PAUSED;
+ }
+}
+
+void S_ResumeGameSounds (void)
+{
+ unsigned int i;
+
+ for (i = 0; i < total_channels; i++)
+ {
+ channel_t *ch;
+
+ ch = &channels[i];
+ if (ch->sfx != NULL && ! (ch->flags & CHANNELFLAG_LOCALSOUND))
+ ch->flags &= ~CHANNELFLAG_PAUSED;
+ }
+}
+
void S_ClearBuffer(void)
{
int clear;
static void S_Play_Common(float fvol, float attenuation)
{
- int i;
+ int i, ch_ind;
char name[256];
sfx_t *sfx;
else
i++;
- S_StartSound(-1, 0, sfx, listener_vieworigin, fvol, attenuation);
+ ch_ind = S_StartSound(-1, 0, sfx, listener_vieworigin, fvol, attenuation);
+ if (ch_ind >= 0)
+ channels[ch_ind].flags |= CHANNELFLAG_LOCALSOUND;
}
}
void S_LocalSound (char *sound)
{
sfx_t *sfx;
+ int ch_ind;
if (!snd_initialized.integer || nosound.integer)
return;
Con_Printf("S_LocalSound: can't precache %s\n", sound);
return;
}
- S_StartSound (cl.viewentity, -1, sfx, vec3_origin, 1, 1);
+
+ ch_ind = S_StartSound (cl.viewentity, -1, sfx, vec3_origin, 1, 1);
+ if (ch_ind >= 0)
+ channels[ch_ind].flags |= CHANNELFLAG_LOCALSOUND;
}
{
}
-void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
+int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
{
+ return -1;
}
void S_StopSound (int entnum, int entchannel)
{
}
+void S_PauseGameSounds (void)
+{
+}
+
+void S_ResumeGameSounds (void)
+{
+}
+
sfx_t *S_GetCached(const char *name)
{
return NULL;
// channel_t flags
#define CHANNELFLAG_NONE 0
#define CHANNELFLAG_FORCELOOP (1 << 0) // force looping even if the sound is not looped
+#define CHANNELFLAG_LOCALSOUND (1 << 1) // non-game sound (ex: menu sound)
+#define CHANNELFLAG_PAUSED (1 << 2)
typedef struct
{
void S_Init (void);
void S_Startup (void);
void S_Shutdown (void);
-void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation);
+int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation);
void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation);
void S_StopSound (int entnum, int entchannel);
void S_StopAllSounds(qboolean clear);
+void S_PauseGameSounds (void);
+void S_ResumeGameSounds (void);
void S_ClearBuffer (void);
void S_Update(vec3_t origin, vec3_t forward, vec3_t left, vec3_t up);
void S_ExtraUpdate (void);