snd_xmp.c: use xmp_load_module_from_callbacks() if available

This commit is contained in:
Ozkan Sezer 2022-05-03 23:01:02 +03:00
parent 5f365331fa
commit a5750de9ae

View file

@ -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)