mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-09 01:01:07 +00:00
snd_xmp.c: use xmp_load_module_from_callbacks() if available
This commit is contained in:
parent
5f365331fa
commit
a5750de9ae
1 changed files with 32 additions and 2 deletions
|
@ -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)
|
static qboolean S_XMP_CodecOpenStream (snd_stream_t *stream)
|
||||||
{
|
{
|
||||||
/* need to load the whole file into memory and pass it to libxmp
|
/* need to load the whole file into memory and pass it to libxmp
|
||||||
* using xmp_load_module_from_memory() which requires libxmp >= 4.2.
|
* 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
|
* 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;
|
xmp_context c;
|
||||||
|
#if (XMP_VERCODE >= 0x040500)
|
||||||
|
struct xmp_callbacks file_callbacks = {
|
||||||
|
xmp_fread, xmp_fseek, xmp_ftell, NULL
|
||||||
|
};
|
||||||
|
#else
|
||||||
byte *moddata;
|
byte *moddata;
|
||||||
long len;
|
long len;
|
||||||
int fmt;
|
|
||||||
int mark;
|
int mark;
|
||||||
|
#endif
|
||||||
|
int fmt;
|
||||||
|
|
||||||
c = xmp_create_context();
|
c = xmp_create_context();
|
||||||
if (c == NULL)
|
if (c == NULL)
|
||||||
return false;
|
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);
|
len = FS_filelength (&stream->fh);
|
||||||
mark = Hunk_LowMark();
|
mark = Hunk_LowMark();
|
||||||
moddata = (byte *) Hunk_Alloc(len);
|
moddata = (byte *) Hunk_Alloc(len);
|
||||||
|
@ -68,6 +97,7 @@ static qboolean S_XMP_CodecOpenStream (snd_stream_t *stream)
|
||||||
goto err1;
|
goto err1;
|
||||||
}
|
}
|
||||||
Hunk_FreeToLowMark(mark); /* free original file data */
|
Hunk_FreeToLowMark(mark); /* free original file data */
|
||||||
|
#endif
|
||||||
|
|
||||||
stream->priv = c;
|
stream->priv = c;
|
||||||
if (shm->speed > XMP_MAX_SRATE)
|
if (shm->speed > XMP_MAX_SRATE)
|
||||||
|
|
Loading…
Reference in a new issue