]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_mem.c
use dynamic eye position-centered bouncegrid when rendering in dynamic
[xonotic/darkplaces.git] / snd_mem.c
index adb296ff2ddfdfa74723d54597d9912e9a7c30cc..75f9e829560df539cc84e5a1a543d092da4a410e 100644 (file)
--- a/snd_mem.c
+++ b/snd_mem.c
@@ -24,6 +24,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "snd_main.h"
 #include "snd_ogg.h"
 #include "snd_wav.h"
+#include "snd_modplug.h"
+
+unsigned char resampling_buffer [48000 * 2 * 2];
 
 
 /*
@@ -58,12 +61,12 @@ snd_ringbuffer_t *Snd_CreateRingBuffer (const snd_format_t* format, unsigned int
                        maxframes = sampleframes;
 
                memsize = maxframes * format->width * format->channels;
-               ringbuffer->ring = Mem_Alloc(snd_mempool, memsize);
+               ringbuffer->ring = (unsigned char *) Mem_Alloc(snd_mempool, memsize);
                ringbuffer->maxframes = maxframes;
        }
        else
        {
-               ringbuffer->ring = buffer;
+               ringbuffer->ring = (unsigned char *) buffer;
                ringbuffer->maxframes = sampleframes;
        }
 
@@ -81,7 +84,7 @@ snd_buffer_t *Snd_CreateSndBuffer (const unsigned char *samples, unsigned int sa
        size_t newsampleframes, memsize;
        snd_buffer_t* sb;
 
-       newsampleframes = (double)sampleframes * (double)sb_speed / (double)in_format->speed;
+       newsampleframes = (size_t) ((double)sampleframes * (double)sb_speed / (double)in_format->speed);
 
        memsize = newsampleframes * in_format->channels * in_format->width;
        memsize += sizeof (*sb) - sizeof (sb->samples);
@@ -123,7 +126,7 @@ qboolean Snd_AppendToSndBuffer (snd_buffer_t* sb, const unsigned char *samples,
                return false;
        }
 
-       outcount = (double)sampleframes * (double)sb->format.speed / (double)format->speed;
+       outcount = (size_t) ((double)sampleframes * (double)sb->format.speed / (double)format->speed);
 
        // If the sound buffer is too short
        if (outcount > sb->maxframes - sb->nbframes)
@@ -322,42 +325,66 @@ qboolean S_LoadSound (sfx_t *sfx, qboolean complain)
        // Initialize volume peak to 0; if ReplayGain is supported, the loader will change this away
        sfx->volume_peak = 0.0;
 
+       if (developer_loading.integer)
+               Con_Printf("loading sound %s\n", sfx->name);
+
+       SCR_PushLoadingScreen(true, sfx->name, 1);
+
        // LordHavoc: if the sound filename does not begin with sound/, try adding it
        if (strncasecmp(sfx->name, "sound/", 6))
        {
-               len = dpsnprintf (namebuffer, sizeof(namebuffer), "sound/%s", sfx->name);
-               if (len < 0)
-               {
-                       // name too long
-                       Con_DPrintf("S_LoadSound: name \"%s\" is too long\n", sfx->name);
-                       return false;
-               }
-               if (S_LoadWavFile (namebuffer, sfx))
-                       return true;
+               dpsnprintf (namebuffer, sizeof(namebuffer), "sound/%s", sfx->name);
+               len = strlen(namebuffer);
                if (len >= 4 && !strcasecmp (namebuffer + len - 4, ".wav"))
+               {
+                       if (S_LoadWavFile (namebuffer, sfx))
+                               goto loaded;
                        memcpy (namebuffer + len - 3, "ogg", 4);
-               if (OGG_LoadVorbisFile (namebuffer, sfx))
-                       return true;
+               }
+               if (len >= 4 && !strcasecmp (namebuffer + len - 4, ".ogg"))
+               {
+                       if (OGG_LoadVorbisFile (namebuffer, sfx))
+                               goto loaded;
+               }
+               else
+               {
+                       if (ModPlug_LoadModPlugFile (namebuffer, sfx))
+                               goto loaded;
+               }
        }
 
        // LordHavoc: then try without the added sound/ as wav and ogg
-       len = dpsnprintf (namebuffer, sizeof(namebuffer), "%s", sfx->name);
-       if (len < 0)
-       {
-               // name too long
-               Con_DPrintf("S_LoadSound: name \"%s\" is too long\n", sfx->name);
-               return false;
-       }
-       if (S_LoadWavFile (namebuffer, sfx))
-               return true;
+       dpsnprintf (namebuffer, sizeof(namebuffer), "%s", sfx->name);
+       len = strlen(namebuffer);
+       // request foo.wav: tries foo.wav, then foo.ogg
+       // request foo.ogg: tries foo.ogg only
+       // request foo.mod: tries foo.mod only
        if (len >= 4 && !strcasecmp (namebuffer + len - 4, ".wav"))
+       {
+               if (S_LoadWavFile (namebuffer, sfx))
+                       goto loaded;
                memcpy (namebuffer + len - 3, "ogg", 4);
-       if (OGG_LoadVorbisFile (namebuffer, sfx))
-               return true;
+       }
+       if (len >= 4 && !strcasecmp (namebuffer + len - 4, ".ogg"))
+       {
+               if (OGG_LoadVorbisFile (namebuffer, sfx))
+                       goto loaded;
+       }
+       else
+       {
+               if (ModPlug_LoadModPlugFile (namebuffer, sfx))
+                       goto loaded;
+       }
 
        // Can't load the sound!
        sfx->flags |= SFXFLAG_FILEMISSING;
        if (complain)
-               Con_DPrintf("S_LoadSound: Couldn't load \"%s\"\n", sfx->name);
+               Con_DPrintf("failed to load sound \"%s\"\n", sfx->name);
+
+       SCR_PopLoadingScreen(false);
        return false;
+
+loaded:
+       SCR_PopLoadingScreen(false);
+       return true;
 }