]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_ogg.c
fix a crash on CentOS 5.6
[xonotic/darkplaces.git] / snd_ogg.c
index ded0473cf38d329dc6618e314e87408de14724ff..e1bf0959be7f61f8e2c90e99e87a8d3e0fd0b6b0 100644 (file)
--- a/snd_ogg.c
+++ b/snd_ogg.c
@@ -274,6 +274,7 @@ qboolean OGG_OpenLibrary (void)
        const char* dllnames_vo [] =
        {
 #if defined(WIN32)
+               "libvorbis-0.dll",
                "libvorbis.dll",
                "vorbis.dll",
 #elif defined(MACOSX)
@@ -287,6 +288,7 @@ qboolean OGG_OpenLibrary (void)
        const char* dllnames_vf [] =
        {
 #if defined(WIN32)
+               "libvorbisfile-3.dll",
                "libvorbisfile.dll",
                "vorbisfile.dll",
 #elif defined(MACOSX)
@@ -532,10 +534,11 @@ static const snd_buffer_t* OGG_FetchSound (void *sfxfetcher, void **chfetcherpoi
        // 1- to ensure we won't lose many samples during the resampling process
        // 2- to reduce calls to OGG_FetchSound to regulate workload
        newlength = (int)(per_sfx->format.speed*STREAM_BUFFER_FILL);
-       if (newlength + sb->nbframes > sb->maxframes)
+       // this is how much we FETCH...
+       if ((size_t) ((double) newlength * (double)sb->format.speed / (double)per_sfx->format.speed) + sb->nbframes > sb->maxframes)
        {
-               Con_Printf ("OGG_FetchSound: stream buffer overflow (%u sample frames / %u)\n",
-                                       sb->format.speed + sb->nbframes, sb->maxframes);
+               Con_Printf ("OGG_FetchSound: stream buffer overflow (%u + %u = %u sample frames / %u)\n",
+                                       (unsigned int) ((double) newlength * (double)sb->format.speed / (double)per_sfx->format.speed), sb->nbframes, (unsigned int) ((double) newlength * (double)sb->format.speed / (double)per_sfx->format.speed) + sb->nbframes, sb->maxframes);
                return NULL;
        }
        newlength *= factor; // convert from sample frames to bytes
@@ -671,6 +674,7 @@ qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *sfx)
        vorbis_comment *vc;
        ogg_int64_t len, buff_len;
        double peak, gaindb;
+       qboolean want_stream;
 
 #ifndef LINK_TO_LIBVORBIS
        if (!vf_dll)
@@ -715,7 +719,25 @@ qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *sfx)
 
        // Decide if we go for a stream or a simple PCM cache
        buff_len = (int)ceil (STREAM_BUFFER_DURATION * snd_renderbuffer->format.speed) * 2 * vi->channels;
-       if (snd_streaming.integer && (len > (ogg_int64_t)filesize + 3 * buff_len || snd_streaming.integer >= 2))
+
+       if(snd_streaming.integer)
+       {
+               want_stream = true;
+
+               // don't stream if we would need more RAM when streaming
+               if(snd_streaming.integer < 2)
+                       if(len <= (ogg_int64_t)filesize + 3 * buff_len)
+                               want_stream = false;
+
+               // if streaming length is set, do NOT stream if below the length
+               if(snd_streaming_length.value > 0)
+                       if(len <= snd_streaming_length.value * vi->channels * 2)
+                               want_stream = false;
+       }
+       else
+               want_stream = false;
+       
+       if (want_stream)
        {
                ogg_stream_persfx_t* per_sfx;