]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_main.c
progs: Implement new extension DP_QC_FS_SEARCH_PACKFILE
[xonotic/darkplaces.git] / snd_main.c
index 9f8b748ea7b6cf9d93ab52e124fc2be551d5c5cc..33c3a08bd1e958c665294288fb1883002c68cc59 100644 (file)
@@ -23,6 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "snd_main.h"
 #include "snd_ogg.h"
+#ifdef USEXMP
+#include "snd_xmp.h"
+#endif
 #include "csprogs.h"
 #include "cl_collision.h"
 #include "cdaudio.h"
@@ -147,7 +150,9 @@ static qboolean sound_spatialized = false;
 
 qboolean simsound = false;
 
+#ifdef CONFIG_VIDEO_CAPTURE
 static qboolean recording_sound = false;
+#endif
 
 int snd_blocked = 0;
 static int current_swapstereo = false;
@@ -359,6 +364,14 @@ static void S_SoundInfo_f(cmd_state_t *cmd)
        Con_Printf("%5u total_channels\n", total_channels);
 }
 
+static void S_PauseSound_f(cmd_state_t *cmd)
+{
+       if( Cmd_Argc(cmd) != 2 ) {
+               Con_Print("pausesound <pause>\n");
+               return;
+       }
+       S_PauseGameSounds(atoi( Cmd_Argv(cmd, 1 ) ) != 0);
+}
 
 int S_GetSoundRate(void)
 {
@@ -370,6 +383,11 @@ int S_GetSoundChannels(void)
        return snd_renderbuffer ? snd_renderbuffer->format.channels : 0;
 }
 
+int S_GetSoundWidth(void)
+{
+       return snd_renderbuffer ? snd_renderbuffer->format.width : 0;
+}
+
 
 #define SWAP_LISTENERS(l1, l2, tmpl) { tmpl = (l1); (l1) = (l2); (l2) = tmpl; }
 
@@ -528,15 +546,15 @@ void S_Startup (void)
        }
 // COMMANDLINEOPTION: Sound: -sndspeed <hz> chooses sound output rate (supported values are 48000, 44100, 32000, 24000, 22050, 16000, 11025 (quake), 8000)
        i = COM_CheckParm ("-sndspeed");
-       if (0 < i && i < com_argc - 1)
+       if (0 < i && i < sys.argc - 1)
        {
-               chosen_fmt.speed = atoi (com_argv[i + 1]);
+               chosen_fmt.speed = atoi (sys.argv[i + 1]);
        }
 // COMMANDLINEOPTION: Sound: -sndbits <bits> chooses 8 bit or 16 bit or 32bit float sound output
        i = COM_CheckParm ("-sndbits");
-       if (0 < i && i < com_argc - 1)
+       if (0 < i && i < sys.argc - 1)
        {
-               chosen_fmt.width = atoi (com_argv[i + 1]) / 8;
+               chosen_fmt.width = atoi (sys.argv[i + 1]) / 8;
        }
 
 #if 0
@@ -567,7 +585,7 @@ void S_Startup (void)
        {
                chosen_fmt.width = SND_MIN_WIDTH;
        }
-    else if (chosen_fmt.width == 3)
+       else if (chosen_fmt.width == 3)
        {
                chosen_fmt.width = 4;
        }
@@ -621,7 +639,7 @@ void S_Startup (void)
        current_channellayout_used = SND_CHANNELLAYOUT_AUTO;
        S_SetChannelLayout();
 
-       snd_starttime = realtime;
+       snd_starttime = host.realtime;
 
        // If the sound module has already run, add an extra time to make sure
        // the sound time doesn't decrease, to not confuse playing SFXs
@@ -640,7 +658,9 @@ void S_Startup (void)
                extrasoundtime = 0;
        snd_renderbuffer->startframe = soundtime;
        snd_renderbuffer->endframe = soundtime;
+#ifdef CONFIG_VIDEO_CAPTURE
        recording_sound = false;
+#endif
 }
 
 void S_Shutdown(void)
@@ -773,6 +793,7 @@ void S_Init(void)
        Cmd_AddCommand(CMD_CLIENT, "play2", S_Play2_f, "play a sound globally throughout the level (not heard by anyone else)");
        Cmd_AddCommand(CMD_CLIENT, "playvol", S_PlayVol_f, "play a sound at the specified volume level at your current location (not heard by anyone else)");
        Cmd_AddCommand(CMD_CLIENT, "stopsound", S_StopAllSounds_f, "silence");
+       Cmd_AddCommand(CMD_CLIENT, "pausesound", S_PauseSound_f, "temporary silence");
        Cmd_AddCommand(CMD_CLIENT, "soundlist", S_SoundList_f, "list loaded sounds");
        Cmd_AddCommand(CMD_CLIENT, "soundinfo", S_SoundInfo_f, "print sound system information (such as channels and speed)");
        Cmd_AddCommand(CMD_CLIENT, "snd_restart", S_Restart_f, "restart sound system");
@@ -800,6 +821,9 @@ void S_Init(void)
        memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
 
        OGG_OpenLibrary ();
+#ifdef USEXMP
+       XMP_OpenLibrary ();
+#endif
 }
 
 
@@ -813,6 +837,9 @@ Shutdown and free all resources
 void S_Terminate (void)
 {
        S_Shutdown ();
+#ifdef USEXMP
+       XMP_CloseLibrary ();
+#endif
        OGG_CloseLibrary ();
 
        // Free all SFXs
@@ -1897,19 +1924,25 @@ static void S_PaintAndSubmit (void)
                usesoundtimehack = 1;
                newsoundtime = (unsigned int)((double)cl.mtime[0] * (double)snd_renderbuffer->format.speed);
        }
+#ifdef CONFIG_VIDEO_CAPTURE
        else if (cls.capturevideo.soundrate && !cls.capturevideo.realtime) // SUPER NASTY HACK to record non-realtime sound
        {
                usesoundtimehack = 2;
                newsoundtime = (unsigned int)((double)cls.capturevideo.frame * (double)snd_renderbuffer->format.speed / (double)cls.capturevideo.framerate);
        }
+#endif
        else if (simsound)
        {
                usesoundtimehack = 3;
-               newsoundtime = (unsigned int)((realtime - snd_starttime) * (double)snd_renderbuffer->format.speed);
+               newsoundtime = (unsigned int)((host.realtime - snd_starttime) * (double)snd_renderbuffer->format.speed);
        }
        else
        {
+#ifdef CONFIG_VIDEO_CAPTURE
                snd_usethreadedmixing = snd_threaded && !cls.capturevideo.soundrate;
+#else
+               snd_usethreadedmixing = snd_threaded;
+#endif
                usesoundtimehack = 0;
                newsoundtime = SndSys_GetSoundTime();
        }
@@ -1943,6 +1976,7 @@ static void S_PaintAndSubmit (void)
        newsoundtime += extrasoundtime;
        if (newsoundtime < soundtime)
        {
+#ifdef CONFIG_VIDEO_CAPTURE
                if ((cls.capturevideo.soundrate != 0) != recording_sound)
                {
                        unsigned int additionaltime;
@@ -1961,11 +1995,16 @@ static void S_PaintAndSubmit (void)
                                                extrasoundtime);
                }
                else if (!soundtimehack)
+#else
+               if (!soundtimehack)
+#endif
                        Con_Printf("S_PaintAndSubmit: WARNING: newsoundtime < soundtime (%u < %u)\n",
                                           newsoundtime, soundtime);
        }
        soundtime = newsoundtime;
+#ifdef CONFIG_VIDEO_CAPTURE
        recording_sound = (cls.capturevideo.soundrate != 0);
+#endif
 
        // Lock submitbuffer
        if (!simsound && !SndSys_LockRenderBuffer())