#include "snd_main.h"
#include "snd_ogg.h"
-// TODO: find a better solution instead of using a define
-#if defined( _WIN32 ) && !defined( USE_SDL )
-# define USE_DSOUND
-#endif
-
-#ifdef USE_DSOUND
-#include <windows.h>
-#include <dsound.h>
-extern DWORD gSndBufSize;
-extern LPDIRECTSOUND pDS;
-extern LPDIRECTSOUNDBUFFER pDSBuf;
-#endif
-
void S_Play(void);
void S_PlayVol(void);
cvar_t snd_initialized = { CVAR_READONLY, "snd_initialized", "0"};
cvar_t snd_streaming = { CVAR_SAVE, "snd_streaming", "1"};
-// pointer should go away
volatile dma_t *shm = 0;
volatile dma_t sn;
void S_ClearBuffer(void)
{
- int clear;
+ int clear;
+ unsigned char *pbuf;
if (!sound_started || !shm)
return;
if (shm->format.width == 1)
- clear = 0x80;
+ clear = 0x80; // 8 bit sound (unsigned)
else
- clear = 0;
-
-#ifdef USE_DSOUND
- if (pDSBuf)
- {
- DWORD dwSize;
- DWORD *pData;
- int reps;
- HRESULT hresult;
-
- reps = 0;
-
- while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, (LPVOID*)&pData, &dwSize, NULL, NULL, 0)) != DS_OK)
- {
- if (hresult != DSERR_BUFFERLOST)
- {
- Con_Print("S_ClearBuffer: DS::Lock Sound Buffer Failed\n");
- S_Shutdown ();
- return;
- }
-
- if (++reps > 10000)
- {
- Con_Print("S_ClearBuffer: DS: couldn't restore buffer\n");
- S_Shutdown ();
- return;
- }
- }
+ clear = 0; // 16 bit sound (signed)
- memset(pData, clear, shm->samples * shm->format.width);
-
- pDSBuf->lpVtbl->Unlock(pDSBuf, pData, dwSize, NULL, 0);
-
- }
- else
-#endif
- if (shm->buffer)
+ pbuf = S_LockBuffer();
+ if (pbuf != NULL)
{
int setsize = shm->samples * shm->format.width;
- unsigned char *buf = shm->buffer;
while (setsize--)
- *buf++ = clear;
+ *pbuf++ = clear;
// on i586/i686 optimized versions of glibc, glibc *wrongly* IMO,
// reads the memory area before writing to it causing a seg fault
// since the memory is PROT_WRITE only and not PROT_READ|PROT_WRITE
//memset(shm->buffer, clear, shm->samples * shm->format.width);
+
+ S_UnlockBuffer ();
}
}
if (!sound_started || (snd_blocked > 0))
return;
-// Updates DMA time
+ // Updates DMA time
GetSoundtime();
-// check to make sure that we haven't overshot
+ // check to make sure that we haven't overshot
if (paintedtime < soundtime)
paintedtime = soundtime;
-// mix ahead of current position
+ // mix ahead of current position
endtime = soundtime + _snd_mixahead.value * shm->format.speed;
samps = shm->samples >> (shm->format.channels - 1);
if (endtime > (unsigned int)(soundtime + samps))
endtime = soundtime + samps;
-#ifdef USE_DSOUND
-// if the buffer was lost or stopped, restore it and/or restart it
- {
- DWORD dwStatus;
-
- if (pDSBuf)
- {
- 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);
-
- if (!(dwStatus & DSBSTATUS_PLAYING))
- pDSBuf->lpVtbl->Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);
- }
- }
-#endif
-
S_PaintChannels (endtime);
SNDDMA_Submit ();
gSndBufSize = dsbcaps.dwBufferBytes;
-// initialize the buffer
+ // initialize the buffer
reps = 0;
while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, (LPVOID*)&lpData, &dwSize, NULL, NULL, 0)) != DS_OK)
shm->format.channels = 2;
shm->format.width = 2;
// COMMANDLINEOPTION: Windows Sound: -sndspeed <hz> chooses 44100 hz, 22100 hz, or 11025 hz sound output rate
- i = COM_CheckParm ("-sndspeed"); // LordHavoc: -sndspeed option
+ i = COM_CheckParm ("-sndspeed");
if (i && i != (com_argc - 1))
shm->format.speed = atoi(com_argv[i+1]);
else
{
int reps;
HRESULT hresult;
+ DWORD dwStatus;
if (pDSBuf)
{
+ // if the buffer was lost or stopped, restore it and/or restart it
+ 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);
+
+ if (!(dwStatus & DSBSTATUS_PLAYING))
+ pDSBuf->lpVtbl->Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);
+
reps = 0;
while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, (LPVOID*)&dsound_pbuf, &dsound_dwSize, (LPVOID*)&dsound_pbuf2, &dsound_dwSize2, 0)) != DS_OK)
{
if (hresult != DSERR_BUFFERLOST)
{
- Con_Print("S_LockBuffer: DS::Lock Sound Buffer Failed\n");
+ Con_Print("S_LockBuffer: DS: Lock Sound Buffer Failed\n");
S_Shutdown ();
S_Startup ();
return NULL;