20 #include "client/sound/dma.h"
24 #define WAV_BUFFERS 64
25 #define WAV_MASK (WAV_BUFFERS - 1)
26 #define WAV_BUFFER_SIZE 0x0400
55 Com_Printf(
"Shutting down wave sound\n");
58 Com_DPrintf(
"...resetting waveOut\n");
62 Com_DPrintf(
"...unpreparing headers\n");
67 Com_DPrintf(
"...closing waveOut\n");
71 Com_DPrintf(
"...freeing WAV header\n");
77 Com_DPrintf(
"...freeing WAV buffer\n");
106 Com_DPrintf(
"Initializing wave sound\n");
111 memset(&
dma, 0,
sizeof(
dma));
115 if (
s_khz->integer == 44)
117 else if (
s_khz->integer == 22)
122 memset(&format, 0,
sizeof(format));
123 format.wFormatTag = WAVE_FORMAT_PCM;
124 format.nChannels =
dma.channels;
125 format.wBitsPerSample =
dma.samplebits;
126 format.nSamplesPerSec =
dma.speed;
127 format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
129 format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
132 Com_DPrintf(
"...opening waveform device: ");
133 while ((hr = waveOutOpen((LPHWAVEOUT)&
hWaveOut, WAVE_MAPPER,
135 0, 0
L, CALLBACK_NULL)) != MMSYSERR_NOERROR) {
136 if (hr != MMSYSERR_ALLOCATED) {
137 Com_DPrintf(
"failed\n");
142 _T(
"The sound hardware is in use by another app.\n\n")
143 _T(
"Select Retry to try to start sound again or Cancel to run ") _T(
"q2pro") _T(
" with no sound."),
144 _T(
"Sound not available"),
145 MB_RETRYCANCEL | MB_SETFOREGROUND | MB_ICONEXCLAMATION) != IDRETRY) {
146 Com_DPrintf(
"hw in use\n");
158 Com_DPrintf(
"...allocating waveform buffer: ");
162 Com_DPrintf(
" failed with error %#lx\n", GetLastError());
168 Com_DPrintf(
"...locking waveform buffer: ");
171 Com_DPrintf(
" failed with error %#lx\n", GetLastError());
183 Com_DPrintf(
"...allocating waveform header: ");
184 hWaveHdr = GlobalAlloc(GMEM_MOVEABLE ,
187 Com_DPrintf(
"failed with error %#lx\n", GetLastError());
193 Com_DPrintf(
"...locking waveform header: ");
196 Com_DPrintf(
"failed with error %#lx\n", GetLastError());
204 Com_DPrintf(
"...preparing headers: ");
211 Com_DPrintf(
"failed\n");
220 dma.submission_chunk = 512;
224 Com_Printf(
"Wave sound initialized\n");
250 dma.samplepos = s & (
dma.samples - 1);
277 Com_DPrintf(
"WAVE_Submit: Sound overrun\n");
301 wResult = waveOutWrite(
hWaveOut, h,
sizeof(WAVEHDR));
303 if (wResult != MMSYSERR_NOERROR) {
304 Com_EPrintf(
"WAVE_Submit: Failed to write block to device\n");