]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_mem.c
fixed -tenebrae support, added glass and mirror rendering and caulk
[xonotic/darkplaces.git] / snd_mem.c
index 15e571b37c1a368b185ff034a755b4df453ca86f..a6cb234e69ca2f1d08e4e05b9b3121b910f677b2 100644 (file)
--- a/snd_mem.c
+++ b/snd_mem.c
@@ -24,6 +24,7 @@ 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"
 
 
 /*
@@ -80,7 +81,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;
 
        memsize = newsampleframes * in_format->channels * in_format->width;
@@ -311,6 +312,7 @@ qboolean S_LoadSound (sfx_t *sfx, qboolean complain)
                return true;
 
        // If we weren't able to load it previously, no need to retry
+       // Note: S_PrecacheSound clears this flag to cause a retry
        if (sfx->flags & SFXFLAG_FILEMISSING)
                return false;
 
@@ -318,6 +320,9 @@ qboolean S_LoadSound (sfx_t *sfx, qboolean complain)
        if (snd_renderbuffer == NULL)
                return false;
 
+       // Initialize volume peak to 0; if ReplayGain is supported, the loader will change this away
+       sfx->volume_peak = 0.0;
+
        // LordHavoc: if the sound filename does not begin with sound/, try adding it
        if (strncasecmp(sfx->name, "sound/", 6))
        {
@@ -325,15 +330,25 @@ qboolean S_LoadSound (sfx_t *sfx, qboolean complain)
                if (len < 0)
                {
                        // name too long
-                       Con_Printf("S_LoadSound: name \"%s\" is too long\n", sfx->name);
+                       Con_DPrintf("S_LoadSound: name \"%s\" is too long\n", sfx->name);
                        return false;
                }
-               if (S_LoadWavFile (namebuffer, sfx))
-                       return true;
                if (len >= 4 && !strcasecmp (namebuffer + len - 4, ".wav"))
+               {
+                       if (S_LoadWavFile (namebuffer, sfx))
+                               return true;
                        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))
+                               return true;
+               }
+               else
+               {
+                       if (ModPlug_LoadModPlugFile (namebuffer, sfx))
+                               return true;
+               }
        }
 
        // LordHavoc: then try without the added sound/ as wav and ogg
@@ -341,19 +356,32 @@ qboolean S_LoadSound (sfx_t *sfx, qboolean complain)
        if (len < 0)
        {
                // name too long
-               Con_Printf("S_LoadSound: name \"%s\" is too long\n", sfx->name);
+               Con_DPrintf("S_LoadSound: name \"%s\" is too long\n", sfx->name);
                return false;
        }
-       if (S_LoadWavFile (namebuffer, sfx))
-               return true;
+       // 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))
+                       return true;
                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))
+                       return true;
+       }
+       else
+       {
+               if (ModPlug_LoadModPlugFile (namebuffer, sfx))
+                       return true;
+       }
 
        // Can't load the sound!
        sfx->flags |= SFXFLAG_FILEMISSING;
        if (complain)
-               Con_Printf("S_LoadSound: Couldn't load \"%s\"\n", sfx->name);
+               Con_DPrintf("S_LoadSound: Couldn't load \"%s\"\n", sfx->name);
        return false;
 }