]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_main.c
Fix Windows build of sys_unix.c
[xonotic/darkplaces.git] / snd_main.c
index 95273acf769877d84968498d89ce2142554e7770..1509d97b3369439fbd454b6fd4aef380d7219562 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;
@@ -456,7 +461,6 @@ static void S_SetChannelLayout (void)
 
 void S_Startup (void)
 {
-       qboolean fixed_speed, fixed_width, fixed_channels;
        snd_format_t chosen_fmt;
        static snd_format_t prev_render_format = {0, 0, 0};
        char* env;
@@ -468,10 +472,6 @@ void S_Startup (void)
        if (!snd_initialized.integer)
                return;
 
-       fixed_speed = false;
-       fixed_width = false;
-       fixed_channels = false;
-
        // Get the starting sound format from the cvars
        chosen_fmt.speed = snd_speed.integer;
        chosen_fmt.width = snd_width.integer;
@@ -489,7 +489,6 @@ void S_Startup (void)
 #if _MSC_VER >= 1400
                free(env);
 #endif
-               fixed_channels = true;
        }
 #if _MSC_VER >= 1400
        _dupenv_s(&env, &envlen, "QUAKE_SOUND_SPEED");
@@ -502,7 +501,6 @@ void S_Startup (void)
 #if _MSC_VER >= 1400
                free(env);
 #endif
-               fixed_speed = true;
        }
 #if _MSC_VER >= 1400
        _dupenv_s(&env, &envlen, "QUAKE_SOUND_SAMPLEBITS");
@@ -515,7 +513,6 @@ void S_Startup (void)
 #if _MSC_VER >= 1400
                free(env);
 #endif
-               fixed_width = true;
        }
 
        // Parse the command line to see if the player wants a particular sound format
@@ -523,33 +520,28 @@ void S_Startup (void)
        if (COM_CheckParm ("-sndquad") != 0)
        {
                chosen_fmt.channels = 4;
-               fixed_channels = true;
        }
 // COMMANDLINEOPTION: Sound: -sndstereo sets sound output to stereo
        else if (COM_CheckParm ("-sndstereo") != 0)
        {
                chosen_fmt.channels = 2;
-               fixed_channels = true;
        }
 // COMMANDLINEOPTION: Sound: -sndmono sets sound output to mono
        else if (COM_CheckParm ("-sndmono") != 0)
        {
                chosen_fmt.channels = 1;
-               fixed_channels = true;
        }
 // 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]);
-               fixed_speed = true;
+               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;
-               fixed_width = true;
+               chosen_fmt.width = atoi (sys.argv[i + 1]) / 8;
        }
 
 #if 0
@@ -557,7 +549,6 @@ void S_Startup (void)
        // You can't change sound speed after start time (not yet supported)
        if (prev_render_format.speed != 0)
        {
-               fixed_speed = true;
                if (chosen_fmt.speed != prev_render_format.speed)
                {
                        Con_Printf("S_Startup: sound speed has changed! This is NOT supported yet. Falling back to previous speed (%u Hz)\n",
@@ -571,39 +562,32 @@ void S_Startup (void)
        if (chosen_fmt.speed < SND_MIN_SPEED)
        {
                chosen_fmt.speed = SND_MIN_SPEED;
-               fixed_speed = false;
        }
        else if (chosen_fmt.speed > SND_MAX_SPEED)
        {
                chosen_fmt.speed = SND_MAX_SPEED;
-               fixed_speed = false;
        }
 
        if (chosen_fmt.width < SND_MIN_WIDTH)
        {
                chosen_fmt.width = SND_MIN_WIDTH;
-               fixed_width = false;
        }
     else if (chosen_fmt.width == 3)
        {
                chosen_fmt.width = 4;
-               fixed_width = false;
        }
        else if (chosen_fmt.width > SND_MAX_WIDTH)
        {
                chosen_fmt.width = SND_MAX_WIDTH;
-               fixed_width = false;
        }
 
        if (chosen_fmt.channels < SND_MIN_CHANNELS)
        {
                chosen_fmt.channels = SND_MIN_CHANNELS;
-               fixed_channels = false;
        }
        else if (chosen_fmt.channels > SND_MAX_CHANNELS)
        {
                chosen_fmt.channels = SND_MAX_CHANNELS;
-               fixed_channels = false;
        }
 
        // create the sound buffer used for sumitting the samples to the plaform-dependent module
@@ -642,7 +626,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
@@ -661,7 +645,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)
@@ -779,8 +765,8 @@ void S_Init(void)
        if (COM_CheckParm("-nosound"))
        {
                // dummy out Play and Play2 because mods stuffcmd that
-               Cmd_AddCommand(&cmd_client, "play", Host_NoOperation_f, "does nothing because -nosound was specified");
-               Cmd_AddCommand(&cmd_client, "play2", Host_NoOperation_f, "does nothing because -nosound was specified");
+               Cmd_AddCommand(CMD_CLIENT, "play", Host_NoOperation_f, "does nothing because -nosound was specified");
+               Cmd_AddCommand(CMD_CLIENT, "play2", Host_NoOperation_f, "does nothing because -nosound was specified");
                return;
        }
 
@@ -790,14 +776,14 @@ void S_Init(void)
        if (COM_CheckParm("-simsound"))
                simsound = true;
 
-       Cmd_AddCommand(&cmd_client, "play", S_Play_f, "play a sound at your current location (not heard by anyone else)");
-       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, "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");
-       Cmd_AddCommand(&cmd_client, "snd_unloadallsounds", S_UnloadAllSounds_f, "unload all sound files");
+       Cmd_AddCommand(CMD_CLIENT, "play", S_Play_f, "play a sound at your current location (not heard by anyone else)");
+       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, "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");
+       Cmd_AddCommand(CMD_CLIENT, "snd_unloadallsounds", S_UnloadAllSounds_f, "unload all sound files");
 
        Cvar_RegisterVariable(&nosound);
        Cvar_RegisterVariable(&snd_precache);
@@ -821,6 +807,9 @@ void S_Init(void)
        memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
 
        OGG_OpenLibrary ();
+#ifdef USEXMP
+       XMP_OpenLibrary ();
+#endif
 }
 
 
@@ -834,6 +823,9 @@ Shutdown and free all resources
 void S_Terminate (void)
 {
        S_Shutdown ();
+#ifdef USEXMP
+       XMP_CloseLibrary ();
+#endif
        OGG_CloseLibrary ();
 
        // Free all SFXs
@@ -1918,19 +1910,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();
        }
@@ -1964,6 +1962,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;
@@ -1982,11 +1981,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())