X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=snd_modplug.c;h=9cb486931fc402316a41464a8970a7502516d79c;hb=a0593ee6b57c492e4ec9c4f1e62d0dc0114f119c;hp=35b255c91e7f57e2ac2c79bcb2a439b32219c757;hpb=dfa13cb7dc4a981d5c6141ac4a96c08b57383f24;p=xonotic%2Fdarkplaces.git diff --git a/snd_modplug.c b/snd_modplug.c index 35b255c9..9cb48693 100644 --- a/snd_modplug.c +++ b/snd_modplug.c @@ -96,7 +96,8 @@ 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); -static void (*ModPlug_SetMasterVolume) (ModPlugFile* file,unsigned int cvol) ; +typedef void (ModPlug_SetMasterVolume_t) (ModPlugFile* file,unsigned int cvol) ; +ModPlug_SetMasterVolume_t *ModPlug_SetMasterVolume; static dllfunction_t modplugfuncs[] = @@ -159,7 +160,7 @@ qboolean ModPlug_OpenLibrary (void) // the modplug DLL automatically when loading the modplugFile DLL if(Sys_LoadLibrary (dllnames_modplug, &modplug_dll, modplugfuncs)) { - ModPlug_SetMasterVolume = Sys_GetProcAddress(modplug_dll, "ModPlug_SetMasterVolume"); + 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; @@ -191,13 +192,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 { @@ -256,7 +250,9 @@ static const snd_buffer_t* ModPlug_FetchSound (void *sfxfetcher, void **chfetche 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; @@ -315,7 +311,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", @@ -333,16 +329,17 @@ 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); @@ -466,7 +463,9 @@ 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)