22 #include "../client/client.h"
23 #include "../client/snd_loc.h"
26 #define iDirectSoundCreate(a,b,c) pDirectSoundCreate(a,b,c)
31 #define WAV_BUFFERS 64
33 #define WAV_BUFFER_SIZE 0x0400
34 #define SECONDARY_BUFFER_SIZE 0x10000
84 case DSERR_BUFFERLOST:
85 return "DSERR_BUFFERLOST";
86 case DSERR_INVALIDCALL:
87 return "DSERR_INVALIDCALLS";
88 case DSERR_INVALIDPARAM:
89 return "DSERR_INVALIDPARAM";
90 case DSERR_PRIOLEVELNEEDED:
91 return "DSERR_PRIOLEVELNEEDED";
104 WAVEFORMATEX pformat,
format;
108 format.wFormatTag = WAVE_FORMAT_PCM;
119 if ( DS_OK !=
pDS->lpVtbl->SetCooperativeLevel(
pDS,
cl_hwnd, DSSCL_EXCLUSIVE ) )
129 memset (&dsbuf, 0,
sizeof(dsbuf));
130 dsbuf.dwSize =
sizeof(DSBUFFERDESC);
131 dsbuf.dwFlags = DSBCAPS_PRIMARYBUFFER;
132 dsbuf.dwBufferBytes = 0;
133 dsbuf.lpwfxFormat =
NULL;
135 memset(&dsbcaps, 0,
sizeof(dsbcaps));
136 dsbcaps.dwSize =
sizeof(dsbcaps);
148 Com_DPrintf (
"...setting primary sound format: failed\n");
153 Com_DPrintf (
"...setting primary sound format: ok\n");
164 memset (&dsbuf, 0,
sizeof(dsbuf));
165 dsbuf.dwSize =
sizeof(DSBUFFERDESC);
166 dsbuf.dwFlags = DSBCAPS_CTRLFREQUENCY | DSBCAPS_LOCSOFTWARE;
168 dsbuf.lpwfxFormat = &
format;
170 memset(&dsbcaps, 0,
sizeof(dsbcaps));
171 dsbcaps.dwSize =
sizeof(dsbcaps);
186 if (DS_OK !=
pDSBuf->lpVtbl->GetCaps (
pDSBuf, &dsbcaps))
193 Com_Printf (
"...using secondary sound buffer\n");
199 Com_DPrintf(
"...setting WRITEPRIMARY coop level: " );
200 if (DS_OK !=
pDS->lpVtbl->SetCooperativeLevel (
pDS,
cl_hwnd, DSSCL_WRITEPRIMARY))
253 pDS->lpVtbl->SetCooperativeLevel(
pDS,
cl_hwnd, DSSCL_NORMAL );
258 Com_DPrintf(
"...stopping and releasing sound buffer\n" );
323 pDS->lpVtbl->Release(
pDS );
373 hInstDS = LoadLibrary(
"dsound.dll");
382 pDirectSoundCreate = (
void *)GetProcAddress(
hInstDS,
"DirectSoundCreate");
384 if (!pDirectSoundCreate)
386 Com_Printf (
"*** couldn't get DS proc addr ***\n");
394 if (hresult != DSERR_ALLOCATED)
400 if (MessageBox (
NULL,
401 "The sound hardware is in use by another app.\n\n"
402 "Select Retry to try to start sound again or Cancel to run Quake with no sound.",
403 "Sound not available",
404 MB_RETRYCANCEL | MB_SETFOREGROUND | MB_ICONEXCLAMATION) != IDRETRY)
406 Com_Printf (
"failed, hardware already in use\n" );
412 dscaps.dwSize =
sizeof(dscaps);
414 if ( DS_OK !=
pDS->lpVtbl->GetCaps(
pDS, &dscaps ) )
416 Com_Printf (
"*** couldn't get DS caps ***\n");
419 if ( dscaps.dwFlags & DSCAPS_EMULDRIVER )
466 format.wFormatTag = WAVE_FORMAT_PCM;
471 *
format.wBitsPerSample / 8;
478 while ((hr = waveOutOpen((LPHWAVEOUT)&
hWaveOut, WAVE_MAPPER,
480 0, 0
L, CALLBACK_NULL)) != MMSYSERR_NOERROR)
482 if (hr != MMSYSERR_ALLOCATED)
488 if (MessageBox (
NULL,
489 "The sound hardware is in use by another app.\n\n"
490 "Select Retry to try to start sound again or Cancel to run Quake 2 with no sound.",
491 "Sound not available",
492 MB_RETRYCANCEL | MB_SETFOREGROUND | MB_ICONEXCLAMATION) != IDRETRY)
534 hWaveHdr = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE,
597 memset ((
void *)&
dma, 0,
sizeof (
dma));
657 Com_Printf (
"*** No sound device initialized ***\n");
682 mmtime.wType = TIME_SAMPLES;
683 pDSBuf->lpVtbl->GetCurrentPosition(
pDSBuf, &mmtime.u.sample, &dwWrite);
719 if (
pDSBuf->lpVtbl->GetStatus (
pDSBuf, &dwStatus) != DS_OK)
720 Com_Printf (
"Couldn't get sound buffer status\n");
722 if (dwStatus & DSBSTATUS_BUFFERLOST)
725 if (!(dwStatus & DSBSTATUS_PLAYING))
734 &pbuf2, &dwSize2, 0)) != DS_OK)
736 if (hresult != DSERR_BUFFERLOST)
811 wResult = waveOutWrite(
hWaveOut, h,
sizeof(WAVEHDR));
813 if (wResult != MMSYSERR_NOERROR)
815 Com_Printf (
"Failed to write block to device\n");