#include "quakedef.h"
#ifdef _WIN32
-#include "winquake.h"
+#include <windows.h>
+#include <dsound.h>
+extern DWORD gSndBufSize;
+extern LPDIRECTSOUND pDS;
+extern LPDIRECTSOUNDBUFFER pDSBuf;
#endif
#include "ogg.h"
{
if (!sound_started || !shm)
{
- Con_Printf ("sound system not started\n");
+ Con_Print("sound system not started\n");
return;
}
{
if (!SNDDMA_Init())
{
- Con_Printf("S_Startup: SNDDMA_Init failed.\n");
+ Con_Print("S_Startup: SNDDMA_Init failed.\n");
sound_started = 0;
shm = NULL;
return;
*/
void S_Init(void)
{
- Con_DPrintf("\nSound Initialization\n");
+ Con_DPrint("\nSound Initialization\n");
S_RawSamples_ClearQueue();
/*
=========
-S_IsCached
+S_GetCached
=========
*/
sfx = &known_sfx[num_sfx++];
memset(sfx, 0, sizeof(*sfx));
- snprintf(sfx->name, sizeof(sfx->name), "%s", name);
+ strncpy(sfx->name, name, sizeof(sfx->name));
return sfx;
}
*/
void S_TouchSound (char *name)
{
- S_FindName(name);
+ sfx_t *sfx;
+
+ sfx = S_FindName (name);
+
+ // Set the "used" flag for this sound
+ if (sfx != NULL)
+ sfx->flags |= SFXFLAG_USED;
}
+
+/*
+==================
+S_ClearUsed
+
+Reset the "used" flag of all precached sounds
+==================
+*/
+void S_ClearUsed (void)
+{
+ int i;
+
+ for (i = 0; i < num_sfx; i++)
+ known_sfx[i].flags &= ~SFXFLAG_USED;
+}
+
+
+/*
+==================
+S_PurgeUnused
+
+Free all precached sounds without the "used" flag
+==================
+*/
+void S_PurgeUnused (void)
+{
+ int i;
+ sfx_t *sfx;
+
+ for (i = 0; i < num_sfx; i++)
+ {
+ sfx = &known_sfx[i];
+ if (! (sfx->flags & SFXFLAG_USED))
+ S_UnloadSound (sfx);
+ }
+}
+
+
/*
==================
S_PrecacheSound
{
if (hresult != DSERR_BUFFERLOST)
{
- Con_Printf ("S_ClearBuffer: DS::Lock Sound Buffer Failed\n");
+ Con_Print("S_ClearBuffer: DS::Lock Sound Buffer Failed\n");
S_Shutdown ();
return;
}
if (++reps > 10000)
{
- Con_Printf ("S_ClearBuffer: DS: couldn't restore buffer\n");
+ Con_Print("S_ClearBuffer: DS: couldn't restore buffer\n");
S_Shutdown ();
return;
}
if (total_channels == MAX_CHANNELS)
{
- Con_Printf ("total_channels == MAX_CHANNELS\n");
+ Con_Print("total_channels == MAX_CHANNELS\n");
return;
}
// calc ambient sound levels
for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++)
{
- if (ambient_sfx[ambient_channel] && ambient_sfx[ambient_channel]->silentlymissing)
+ if (ambient_sfx[ambient_channel] &&
+ (ambient_sfx[ambient_channel]->flags & SFXFLAG_SILENTLYMISSING))
continue;
chan = &channels[ambient_channel];
chan->forceloop = true;
if (ch->sfx && (ch->leftvol || ch->rightvol) )
total++;
- Con_Printf ("----(%i)----\n", total);
+ Con_Printf("----(%i)----\n", total);
}
// mix some sound
if (pDSBuf)
{
- if (pDSBuf->lpVtbl->GetStatus (pDSBuf, &dwStatus) != DD_OK)
- Con_Printf ("Couldn't get sound buffer status\n");
+ if (pDSBuf->lpVtbl->GetStatus (pDSBuf, &dwStatus) != DS_OK)
+ Con_Print("Couldn't get sound buffer status\n");
if (dwStatus & DSBSTATUS_BUFFERLOST)
pDSBuf->lpVtbl->Restore (pDSBuf);
sfx = S_PrecacheSound (sound, true);
if (!sfx)
{
- Con_Printf ("S_LocalSound: can't precache %s\n", sound);
+ Con_Printf("S_LocalSound: can't precache %s\n", sound);
return;
}
S_StartSound (cl.viewentity, -1, sfx, vec3_origin, 1, 1);
}
-void S_ClearPrecache (void)
-{
-}
-
-
-void S_BeginPrecaching (void)
-{
-}
-
-
-void S_EndPrecaching (void)
-{
-}
-
-
#define RAWSAMPLESBUFFER 32768
short s_rawsamplesbuffer[RAWSAMPLESBUFFER * 2];
int s_rawsamplesbuffer_start;