X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=snd_win.c;h=080122487a821d438a0e25eaad3070e4139294f0;hp=c61804730a7de28f4d1c911364e4abfc31e8151e;hb=2bac60709c4346c472301edf43d1723a72369450;hpb=85ff1e4d0bb64c1f3d856d5ed661cc18c453db75 diff --git a/snd_win.c b/snd_win.c index c6180473..08012248 100644 --- a/snd_win.c +++ b/snd_win.c @@ -17,8 +17,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "quakedef.h" -#include "snd_main.h" #ifdef SUPPORTDIRECTX #ifndef DIRECTSOUND_VERSION @@ -31,6 +29,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #endif +#include "qtypes.h" +#include "quakedef.h" +#include "snd_main.h" + // ============================================================================== #ifndef _WAVEFORMATEXTENSIBLE_ @@ -82,14 +84,15 @@ static const GUID MY_KSDATAFORMAT_SUBTYPE_PCM = // ============================================================================== 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: 64KB in 64 buffers of 1KB -// (64KB is > 1 sec at 16-bit 22050 Hz mono, and is 1/3 sec at 16-bit 44100 Hz stereo) -#define WAV_BUFFERS 64 +// 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; @@ -237,7 +240,7 @@ static sndinitstat SndSys_InitDirectSound (const snd_format_t* requested) return SIS_FAILURE; } - pDirectSoundCreate = (void *)GetProcAddress(hInstDS,"DirectSoundCreate"); + pDirectSoundCreate = (HRESULT (__stdcall *)(GUID *, LPDIRECTSOUND *,IUnknown *))GetProcAddress(hInstDS,"DirectSoundCreate"); if (!pDirectSoundCreate) { @@ -458,7 +461,7 @@ static qboolean SndSys_InitMmsystem (const snd_format_t* requested) } } - wav_buffer_size = (requested->speed / 2 / 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 @@ -473,7 +476,7 @@ static qboolean SndSys_InitMmsystem (const snd_format_t* requested) SndSys_Shutdown (); return false; } - lpData = GlobalLock(hData); + lpData = (HPSTR)GlobalLock(hData); if (!lpData) { Con_Print("Sound: Failed to lock.\n"); @@ -550,6 +553,12 @@ qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested) #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 @@ -699,20 +708,26 @@ void SndSys_Submit (void) { h = lpWaveHdr + (snd_sent & WAV_MASK); - snd_sent++; /* * Now the data block can be sent to the output device. The * waveOutWrite function returns immediately and waveform * data is sent to the output device in the background. */ wResult = waveOutWrite(hWaveOut, h, sizeof(WAVEHDR)); - - if (wResult != MMSYSERR_NOERROR) + if (wResult == MMSYSERR_NOERROR) + snd_sent++; + else if (wResult == WAVERR_STILLPLAYING) + { + if(developer_insane.integer) + Con_DPrint("waveOutWrite failed (too much sound data)\n"); + //h->dwFlags |= WHDR_DONE; + //snd_sent++; + } + else { - if (developer.integer >= 1000) - Con_Print("waveOutWrite failed (too much sound data)\n"); - //SndSys_Shutdown (); - //return; + Con_Printf("waveOutWrite failed, error code %d\n", (int) wResult); + SndSys_Shutdown (); + return; } paintpot -= wav_buffer_size; @@ -756,7 +771,7 @@ unsigned int SndSys_GetSoundTime (void) { if (snd_completed == snd_sent) { - Con_DPrint("Sound overrun\n"); + // Con_DPrint("Sound overrun\n"); break; } @@ -767,6 +782,20 @@ unsigned int SndSys_GetSoundTime (void) } 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; @@ -854,3 +883,15 @@ void SndSys_UnlockRenderBuffer (void) 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 +}