]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_win.c
S_LoadSound now automatically tries both with and without sound/ when loading sounds...
[xonotic/darkplaces.git] / snd_win.c
index 0fec464b841422c9ecb69ba0f3a222549aa5e985..89b885bacf90720bf122f9b350515547f4cfc62a 100644 (file)
--- a/snd_win.c
+++ b/snd_win.c
@@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 */
 #include "quakedef.h"
+#include "snd_main.h"
 #include <windows.h>
 #include <dsound.h>
 
@@ -196,7 +197,8 @@ sndinitstat SNDDMA_InitDirect (void)
        memset((void *)shm, 0, sizeof(*shm));
        shm->format.channels = 2;
        shm->format.width = 2;
-       i = COM_CheckParm ("-sndspeed"); // LordHavoc: -sndspeed option
+// COMMANDLINEOPTION: Windows Sound: -sndspeed <hz> chooses 44100 hz, 22100 hz, or 11025 hz sound output rate
+       i = COM_CheckParm ("-sndspeed");
        if (i && i != (com_argc - 1))
                shm->format.speed = atoi(com_argv[i+1]);
        else
@@ -282,6 +284,7 @@ sndinitstat SNDDMA_InitDirect (void)
        dsbcaps.dwSize = sizeof(dsbcaps);
        primary_format_set = false;
 
+// COMMANDLINEOPTION: Windows DirectSound: -snoforceformat uses the format that DirectSound returns, rather than forcing it
        if (!COM_CheckParm ("-snoforceformat"))
        {
                if (DS_OK == pDS->lpVtbl->CreateSoundBuffer(pDS, &dsbuf, &pDSPBuf, NULL))
@@ -303,6 +306,7 @@ sndinitstat SNDDMA_InitDirect (void)
                }
        }
 
+// COMMANDLINEOPTION: Windows DirectSound: -primarysound locks the sound hardware for exclusive use
        if (!primary_format_set || !COM_CheckParm ("-primarysound"))
        {
        // create the secondary buffer we'll actually work with
@@ -366,7 +370,7 @@ sndinitstat SNDDMA_InitDirect (void)
 
        gSndBufSize = dsbcaps.dwBufferBytes;
 
-// initialize the buffer
+       // initialize the buffer
        reps = 0;
 
        while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, (LPVOID*)&lpData, &dwSize, NULL, NULL, 0)) != DS_OK)
@@ -428,7 +432,8 @@ qboolean SNDDMA_InitWav (void)
        memset((void *)shm, 0, sizeof(*shm));
        shm->format.channels = 2;
        shm->format.width = 2;
-       i = COM_CheckParm ("-sndspeed"); // LordHavoc: -sndspeed option
+// COMMANDLINEOPTION: Windows Sound: -sndspeed <hz> chooses 44100 hz, 22100 hz, or 11025 hz sound output rate
+       i = COM_CheckParm ("-sndspeed");
        if (i && i != (com_argc - 1))
                shm->format.speed = atoi(com_argv[i+1]);
        else
@@ -554,6 +559,7 @@ qboolean SNDDMA_Init(void)
 {
        sndinitstat     stat;
 
+// COMMANDLINEOPTION: Windows Sound: -wavonly uses wave sound instead of DirectSound
        if (COM_CheckParm ("-wavonly"))
                wavonly = true;
 
@@ -728,16 +734,27 @@ void *S_LockBuffer(void)
 {
        int reps;
        HRESULT hresult;
+       DWORD   dwStatus;
 
        if (pDSBuf)
        {
+               // if the buffer was lost or stopped, restore it and/or restart it
+               if (pDSBuf->lpVtbl->GetStatus (pDSBuf, &dwStatus) != DS_OK)
+                       Con_Print("Couldn't get sound buffer status\n");
+
+               if (dwStatus & DSBSTATUS_BUFFERLOST)
+                       pDSBuf->lpVtbl->Restore (pDSBuf);
+
+               if (!(dwStatus & DSBSTATUS_PLAYING))
+                       pDSBuf->lpVtbl->Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);
+
                reps = 0;
 
                while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, (LPVOID*)&dsound_pbuf, &dsound_dwSize, (LPVOID*)&dsound_pbuf2, &dsound_dwSize2, 0)) != DS_OK)
                {
                        if (hresult != DSERR_BUFFERLOST)
                        {
-                               Con_Print("S_LockBuffer: DS::Lock Sound Buffer Failed\n");
+                               Con_Print("S_LockBuffer: DS: Lock Sound Buffer Failed\n");
                                S_Shutdown ();
                                S_Startup ();
                                return NULL;