mirror of
https://git.code.sf.net/p/quake/newtree
synced 2024-11-25 13:32:01 +00:00
Win32 sound cleanups - phase1
This commit is contained in:
parent
48f6a02a38
commit
477bcf51b0
4 changed files with 90 additions and 135 deletions
|
@ -103,6 +103,10 @@ void CenterWindow(HWND hWndCenter, int width, int height, BOOL lefttopjustify);
|
|||
void S_BlockSound (void);
|
||||
void S_UnblockSound (void);
|
||||
|
||||
DWORD *DSOUND_LockBuffer(qboolean lockit);
|
||||
void DSOUND_ClearBuffer(int clear);
|
||||
void DSOUND_Restore(void);
|
||||
|
||||
void VID_SetDefaultMode (void);
|
||||
|
||||
int (PASCAL FAR *pWSAStartup)(WORD wVersionRequired, LPWSADATA lpWSAData);
|
||||
|
|
|
@ -38,11 +38,6 @@
|
|||
#include "sys.h"
|
||||
#include "sound.h"
|
||||
|
||||
// fixme: Damn crappy complier doesn't allow me to UNDEF _win32 on command line!
|
||||
#ifdef WIN32SDL
|
||||
#undef _WIN32
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "winquake.h"
|
||||
#include "in_win.h"
|
||||
|
@ -620,35 +615,8 @@ S_ClearBuffer (void)
|
|||
clear = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
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_Printf ("S_ClearBuffer: DS::Lock Sound Buffer Failed\n");
|
||||
S_Shutdown ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (++reps > 10000) {
|
||||
Con_Printf ("S_ClearBuffer: DS: couldn't restore buffer\n");
|
||||
S_Shutdown ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
memset (pData, clear, shm->samples * shm->samplebits / 8);
|
||||
|
||||
pDSBuf->lpVtbl->Unlock (pDSBuf, pData, dwSize, NULL, 0);
|
||||
|
||||
} else
|
||||
if (pDSBuf) DSOUND_ClearBuffer(clear);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
memset (shm->buffer, clear, shm->samples * shm->samplebits / 8);
|
||||
|
@ -909,21 +877,7 @@ S_Update_ (void)
|
|||
endtime = soundtime + samps;
|
||||
|
||||
#ifdef _WIN32
|
||||
// if the buffer was lost or stopped, restore it and/or restart it
|
||||
{
|
||||
DWORD dwStatus;
|
||||
|
||||
if (pDSBuf) {
|
||||
if (pDSBuf->lpVtbl->GetStatus (pDSBuf, &dwStatus) != DD_OK)
|
||||
Con_Printf ("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);
|
||||
}
|
||||
}
|
||||
if(pDSBuf) DSOUND_Restore();
|
||||
#endif
|
||||
|
||||
S_PaintChannels (endtime);
|
||||
|
|
|
@ -36,11 +36,6 @@
|
|||
#include "console.h"
|
||||
#include "sound.h"
|
||||
|
||||
// fixme: Damn crappy complier doesn't allow me to UNDEF _win32 on command line!
|
||||
#ifdef WIN32SDL
|
||||
#undef _WIN32
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "winquake.h"
|
||||
#else
|
||||
|
@ -90,43 +85,15 @@ S_TransferStereo16 (int endtime)
|
|||
int lpaintedtime;
|
||||
DWORD *pbuf;
|
||||
|
||||
#ifdef _WIN32
|
||||
int reps;
|
||||
DWORD dwSize, dwSize2;
|
||||
DWORD *pbuf2;
|
||||
HRESULT hresult;
|
||||
#endif
|
||||
|
||||
snd_vol = volume->value * 256;
|
||||
|
||||
snd_p = (int *) paintbuffer;
|
||||
lpaintedtime = paintedtime;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (pDSBuf) {
|
||||
reps = 0;
|
||||
|
||||
while ((hresult = pDSBuf->lpVtbl->Lock (pDSBuf, 0, gSndBufSize,
|
||||
(LPVOID *) & pbuf, &dwSize,
|
||||
(LPVOID *) & pbuf2, &dwSize2,
|
||||
0)) != DS_OK) {
|
||||
if (hresult != DSERR_BUFFERLOST) {
|
||||
Con_Printf
|
||||
("S_TransferStereo16: DS::Lock Sound Buffer Failed\n");
|
||||
S_Shutdown ();
|
||||
S_Startup ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (++reps > 10000) {
|
||||
Con_Printf
|
||||
("S_TransferStereo16: DS: couldn't restore buffer\n");
|
||||
S_Shutdown ();
|
||||
S_Startup ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else
|
||||
// fixme: should check for NULL pbuf value
|
||||
if (pDSBuf) pbuf=DSOUND_LockBuffer(true);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
pbuf = (DWORD *) shm->buffer;
|
||||
|
@ -152,8 +119,7 @@ S_TransferStereo16 (int endtime)
|
|||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (pDSBuf)
|
||||
pDSBuf->lpVtbl->Unlock (pDSBuf, pbuf, dwSize, NULL, 0);
|
||||
if (pDSBuf) DSOUND_LockBuffer(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -169,13 +135,6 @@ S_TransferPaintBuffer (int endtime)
|
|||
int snd_vol;
|
||||
DWORD *pbuf;
|
||||
|
||||
#ifdef _WIN32
|
||||
int reps;
|
||||
DWORD dwSize, dwSize2;
|
||||
DWORD *pbuf2;
|
||||
HRESULT hresult;
|
||||
#endif
|
||||
|
||||
if (shm->samplebits == 16 && shm->channels == 2) {
|
||||
S_TransferStereo16 (endtime);
|
||||
return;
|
||||
|
@ -189,30 +148,9 @@ S_TransferPaintBuffer (int endtime)
|
|||
snd_vol = volume->value * 256;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (pDSBuf) {
|
||||
reps = 0;
|
||||
|
||||
while ((hresult = pDSBuf->lpVtbl->Lock (pDSBuf, 0, gSndBufSize,
|
||||
(LPVOID *) & pbuf, &dwSize,
|
||||
(LPVOID *) & pbuf2, &dwSize2,
|
||||
0)) != DS_OK) {
|
||||
if (hresult != DSERR_BUFFERLOST) {
|
||||
Con_Printf
|
||||
("S_TransferPaintBuffer: DS::Lock Sound Buffer Failed\n");
|
||||
S_Shutdown ();
|
||||
S_Startup ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (++reps > 10000) {
|
||||
Con_Printf
|
||||
("S_TransferPaintBuffer: DS: couldn't restore buffer\n");
|
||||
S_Shutdown ();
|
||||
S_Startup ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else
|
||||
// fixme: should check for NULL pbuf value
|
||||
if (pDSBuf) pbuf=DSOUND_LockBuffer(true);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
pbuf = (DWORD *) shm->buffer;
|
||||
|
@ -246,20 +184,7 @@ S_TransferPaintBuffer (int endtime)
|
|||
}
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (pDSBuf) {
|
||||
DWORD dwNewpos, dwWrite;
|
||||
int il = paintedtime;
|
||||
int ir = endtime - paintedtime;
|
||||
|
||||
ir += il;
|
||||
|
||||
pDSBuf->lpVtbl->Unlock (pDSBuf, pbuf, dwSize, NULL, 0);
|
||||
|
||||
pDSBuf->lpVtbl->GetCurrentPosition (pDSBuf, &dwNewpos, &dwWrite);
|
||||
|
||||
// if ((dwNewpos >= il) && (dwNewpos <= ir))
|
||||
// Con_Printf("%d-%d p %d c\n", il, ir, dwNewpos);
|
||||
}
|
||||
if (pDSBuf) DSOUND_LockBuffer(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -37,8 +37,7 @@
|
|||
#define iDirectSoundCreate(a,b,c) pDirectSoundCreate(a,b,c)
|
||||
|
||||
HRESULT (WINAPI * pDirectSoundCreate) (GUID FAR * lpGUID,
|
||||
LPDIRECTSOUND FAR * lplpDS,
|
||||
IUnknown FAR * pUnkOuter);
|
||||
LPDIRECTSOUND FAR * lplpDS,IUnknown FAR * pUnkOuter);
|
||||
|
||||
// 64K is > 1 second at 16-bit, 22050 Hz
|
||||
#define WAV_BUFFERS 64
|
||||
|
@ -57,7 +56,6 @@ static qboolean primary_format_set;
|
|||
static int sample16;
|
||||
static int snd_sent, snd_completed;
|
||||
|
||||
|
||||
/*
|
||||
* Global variables. Must be visible to window-procedure function
|
||||
* so it can unlock and free the data block after it has been played.
|
||||
|
@ -692,3 +690,77 @@ SNDDMA_Shutdown (void)
|
|||
{
|
||||
FreeSound ();
|
||||
}
|
||||
|
||||
DWORD *
|
||||
DSOUND_LockBuffer(qboolean lockit)
|
||||
{
|
||||
int reps;
|
||||
|
||||
static DWORD dwSize;
|
||||
static DWORD dwSize2;
|
||||
static DWORD *pbuf1;
|
||||
static DWORD *pbuf2;
|
||||
HRESULT hresult;
|
||||
|
||||
if (!pDSBuf) return;
|
||||
|
||||
if (lockit) {
|
||||
reps = 0;
|
||||
while ((hresult = pDSBuf->lpVtbl->Lock (pDSBuf, 0, gSndBufSize,
|
||||
(LPVOID *) & pbuf1, &dwSize,
|
||||
(LPVOID *) & pbuf2, &dwSize2,0)) != DS_OK) {
|
||||
if (hresult != DSERR_BUFFERLOST) {
|
||||
Con_Printf
|
||||
("S_TransferStereo16: DS::Lock Sound Buffer Failed\n");
|
||||
S_Shutdown ();
|
||||
S_Startup ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (++reps > 10000) {
|
||||
Con_Printf
|
||||
("S_TransferStereo16: DS: couldn't restore buffer\n");
|
||||
S_Shutdown ();
|
||||
S_Startup ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pDSBuf->lpVtbl->Unlock (pDSBuf, pbuf1, dwSize, NULL, 0);
|
||||
pbuf1=NULL;
|
||||
pbuf2=NULL;
|
||||
dwSize=0;
|
||||
dwSize2=0;
|
||||
}
|
||||
return(pbuf1);
|
||||
}
|
||||
|
||||
void DSOUND_ClearBuffer(int clear)
|
||||
{
|
||||
DWORD *pData;
|
||||
|
||||
// fixme: this should be called with 2nd pbuf2 = NULL, dwsize =0
|
||||
pData=DSOUND_LockBuffer(true);
|
||||
memset (pData, clear, shm->samples * shm->samplebits / 8);
|
||||
DSOUND_LockBuffer(false);
|
||||
}
|
||||
|
||||
void DSOUND_Restore(void)
|
||||
{
|
||||
// if the buffer was lost or stopped, restore it and/or restart it
|
||||
DWORD dwStatus;
|
||||
|
||||
if (!pDSBuf) return;
|
||||
|
||||
if (pDSBuf->lpVtbl->GetStatus (pDSBuf, &dwStatus) != DD_OK)
|
||||
Con_Printf ("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);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue