From a5750de9ae5ae933868fa48521e9a3a7eba3e2f6 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Tue, 3 May 2022 23:01:02 +0300 Subject: [PATCH] snd_xmp.c: use xmp_load_module_from_callbacks() if available --- Quake/snd_xmp.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/Quake/snd_xmp.c b/Quake/snd_xmp.c index 7734fd3d..624716a5 100644 --- a/Quake/snd_xmp.c +++ b/Quake/snd_xmp.c @@ -43,22 +43,51 @@ static void S_XMP_CodecShutdown (void) { } +#if (XMP_VERCODE >= 0x040500) +static unsigned long xmp_fread(void *dest, unsigned long len, unsigned long nmemb, void *f) +{ + return FS_fread(dest, len, nmemb, (fshandle_t *)f); +} +static int xmp_fseek(void *f, long offset, int whence) +{ + return FS_fseek((fshandle_t *)f, offset, whence); +} +static long xmp_ftell(void *f) +{ + return FS_ftell((fshandle_t *)f); +} +#endif + static qboolean S_XMP_CodecOpenStream (snd_stream_t *stream) { /* need to load the whole file into memory and pass it to libxmp * using xmp_load_module_from_memory() which requires libxmp >= 4.2. * libxmp-4.0/4.1 only have xmp_load_module() which accepts a file - * name which isn't good with files in containers like paks, etc. */ + * name which isn't good with files in containers like paks, etc. + * On the other hand, libxmp >= 4.5 introduces file callbacks: use + * if available. */ xmp_context c; +#if (XMP_VERCODE >= 0x040500) + struct xmp_callbacks file_callbacks = { + xmp_fread, xmp_fseek, xmp_ftell, NULL + }; +#else byte *moddata; long len; - int fmt; int mark; +#endif + int fmt; c = xmp_create_context(); if (c == NULL) return false; +#if (XMP_VERCODE >= 0x040500) + if (xmp_load_module_from_callbacks(c, &stream->fh, file_callbacks) < 0) { + Con_DPrintf("Could not load module %s\n", stream->name); + goto err1; + } +#else len = FS_filelength (&stream->fh); mark = Hunk_LowMark(); moddata = (byte *) Hunk_Alloc(len); @@ -68,6 +97,7 @@ static qboolean S_XMP_CodecOpenStream (snd_stream_t *stream) goto err1; } Hunk_FreeToLowMark(mark); /* free original file data */ +#endif stream->priv = c; if (shm->speed > XMP_MAX_SRATE)