]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_modplug.c
some color tag cleanups by terencehill
[xonotic/darkplaces.git] / snd_modplug.c
index a3179868200f419615c7edfc7a1a9c59be2ebebe..54a07909437e40bbbf3c2ad90d1ddde7fac4a186 100644 (file)
@@ -96,6 +96,9 @@ static int (*ModPlug_Read) (ModPlugFile* file, void* buffer, int size);
 static void (*ModPlug_Seek) (ModPlugFile* file, int millisecond);
 static void (*ModPlug_GetSettings) (ModPlug_Settings* settings);
 static void (*ModPlug_SetSettings) (const ModPlug_Settings* settings);
+typedef void (ModPlug_SetMasterVolume_t) (ModPlugFile* file,unsigned int cvol) ;
+ModPlug_SetMasterVolume_t *ModPlug_SetMasterVolume;
+
 
 static dllfunction_t modplugfuncs[] =
 {
@@ -155,7 +158,15 @@ qboolean ModPlug_OpenLibrary (void)
        // Load the DLLs
        // We need to load both by hand because some OSes seem to not load
        // the modplug DLL automatically when loading the modplugFile DLL
-       return Sys_LoadLibrary (dllnames_modplug, &modplug_dll, modplugfuncs);
+       if(Sys_LoadLibrary (dllnames_modplug, &modplug_dll, modplugfuncs))
+       {
+               ModPlug_SetMasterVolume = (ModPlug_SetMasterVolume_t *) Sys_GetProcAddress(modplug_dll, "ModPlug_SetMasterVolume");
+               if(!ModPlug_SetMasterVolume)
+                       Con_Print("Warning: modplug volume control not supported. Try getting a newer version of libmodplug.\n");
+               return true;
+       }
+       else
+               return false;
 }
 
 
@@ -245,6 +256,12 @@ static const snd_buffer_t* ModPlug_FetchSound (void *sfxfetcher, void **chfetche
                        Mem_Free (per_ch);
                        return NULL;
                }
+
+#ifndef SND_MODPLUG_STATIC
+               if(ModPlug_SetMasterVolume)
+#endif
+                       ModPlug_SetMasterVolume(per_ch->mf, 512); // max volume, DP scales down!
+
                per_ch->bs = 0;
 
                per_ch->sb_offset = 0;
@@ -301,7 +318,7 @@ static const snd_buffer_t* ModPlug_FetchSound (void *sfxfetcher, void **chfetche
                ModPlug_Seek(per_ch->mf, modplug_start);
                sb->nbframes = 0;
 
-               real_start = (float)modplug_start / 1000 * snd_renderbuffer->format.speed;
+               real_start = (unsigned int) ((float)modplug_start / 1000 * snd_renderbuffer->format.speed);
                if (*start - real_start + nbsampleframes > sb->maxframes)
                {
                        Con_Printf ("ModPlug_FetchSound: stream buffer too small after seek (%u sample frames required)\n",
@@ -452,6 +469,11 @@ qboolean ModPlug_LoadModPlugFile (const char *filename, sfx_t *sfx)
                return false;
        }
 
+#ifndef SND_MODPLUG_STATIC
+       if(ModPlug_SetMasterVolume)
+#endif
+               ModPlug_SetMasterVolume(mf, 512); // max volume, DP scales down!
+
        if (developer_loading.integer >= 2)
                Con_Printf ("\"%s\" will be streamed\n", filename);
        per_sfx = (modplug_stream_persfx_t *)Mem_Alloc (snd_mempool, sizeof (*per_sfx));