]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_ogg.c
remove a redundant (and bugged) check
[xonotic/darkplaces.git] / snd_ogg.c
index ad4abadbd779f3eb61b031b8f2b363e6a55a8a28..0ee16bab4bd7f70cfd64d7310b6b9ba8f72001d9 100644 (file)
--- a/snd_ogg.c
+++ b/snd_ogg.c
 #include "snd_ogg.h"
 #include "snd_wav.h"
 
+#ifdef LINK_TO_LIBVORBIS
+#define OV_EXCLUDE_STATIC_CALLBACKS
+#include <ogg/ogg.h>
+#include <vorbis/vorbisfile.h>
+
+#define qov_clear ov_clear
+#define qov_info ov_info
+#define qov_comment ov_comment
+#define qov_open_callbacks ov_open_callbacks
+#define qov_pcm_seek ov_pcm_seek
+#define qov_pcm_total ov_pcm_total
+#define qov_read ov_read
+#define qvorbis_comment_query vorbis_comment_query
+
+qboolean OGG_OpenLibrary (void) {return true;}
+void OGG_CloseLibrary (void) {}
+#else
 
 /*
 =================================================================
@@ -205,7 +222,7 @@ typedef struct
 static int (*qov_clear) (OggVorbis_File *vf);
 static vorbis_info* (*qov_info) (OggVorbis_File *vf,int link);
 static vorbis_comment* (*qov_comment) (OggVorbis_File *vf,int link);
-static char * (*qvorbis_comment_query) (vorbis_comment *vc, char *tag, int count);
+static char * (*qvorbis_comment_query) (vorbis_comment *vc, const char *tag, int count);
 static int (*qov_open_callbacks) (void *datasource, OggVorbis_File *vf,
                                                                  char *initial, long ibytes,
                                                                  ov_callbacks callbacks);
@@ -236,63 +253,6 @@ static dllfunction_t vorbisfuncs[] =
 static dllhandle_t vo_dll = NULL;
 static dllhandle_t vf_dll = NULL;
 
-typedef struct
-{
-       unsigned char *buffer;
-       ogg_int64_t ind, buffsize;
-} ov_decode_t;
-
-
-static size_t ovcb_read (void *ptr, size_t size, size_t nb, void *datasource)
-{
-       ov_decode_t *ov_decode = (ov_decode_t*)datasource;
-       size_t remain, len;
-
-       remain = ov_decode->buffsize - ov_decode->ind;
-       len = size * nb;
-       if (remain < len)
-               len = remain - remain % size;
-
-       memcpy (ptr, ov_decode->buffer + ov_decode->ind, len);
-       ov_decode->ind += len;
-
-       return len / size;
-}
-
-static int ovcb_seek (void *datasource, ogg_int64_t offset, int whence)
-{
-       ov_decode_t *ov_decode = (ov_decode_t*)datasource;
-
-       switch (whence)
-       {
-               case SEEK_SET:
-                       break;
-               case SEEK_CUR:
-                       offset += ov_decode->ind;
-                       break;
-               case SEEK_END:
-                       offset += ov_decode->buffsize;
-                       break;
-               default:
-                       return -1;
-       }
-       if (offset < 0 || offset > ov_decode->buffsize)
-               return -1;
-
-       ov_decode->ind = offset;
-       return 0;
-}
-
-static int ovcb_close (void *ov_decode)
-{
-       return 0;
-}
-
-static long ovcb_tell (void *ov_decode)
-{
-       return ((ov_decode_t*)ov_decode)->ind;
-}
-
 
 /*
 =================================================================
@@ -314,6 +274,7 @@ qboolean OGG_OpenLibrary (void)
        const char* dllnames_vo [] =
        {
 #if defined(WIN32)
+               "libvorbis-0.dll",
                "libvorbis.dll",
                "vorbis.dll",
 #elif defined(MACOSX)
@@ -327,6 +288,7 @@ qboolean OGG_OpenLibrary (void)
        const char* dllnames_vf [] =
        {
 #if defined(WIN32)
+               "libvorbisfile-3.dll",
                "libvorbisfile.dll",
                "vorbisfile.dll",
 #elif defined(MACOSX)
@@ -366,6 +328,7 @@ void OGG_CloseLibrary (void)
        Sys_UnloadLibrary (&vo_dll);
 }
 
+#endif
 
 /*
 =================================================================
@@ -375,6 +338,62 @@ void OGG_CloseLibrary (void)
 =================================================================
 */
 
+typedef struct
+{
+       unsigned char *buffer;
+       ogg_int64_t ind, buffsize;
+} ov_decode_t;
+
+static size_t ovcb_read (void *ptr, size_t size, size_t nb, void *datasource)
+{
+       ov_decode_t *ov_decode = (ov_decode_t*)datasource;
+       size_t remain, len;
+
+       remain = ov_decode->buffsize - ov_decode->ind;
+       len = size * nb;
+       if (remain < len)
+               len = remain - remain % size;
+
+       memcpy (ptr, ov_decode->buffer + ov_decode->ind, len);
+       ov_decode->ind += len;
+
+       return len / size;
+}
+
+static int ovcb_seek (void *datasource, ogg_int64_t offset, int whence)
+{
+       ov_decode_t *ov_decode = (ov_decode_t*)datasource;
+
+       switch (whence)
+       {
+               case SEEK_SET:
+                       break;
+               case SEEK_CUR:
+                       offset += ov_decode->ind;
+                       break;
+               case SEEK_END:
+                       offset += ov_decode->buffsize;
+                       break;
+               default:
+                       return -1;
+       }
+       if (offset < 0 || offset > ov_decode->buffsize)
+               return -1;
+
+       ov_decode->ind = offset;
+       return 0;
+}
+
+static int ovcb_close (void *ov_decode)
+{
+       return 0;
+}
+
+static long ovcb_tell (void *ov_decode)
+{
+       return ((ov_decode_t*)ov_decode)->ind;
+}
+
 // Per-sfx data structure
 typedef struct
 {
@@ -515,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
@@ -655,8 +675,10 @@ qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *sfx)
        ogg_int64_t len, buff_len;
        double peak, gaindb;
 
+#ifndef LINK_TO_LIBVORBIS
        if (!vf_dll)
                return false;
+#endif
 
        // Already loaded?
        if (sfx->fetcher != NULL)