Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include "quakedef.h"
-#include "snd_main.h"
#ifdef SUPPORTDIRECTX
#ifndef DIRECTSOUND_VERSION
#include <dsound.h>
#endif
+#include "qtypes.h"
+#include "quakedef.h"
+#include "snd_main.h"
+
// ==============================================================================
#ifndef _WAVEFORMATEXTENSIBLE_
// ==============================================================================
extern HWND mainwindow;
+static cvar_t snd_wav_partitionsize = {CVAR_SAVE, "snd_wav_partitionsize", "1024", "controls sound delay in samples, values too low will cause crackling, too high will cause delayed sounds"};
+static qboolean sndsys_registeredcvars = false;
#ifdef SUPPORTDIRECTX
HRESULT (WINAPI *pDirectSoundCreate)(GUID FAR *lpGUID, LPDIRECTSOUND FAR *lplpDS, IUnknown FAR *pUnkOuter);
#endif
-// Wave output: how much buffer time, and how many partitions in that time
-#define WAV_BUFFERTIME 0.125
+// Wave output: queue of this many sound buffers to play, reused cyclically
#define WAV_BUFFERS 16
#define WAV_MASK (WAV_BUFFERS - 1)
static unsigned int wav_buffer_size;
return SIS_FAILURE;
}
- pDirectSoundCreate = (void *)GetProcAddress(hInstDS,"DirectSoundCreate");
+ pDirectSoundCreate = (HRESULT (__stdcall *)(GUID *, LPDIRECTSOUND *,IUnknown *))GetProcAddress(hInstDS,"DirectSoundCreate");
if (!pDirectSoundCreate)
{
}
}
- wav_buffer_size = ((int)(requested->speed * WAV_BUFFERTIME) / WAV_BUFFERS) * requested->channels * requested->width;
+ wav_buffer_size = bound(128, snd_wav_partitionsize.integer, 8192) * requested->channels * requested->width;
/*
* Allocate and lock memory for the waveform data. The memory
SndSys_Shutdown ();
return false;
}
- lpData = GlobalLock(hData);
+ lpData = (HPSTR)GlobalLock(hData);
if (!lpData)
{
Con_Print("Sound: Failed to lock.\n");
#endif
sndinitstat stat;
+ if (!sndsys_registeredcvars)
+ {
+ sndsys_registeredcvars = true;
+ Cvar_RegisterVariable(&snd_wav_partitionsize);
+ }
+
Con_Print ("SndSys_Init: using the Win32 module\n");
#ifdef SUPPORTDIRECTX
snd_sent++;
else if (wResult == WAVERR_STILLPLAYING)
{
- if(developer.integer >= 1000)
- Con_Print("waveOutWrite failed (too much sound data)\n");
+ if(developer_insane.integer)
+ Con_DPrint("waveOutWrite failed (too much sound data)\n");
//h->dwFlags |= WHDR_DONE;
//snd_sent++;
}
unsigned int SndSys_GetSoundTime (void)
{
unsigned int factor;
- MMRESULT res;
- MMTIME mmtime;
factor = snd_renderbuffer->format.width * snd_renderbuffer->format.channels;
if (wav_init)
{
- /*
// Find which sound blocks have completed
for (;;)
{
if (snd_completed == snd_sent)
{
- Con_DPrint("Sound overrun\n");
+ // Con_DPrint("Sound overrun\n");
break;
}
}
return (snd_completed * wav_buffer_size) / factor;
- */
+
+ /*
+ * S_PaintAndSubmit: WARNING: newsoundtime (soundtime (275 < 134217707)
+ * apparently this sound time wraps quite early?
+ {
+ MMRESULT res;
+ MMTIME mmtime;
mmtime.wType = TIME_SAMPLES;
res = waveOutGetPosition(hWaveOut, &mmtime, sizeof(mmtime));
if(res == MMSYSERR_NOERROR)
return mmtime.u.sample;
+ }
+ */
}
return 0;
IDirectSoundBuffer_Unlock(pDSBuf, dsound_pbuf, dsound_dwSize, dsound_pbuf2, dsound_dwSize2);
#endif
}
+
+/*
+====================
+SndSys_SendKeyEvents
+
+Send keyboard events originating from the sound system (e.g. MIDI)
+====================
+*/
+void SndSys_SendKeyEvents(void)
+{
+ // not supported
+}