X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=snd_xmp.c;h=9876803d571fbcfc8c0922ba1d513b5100d1f2d5;hp=5b4e3945966448f5fae94d441e6cf57b80750844;hb=9becec9419d9a20c7d373b14e1106d5f0ce78494;hpb=bbc06a4f21fbf57a6ba726e505ef3a1fcd252733 diff --git a/snd_xmp.c b/snd_xmp.c index 5b4e3945..9876803d 100644 --- a/snd_xmp.c +++ b/snd_xmp.c @@ -20,9 +20,10 @@ */ -#include "quakedef.h" +#include "darkplaces.h" #include "snd_main.h" #include "snd_xmp.h" +#include "sound.h" #ifdef LINK_TO_LIBXMP #include @@ -69,7 +70,7 @@ #define xmp_dll 1 -qboolean XMP_OpenLibrary (void) {return true;} +qbool XMP_OpenLibrary (void) {return true;} void XMP_CloseLibrary (void) {} #else @@ -121,8 +122,8 @@ void XMP_CloseLibrary (void) {} //#define XMP_MAX_ENV_POINTS 32 /* Max number of envelope points */ #define XMP_MAX_MOD_LENGTH 256 /* Max number of patterns in module */ //#define XMP_MAX_CHANNELS 64 /* Max number of channels in module */ -//#define XMP_MAX_SRATE 49170 /* max sampling rate (Hz) */ -//#define XMP_MIN_SRATE 4000 /* min sampling rate (Hz) */ +#define XMP_MAX_SRATE 49170 /* max sampling rate (Hz) */ +#define XMP_MIN_SRATE 4000 /* min sampling rate (Hz) */ //#define XMP_MIN_BPM 20 /* min BPM */ #define XMP_MAX_FRAMESIZE (5 * XMP_MAX_SRATE * 2 / XMP_MIN_BPM) @@ -345,7 +346,7 @@ XMP_OpenLibrary Try to load the libxmp DLL ==================== */ -qboolean XMP_OpenLibrary (void) +qbool XMP_OpenLibrary (void) { const char* dllnames_xmp [] = { @@ -366,16 +367,16 @@ qboolean XMP_OpenLibrary (void) return true; // COMMANDLINEOPTION: Sound: -noxmp disables xmp module sound support - if (COM_CheckParm("-noxmp")) + if (Sys_CheckParm("-noxmp")) return false; // Load the DLL - if (Sys_LoadLibrary (dllnames_xmp, &xmp_dll, xmpfuncs)) + if (Sys_LoadDependency (dllnames_xmp, &xmp_dll, xmpfuncs)) { if (*qxmp_vercode < 0x040200) { Con_Printf("Found incompatible XMP library version %s, not loading. (4.2.0 or higher required)\n", *qxmp_version); - Sys_UnloadLibrary (&xmp_dll); + Sys_FreeLibrary (&xmp_dll); return false; } if (developer_loading.integer >= 1) @@ -396,7 +397,7 @@ Unload the libxmp DLL */ void XMP_CloseLibrary (void) { - Sys_UnloadLibrary (&xmp_dll); + Sys_FreeLibrary (&xmp_dll); } #endif @@ -464,9 +465,22 @@ static void XMP_GetSamplesFloat(channel_t *ch, sfx_t *sfx, int firstsampleframe, } // start playing the loaded file - if (sfx->format.width == 1) { format |= XMP_FORMAT_8BIT; } // else 16bit + if (sfx->format.width == 1) { format |= XMP_FORMAT_8BIT | XMP_FORMAT_UNSIGNED; } // else 16bit if (sfx->format.channels == 1) { format |= XMP_FORMAT_MONO; } // else stereo - if (qxmp_start_player(per_ch->playercontext, sfx->format.speed, format) < 0) // FIXME: only if speed is in XMP acceptable range, else default to 48khz and let DP mix + + if (qxmp_start_player(per_ch->playercontext, sfx->format.speed, format) < 0) + { + Mem_Free(per_ch); + return; + } + /* percentual left/right channel separation, default is 70. */ + if (sfx->format.channels == 2 && (qxmp_set_player(per_ch->playercontext, XMP_PLAYER_MIX, 50) != 0)) + { + Mem_Free(per_ch); + return; + } + /* interpolation type, default is XMP_INTERP_LINEAR */ + if (qxmp_set_player(per_ch->playercontext, XMP_PLAYER_INTERP, XMP_INTERP_SPLINE) != 0) { Mem_Free(per_ch); return; @@ -579,7 +593,7 @@ XMP_LoadModFile Load an XMP module file into memory =============== */ -qboolean XMP_LoadModFile(const char *filename, sfx_t *sfx) +qbool XMP_LoadModFile(const char *filename, sfx_t *sfx) { fs_offset_t filesize; unsigned char *data; @@ -593,7 +607,7 @@ qboolean XMP_LoadModFile(const char *filename, sfx_t *sfx) #endif // COMMANDLINEOPTION: Sound: -noxmp disables xmp module sound support - if (COM_CheckParm("-noxmp")) + if (Sys_CheckParm("-noxmp")) return false; // Return if already loaded @@ -634,20 +648,20 @@ qboolean XMP_LoadModFile(const char *filename, sfx_t *sfx) // set dp sfx sfx->memsize += sizeof(*per_sfx); sfx->memsize += filesize; // total memory used (including sfx_t and fetcher data) -// sfx->format // format describing the audio data that fetcher->getsamplesfloat shall return - sfx->format.speed = 48000; // default to this sample rate - sfx->format.width = 2; // default to 16 bit samples -// sfx->format.width = 1; // 8-bit - sfx->format.channels = 2; // default to stereo -// sfx->format.channels = 1; // mono + if (S_GetSoundRate() > XMP_MAX_SRATE) + sfx->format.speed = 48000; + else if (S_GetSoundRate() < XMP_MIN_SRATE) + sfx->format.speed = 8000; + else + sfx->format.speed = S_GetSoundRate(); + sfx->format.width = S_GetSoundWidth(); // 2 = 16 bit samples + sfx->format.channels = S_GetSoundChannels(); sfx->flags |= SFXFLAG_STREAMED; // cf SFXFLAG_* defines -// sfx->total_length // in (pcm) sample frames - sfx->total_length = 1<<30; // 2147384647; // they always loop (FIXME this breaks after 6 hours, we need support for a real "infinite" value!) + sfx->total_length = 1<<30; // 2147384647; // in (pcm) sample frames - they always loop (FIXME this breaks after 6 hours, we need support for a real "infinite" value!) sfx->loopstart = sfx->total_length; // (modplug does it) in sample frames. equals total_length if not looped sfx->fetcher_data = per_sfx; sfx->fetcher = &xmp_fetcher; -// sfx->volume_mult // for replay gain (multiplier to apply) -// sfx->volume_peak // for replay gain (highest peak); if set to 0, ReplayGain isn't supported + sfx->volume_peak = 0; qxmp_get_module_info(xc, &mi); if (developer_loading.integer >= 2)