-void S_ClearBuffer(void)
-{
- int clear;
-
- if (!sound_started || !shm)
- return;
-
- if (shm->format.width == 1)
- clear = 0x80;
- 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;
- }
- }
-
- memset(pData, clear, shm->samples * shm->format.width);
-
- pDSBuf->lpVtbl->Unlock(pDSBuf, pData, dwSize, NULL, 0);
-
- }
- else
-#endif
- if (shm->buffer)
- {
- int setsize = shm->samples * shm->format.width;
- unsigned char *buf = shm->buffer;
-
- while (setsize--)
- *buf++ = 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);
- }
-}
-
-