]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_win.c
limit entity movement lerp to 10th of a second
[xonotic/darkplaces.git] / snd_win.c
index c43f57407c3da5383679af8bd200f1bd2d3934ef..ef6703658f01c0590b20b27cf4af701691dd6af1 100644 (file)
--- a/snd_win.c
+++ b/snd_win.c
@@ -188,6 +188,7 @@ sndinitstat SNDDMA_InitDirect (void)
        WAVEFORMATEX    format, pformat; 
        HRESULT                 hresult;
        int                             reps;
+       int i;
 
        memset ((void *)&sn, 0, sizeof (sn));
 
@@ -195,18 +196,20 @@ sndinitstat SNDDMA_InitDirect (void)
 
        shm->channels = 2;
        shm->samplebits = 16;
-       shm->speed = 11025;
+       i = COM_CheckParm ("-sndspeed"); // LordHavoc: -sndspeed option
+       if (i && i != (com_argc - 1))
+               shm->speed = atoi(com_argv[i+1]);
+       else
+               shm->speed = 11025;
 
        memset (&format, 0, sizeof(format));
        format.wFormatTag = WAVE_FORMAT_PCM;
     format.nChannels = shm->channels;
     format.wBitsPerSample = shm->samplebits;
     format.nSamplesPerSec = shm->speed;
-    format.nBlockAlign = format.nChannels
-               *format.wBitsPerSample / 8;
+    format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
     format.cbSize = 0;
-    format.nAvgBytesPerSec = format.nSamplesPerSec
-               *format.nBlockAlign; 
+    format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; 
 
        if (!hInstDS)
        {
@@ -359,7 +362,7 @@ sndinitstat SNDDMA_InitDirect (void)
        if (snd_firsttime)
                Con_SafePrintf("   %d channel(s)\n"
                               "   %d bits/sample\n"
-                                          "   %d bytes/sec\n",
+                                          "   %d samples/sec\n",
                                           shm->channels, shm->samplebits, shm->speed);
        
        gSndBufSize = dsbcaps.dwBufferBytes;
@@ -386,7 +389,6 @@ sndinitstat SNDDMA_InitDirect (void)
        }
 
        memset(lpData, 0, dwSize);
-//             lpData[4] = lpData[5] = 0x7f;   // force a pop for debugging
 
        pDSBuf->lpVtbl->Unlock(pDSBuf, lpData, dwSize, NULL, 0);
 
@@ -431,7 +433,11 @@ qboolean SNDDMA_InitWav (void)
 
        shm->channels = 2;
        shm->samplebits = 16;
-       shm->speed = 11025;
+       i = COM_CheckParm ("-sndspeed"); // LordHavoc: -sndspeed option
+       if (i && i != (com_argc - 1))
+               shm->speed = atoi(com_argv[i+1]);
+       else
+               shm->speed = 11025;
 
        memset (&format, 0, sizeof(format));
        format.wFormatTag = WAVE_FORMAT_PCM;
@@ -612,12 +618,7 @@ qboolean SNDDMA_Init(void)
        snd_firsttime = false;
 
        if (!dsound_init && !wav_init)
-       {
-//             if (snd_firsttime)
-//                     Con_SafePrintf ("No sound device initialized\n");
-
                return 0;
-       }
 
        return 1;
 }
@@ -647,6 +648,8 @@ int SNDDMA_GetDMAPos(void)
        {
                s = snd_sent * WAV_BUFFER_SIZE;
        }
+       else
+               s = 0;
 
 
        s >>= sample16;
@@ -698,19 +701,19 @@ void SNDDMA_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)); 
+               /*
+                * 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)
-               { 
+               {
                        Con_SafePrintf ("Failed to write block to device\n");
                        FreeSound ();
-                       return; 
-               } 
+                       return;
+               }
        }
 }
 
@@ -726,3 +729,53 @@ void SNDDMA_Shutdown(void)
        FreeSound ();
 }
 
+DWORD dsound_dwSize;
+DWORD dsound_dwSize2;
+DWORD *dsound_pbuf;
+DWORD *dsound_pbuf2;
+void *S_LockBuffer(void)
+{
+       int reps;
+       HRESULT hresult;
+
+       if (pDSBuf)
+       {
+               reps = 0;
+
+               while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &dsound_pbuf, &dsound_dwSize, &dsound_pbuf2, &dsound_dwSize2, 0)) != DS_OK)
+               {
+                       if (hresult != DSERR_BUFFERLOST)
+                       {
+                               Con_Printf ("S_LockBuffer: DS::Lock Sound Buffer Failed\n");
+                               S_Shutdown ();
+                               S_Startup ();
+                               return NULL;
+                       }
+
+                       if (++reps > 10000)
+                       {
+                               Con_Printf ("S_LockBuffer: DS: couldn't restore buffer\n");
+                               S_Shutdown ();
+                               S_Startup ();
+                               return NULL;
+                       }
+               }
+               return dsound_pbuf;
+       }
+       else
+               return shm->buffer;
+}
+
+void S_UnlockBuffer(void)
+{
+       if (pDSBuf)
+               pDSBuf->lpVtbl->Unlock(pDSBuf, dsound_pbuf, dsound_dwSize, dsound_pbuf2, dsound_dwSize2);
+}
+
+void S_Open(void)
+{
+}
+
+void S_Close(void)
+{
+}