X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=snd_modplug.c;h=98d3706969ecaadc12cb7e1b6ad965e0c48c4eeb;hb=12a73552d4fbe2d617d575b54259d0bbdd066b5e;hp=81f00b626fe4b7d402175b5d06a7b2fe2f048b56;hpb=89bf9ac7f13b2308dd89291f15efc8a299c3e783;p=xonotic%2Fdarkplaces.git diff --git a/snd_modplug.c b/snd_modplug.c index 81f00b62..98d37069 100644 --- a/snd_modplug.c +++ b/snd_modplug.c @@ -26,6 +26,19 @@ #include "snd_main.h" #include "snd_modplug.h" +#ifdef SND_MODPLUG_STATIC + +#include +qboolean ModPlug_OpenLibrary (void) +{ + return true; // statically linked +} +void ModPlug_CloseLibrary (void) +{ +} +#define modplug_dll 1 + +#else // BEGIN SECTION FROM modplug.h /* @@ -83,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[] = { @@ -117,9 +133,7 @@ qboolean ModPlug_OpenLibrary (void) { const char* dllnames_modplug [] = { -#if defined(WIN64) - "libmodplug64.dll", -#elif defined(WIN32) +#if defined(WIN32) "libmodplug-0.dll", "modplug.dll", #elif defined(MACOSX) @@ -142,15 +156,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 - if (! Sys_LoadLibrary (dllnames_modplug, &modplug_dll, modplugfuncs)) + if(Sys_LoadLibrary (dllnames_modplug, &modplug_dll, modplugfuncs)) { - Sys_UnloadLibrary (&modplug_dll); - Con_Printf ("ModPlug support disabled\n"); - return false; + 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; } - - Con_Printf ("ModPlug support enabled\n"); - return true; + else + return false; } @@ -165,6 +179,7 @@ void ModPlug_CloseLibrary (void) { Sys_UnloadLibrary (&modplug_dll); } +#endif /* @@ -175,13 +190,6 @@ void ModPlug_CloseLibrary (void) ================================================================= */ -#define STREAM_BUFFER_DURATION 1.5f // 1.5 sec -#define STREAM_BUFFER_SIZE(format_ptr) ((int)(ceil (STREAM_BUFFER_DURATION * ((format_ptr)->speed * (format_ptr)->width * (format_ptr)->channels)))) -// We work with 1 sec sequences, so this buffer must be able to contain -// 1 sec of sound of the highest quality (48 KHz, 16 bit samples, stereo) -static unsigned char resampling_buffer [48000 * 2 * 2]; - - // Per-sfx data structure typedef struct { @@ -213,7 +221,7 @@ static const snd_buffer_t* ModPlug_FetchSound (void *sfxfetcher, void **chfetche modplug_stream_perchannel_t* per_ch = (modplug_stream_perchannel_t *)*chfetcherpointer; modplug_stream_persfx_t* per_sfx = (modplug_stream_persfx_t *)sfxfetcher; snd_buffer_t* sb; - int newlength, done, ret, bigendian; + int newlength, done, ret; unsigned int real_start; unsigned int factor; @@ -239,6 +247,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; @@ -295,7 +309,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", @@ -313,25 +327,21 @@ static const snd_buffer_t* ModPlug_FetchSound (void *sfxfetcher, void **chfetche per_ch->sb_offset = real_start; - // We add exactly 1 sec of sound to the buffer: - // 1- to ensure we won't lose any sample during the resampling process - // 2- to force one call to ModPlug_FetchSound per second to regulate the workload - if (sb->format.speed + sb->nbframes > sb->maxframes) + // We add more than one frame of sound to the buffer: + // 1- to ensure we won't lose many samples during the resampling process + // 2- to reduce calls to ModPlug_FetchSound to regulate workload + newlength = (int)(per_sfx->format.speed*STREAM_BUFFER_FILL); + if (newlength + sb->nbframes > sb->maxframes) { Con_Printf ("ModPlug_FetchSound: stream buffer overflow (%u sample frames / %u)\n", sb->format.speed + sb->nbframes, sb->maxframes); return NULL; } - newlength = per_sfx->format.speed * factor; // -> 1 sec of sound before resampling + newlength *= factor; // convert from sample frames to bytes if(newlength > (int)sizeof(resampling_buffer)) newlength = sizeof(resampling_buffer); // Decompress in the resampling_buffer -#if BYTE_ORDER == BIG_ENDIAN - bigendian = 1; -#else - bigendian = 0; -#endif done = 0; while ((ret = ModPlug_Read (per_ch->mf, (char *)&resampling_buffer[done], (int)(newlength - done))) > 0) done += ret; @@ -431,7 +441,8 @@ qboolean ModPlug_LoadModPlugFile (const char *filename, sfx_t *sfx) if (data == NULL) return false; - Con_DPrintf ("Loading ModPlug file \"%s\"\n", filename); + if (developer_loading.integer >= 2) + Con_Printf ("Loading ModPlug file \"%s\"\n", filename); ModPlug_GetSettings(&s); s.mFlags = MODPLUG_ENABLE_OVERSAMPLING | MODPLUG_ENABLE_NOISE_REDUCTION | MODPLUG_ENABLE_REVERB; @@ -450,7 +461,13 @@ qboolean ModPlug_LoadModPlugFile (const char *filename, sfx_t *sfx) return false; } - Con_DPrintf ("\"%s\" will be streamed\n", filename); +#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)); strlcpy(per_sfx->name, sfx->name, sizeof(per_sfx->name)); sfx->memsize += sizeof (*per_sfx);