void S_StopAllSounds(qboolean clear);
void S_StopAllSoundsC(void);
+void S_ClearBuffer (void);
+
+
// =======================================================================
// Internal sound data & structures
// =======================================================================
unsigned int total_channels;
int snd_blocked = 0;
-static qboolean snd_ambient = 1;
cvar_t snd_initialized = { CVAR_READONLY, "snd_initialized", "0"};
cvar_t snd_streaming = { CVAR_SAVE, "snd_streaming", "1"};
int fakedma_updates = 15;
-void S_AmbientOff (void)
-{
- snd_ambient = false;
-}
-
-
-void S_AmbientOn (void)
-{
- snd_ambient = true;
-}
-
-
void S_SoundInfo_f(void)
{
if (!sound_started || !shm)
Con_Printf("%5d samplepos\n", shm->samplepos);
Con_Printf("%5d samplebits\n", shm->format.width * 8);
Con_Printf("%5d speed\n", shm->format.speed);
- Con_Printf("0x%x dma buffer\n", shm->buffer);
+ Con_Printf("%p dma buffer\n", shm->buffer);
Con_Printf("%5u total_channels\n", total_channels);
}
sfx = &known_sfx[num_sfx++];
memset(sfx, 0, sizeof(*sfx));
- strncpy(sfx->name, name, sizeof(sfx->name));
+ strlcpy (sfx->name, name, sizeof (sfx->name));
return sfx;
}
continue;
// don't override looped sounds
- if (ch->forceloop || (ch->sfx != NULL && ch->sfx->loopstart >= 0))
+ if ((ch->flags & CHANNELFLAG_FORCELOOP) != 0 ||
+ (ch->sfx != NULL && ch->sfx->loopstart >= 0))
continue;
if (ch->end - paintedtime < life_left)
// 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;
+ target_chan->flags = CHANNELFLAG_NONE;
target_chan->pos = 0.0;
target_chan->end = paintedtime + sfx->total_length;
target_chan->lastptime = paintedtime;
break;
}
}
+
+ return (target_chan - channels);
}
-void S_StopSound(int entnum, int entchannel)
+void S_StopChannel (unsigned int channel_ind)
{
- int i;
+ channel_t *ch;
+
+ if (channel_ind >= total_channels)
+ return;
- for (i=0 ; i<MAX_DYNAMIC_CHANNELS ; i++)
+ ch = &channels[channel_ind];
+ if (ch->sfx != NULL)
{
- if (channels[i].entnum == entnum
- && channels[i].entchannel == entchannel)
+ if (ch->sfx->fetcher != NULL)
{
- channels[i].end = 0;
- channels[i].sfx = NULL;
- return;
+ snd_fetcher_end_t fetcher_end = ch->sfx->fetcher->end;
+ if (fetcher_end != NULL)
+ fetcher_end (ch);
}
+ ch->sfx = NULL;
}
+ ch->end = 0;
+}
+
+void S_PauseChannel (unsigned int channel_ind, qboolean toggle)
+{
+ if (toggle)
+ channels[channel_ind].flags |= CHANNELFLAG_PAUSED;
+ else
+ channels[channel_ind].flags &= ~CHANNELFLAG_PAUSED;
+}
+
+void S_LoopChannel (unsigned int channel_ind, qboolean toggle)
+{
+ if (toggle)
+ channels[channel_ind].flags |= CHANNELFLAG_FORCELOOP;
+ else
+ channels[channel_ind].flags &= ~CHANNELFLAG_FORCELOOP;
+}
+
+void S_StopSound(int entnum, int entchannel)
+{
+ unsigned int i;
+
+ for (i = 0; i < MAX_DYNAMIC_CHANNELS; i++)
+ if (channels[i].entnum == entnum && channels[i].entchannel == entchannel)
+ {
+ S_StopChannel (i);
+ return;
+ }
}
void S_StopAllSounds(qboolean clear)
{
+ unsigned int i;
+
+ for (i = 0; i < total_channels; i++)
+ S_StopChannel (i);
+
total_channels = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; // no statics
memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
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_SetChannelVolume (unsigned int ch_ind, float fvol)
+{
+ channels[ch_ind].master_vol = fvol * 255;
+}
+
+
void S_ClearBuffer(void)
{
int clear;
ss = &channels[total_channels++];
memset(ss, 0, sizeof(*ss));
- ss->forceloop = true;
+ ss->flags = CHANNELFLAG_FORCELOOP;
ss->sfx = sfx;
VectorCopy (origin, ss->origin);
ss->master_vol = vol;
for (ambient_channel = 0 ; ambient_channel < NUM_AMBIENTS;ambient_channel++)
channels[ambient_channel].sfx = NULL;
- if (!snd_ambient || ambient_level.value <= 0 || !cl.worldmodel || !cl.worldmodel->brush.AmbientSoundLevelsForPoint)
+ if (ambient_level.value <= 0 || !cl.worldmodel || !cl.worldmodel->brush.AmbientSoundLevelsForPoint)
return;
cl.worldmodel->brush.AmbientSoundLevelsForPoint(cl.worldmodel, listener_vieworigin, ambientlevels, sizeof(ambientlevels));
(ambient_sfx[ambient_channel]->flags & SFXFLAG_SILENTLYMISSING))
continue;
chan = &channels[ambient_channel];
- chan->forceloop = true;
+ chan->flags |= CHANNELFLAG_FORCELOOP;
chan->sfx = ambient_sfx[ambient_channel];
vol = ambient_level.value * ambientlevels[ambient_channel];
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;
}
}
{
size = sfx->mempool->totalsize;
total += size;
- Con_Printf("%c(%2db) %7i : %s\n", sfx->loopstart >= 0 ? 'L' : ' ', sfx->format.width * 8, size, sfx->name);
+ Con_Printf ("%c%c(%2db, %6s) %8i : %s\n",
+ (sfx->loopstart >= 0) ? 'L' : ' ',
+ (sfx->flags & SFXFLAG_STREAMED) ? 'S' : ' ',
+ sfx->format.width * 8,
+ (sfx->format.channels == 2) ? "stereo" : "mono",
+ size,
+ sfx->name);
}
}
Con_Printf("Total resident: %i\n", total);
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;
}