DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
snd_xmp.c File Reference
#include "darkplaces.h"
#include "snd_main.h"
#include "snd_xmp.h"
#include "sound.h"
+ Include dependency graph for snd_xmp.c:

Go to the source code of this file.

Data Structures

struct  xmp_channel
 
struct  xmp_module
 
struct  xmp_module_info
 
struct  xmp_stream_perchannel_t
 
struct  xmp_stream_persfx_t
 

Macros

#define XMP_CHANNEL_MUTE   (1 << 1) /* Channel is muted */
 
#define XMP_CHANNEL_SYNTH   (1 << 0) /* Channel is synthesized */
 
#define XMP_END   1
 
#define XMP_ERROR_DEPACK   5 /* Error depacking file */
 
#define XMP_ERROR_FORMAT   3 /* Unsupported module format */
 
#define XMP_ERROR_INTERNAL   2 /* Internal error */
 
#define XMP_ERROR_INVALID   7 /* Invalid parameter */
 
#define XMP_ERROR_LOAD   4 /* Error loading file */
 
#define XMP_ERROR_STATE   8 /* Invalid player state */
 
#define XMP_ERROR_SYSTEM   6 /* System error */
 
#define XMP_FORMAT_8BIT   (1 << 0) /* Mix to 8-bit instead of 16 */
 
#define XMP_FORMAT_MONO   (1 << 2) /* Mix to mono instead of stereo */
 
#define XMP_FORMAT_UNSIGNED   (1 << 1) /* Mix to unsigned samples */
 
#define XMP_INTERP_LINEAR   1 /* Linear (default) */
 
#define XMP_INTERP_NEAREST   0 /* Nearest neighbor */
 
#define XMP_INTERP_SPLINE   2 /* Cubic spline */
 
#define XMP_MAX_FRAMESIZE   (5 * XMP_MAX_SRATE * 2 / XMP_MIN_BPM)
 
#define XMP_MAX_MOD_LENGTH   256 /* Max number of patterns in module */
 
#define XMP_MAX_SRATE   49170 /* max sampling rate (Hz) */
 
#define XMP_MIN_SRATE   4000 /* min sampling rate (Hz) */
 
#define XMP_NAME_SIZE   64 /* Size of module name and type */
 
#define XMP_PLAYER_AMP   0 /* Amplification factor */
 
#define XMP_PLAYER_CFLAGS   5 /* Player flags for current module */
 
#define XMP_PLAYER_DEFPAN   10 /* Default pan setting */
 
#define XMP_PLAYER_DSP   3 /* DSP effect flags */
 
#define XMP_PLAYER_FLAGS   4 /* Player flags */
 
#define XMP_PLAYER_INTERP   2 /* Interpolation type */
 
#define XMP_PLAYER_MIX   1 /* Stereo mixing */
 
#define XMP_PLAYER_SMIX_VOLUME   9 /* SMIX volume */
 
#define XMP_PLAYER_SMPCTL   6 /* Sample control flags */
 
#define XMP_PLAYER_STATE   8 /* Internal player state */
 
#define XMP_PLAYER_VOLUME   7 /* Player module volume */
 
#define XMP_SMPCTL_SKIP   (1 << 0) /* Don't load samples */
 
#define XMP_STATE_LOADED   1 /* Module loaded */
 
#define XMP_STATE_PLAYING   2 /* Module playing */
 
#define XMP_STATE_UNLOADED   0 /* Context created */
 

Typedefs

typedef char * xmp_context
 

Functions

void XMP_CloseLibrary (void)
 
static void XMP_FreeSfx (sfx_t *sfx)
 
static void XMP_GetSamplesFloat (channel_t *ch, sfx_t *sfx, int firstsampleframe, int numsampleframes, float *outsamplesfloat)
 
qbool XMP_LoadModFile (const char *filename, sfx_t *sfx)
 
qbool XMP_OpenLibrary (void)
 
static void XMP_StopChannel (channel_t *ch)
 

Variables

static xmp_context(* qxmp_create_context )(void)
 
static void(* qxmp_end_player )(xmp_context)
 
static void(* qxmp_free_context )(xmp_context)
 
static void(* qxmp_get_frame_info )(xmp_context, struct xmp_frame_info *)
 
static void(* qxmp_get_module_info )(xmp_context, struct xmp_module_info *)
 
static int(* qxmp_get_player )(xmp_context, int)
 
static int(* qxmp_load_module_from_memory )(xmp_context, void *, long)
 
static int(* qxmp_play_buffer )(xmp_context, void *, int, int)
 
static int(* qxmp_play_frame )(xmp_context)
 
static void(* qxmp_release_module )(xmp_context)
 
static int(* qxmp_set_player )(xmp_context, int, int)
 
static int(* qxmp_start_player )(xmp_context, int, int)
 
static const unsigned intqxmp_vercode
 
static const char ** qxmp_version
 
static dllhandle_t xmp_dll = NULL
 
static const snd_fetcher_t xmp_fetcher = { XMP_GetSamplesFloat, XMP_StopChannel, XMP_FreeSfx }
 
static dllfunction_t xmpfuncs []
 

Macro Definition Documentation

◆ XMP_CHANNEL_MUTE

#define XMP_CHANNEL_MUTE   (1 << 1) /* Channel is muted */

Definition at line 150 of file snd_xmp.c.

◆ XMP_CHANNEL_SYNTH

#define XMP_CHANNEL_SYNTH   (1 << 0) /* Channel is synthesized */

Definition at line 149 of file snd_xmp.c.

◆ XMP_END

#define XMP_END   1

Definition at line 131 of file snd_xmp.c.

◆ XMP_ERROR_DEPACK

#define XMP_ERROR_DEPACK   5 /* Error depacking file */

Definition at line 135 of file snd_xmp.c.

◆ XMP_ERROR_FORMAT

#define XMP_ERROR_FORMAT   3 /* Unsupported module format */

Definition at line 133 of file snd_xmp.c.

◆ XMP_ERROR_INTERNAL

#define XMP_ERROR_INTERNAL   2 /* Internal error */

Definition at line 132 of file snd_xmp.c.

◆ XMP_ERROR_INVALID

#define XMP_ERROR_INVALID   7 /* Invalid parameter */

Definition at line 137 of file snd_xmp.c.

◆ XMP_ERROR_LOAD

#define XMP_ERROR_LOAD   4 /* Error loading file */

Definition at line 134 of file snd_xmp.c.

◆ XMP_ERROR_STATE

#define XMP_ERROR_STATE   8 /* Invalid player state */

Definition at line 138 of file snd_xmp.c.

◆ XMP_ERROR_SYSTEM

#define XMP_ERROR_SYSTEM   6 /* System error */

Definition at line 136 of file snd_xmp.c.

◆ XMP_FORMAT_8BIT

#define XMP_FORMAT_8BIT   (1 << 0) /* Mix to 8-bit instead of 16 */

Definition at line 90 of file snd_xmp.c.

Referenced by XMP_GetSamplesFloat().

◆ XMP_FORMAT_MONO

#define XMP_FORMAT_MONO   (1 << 2) /* Mix to mono instead of stereo */

Definition at line 92 of file snd_xmp.c.

Referenced by XMP_GetSamplesFloat().

◆ XMP_FORMAT_UNSIGNED

#define XMP_FORMAT_UNSIGNED   (1 << 1) /* Mix to unsigned samples */

Definition at line 91 of file snd_xmp.c.

Referenced by XMP_GetSamplesFloat().

◆ XMP_INTERP_LINEAR

#define XMP_INTERP_LINEAR   1 /* Linear (default) */

Definition at line 109 of file snd_xmp.c.

◆ XMP_INTERP_NEAREST

#define XMP_INTERP_NEAREST   0 /* Nearest neighbor */

Definition at line 108 of file snd_xmp.c.

◆ XMP_INTERP_SPLINE

#define XMP_INTERP_SPLINE   2 /* Cubic spline */

Definition at line 110 of file snd_xmp.c.

Referenced by XMP_GetSamplesFloat().

◆ XMP_MAX_FRAMESIZE

#define XMP_MAX_FRAMESIZE   (5 * XMP_MAX_SRATE * 2 / XMP_MIN_BPM)

Definition at line 128 of file snd_xmp.c.

◆ XMP_MAX_MOD_LENGTH

#define XMP_MAX_MOD_LENGTH   256 /* Max number of patterns in module */

Definition at line 123 of file snd_xmp.c.

◆ XMP_MAX_SRATE

#define XMP_MAX_SRATE   49170 /* max sampling rate (Hz) */

Definition at line 125 of file snd_xmp.c.

Referenced by XMP_LoadModFile().

◆ XMP_MIN_SRATE

#define XMP_MIN_SRATE   4000 /* min sampling rate (Hz) */

Definition at line 126 of file snd_xmp.c.

Referenced by XMP_LoadModFile().

◆ XMP_NAME_SIZE

#define XMP_NAME_SIZE   64 /* Size of module name and type */

Definition at line 87 of file snd_xmp.c.

◆ XMP_PLAYER_AMP

#define XMP_PLAYER_AMP   0 /* Amplification factor */

Definition at line 95 of file snd_xmp.c.

◆ XMP_PLAYER_CFLAGS

#define XMP_PLAYER_CFLAGS   5 /* Player flags for current module */

Definition at line 100 of file snd_xmp.c.

◆ XMP_PLAYER_DEFPAN

#define XMP_PLAYER_DEFPAN   10 /* Default pan setting */

Definition at line 105 of file snd_xmp.c.

◆ XMP_PLAYER_DSP

#define XMP_PLAYER_DSP   3 /* DSP effect flags */

Definition at line 98 of file snd_xmp.c.

◆ XMP_PLAYER_FLAGS

#define XMP_PLAYER_FLAGS   4 /* Player flags */

Definition at line 99 of file snd_xmp.c.

◆ XMP_PLAYER_INTERP

#define XMP_PLAYER_INTERP   2 /* Interpolation type */

Definition at line 97 of file snd_xmp.c.

Referenced by XMP_GetSamplesFloat().

◆ XMP_PLAYER_MIX

#define XMP_PLAYER_MIX   1 /* Stereo mixing */

Definition at line 96 of file snd_xmp.c.

Referenced by XMP_GetSamplesFloat().

◆ XMP_PLAYER_SMIX_VOLUME

#define XMP_PLAYER_SMIX_VOLUME   9 /* SMIX volume */

Definition at line 104 of file snd_xmp.c.

◆ XMP_PLAYER_SMPCTL

#define XMP_PLAYER_SMPCTL   6 /* Sample control flags */

Definition at line 101 of file snd_xmp.c.

◆ XMP_PLAYER_STATE

#define XMP_PLAYER_STATE   8 /* Internal player state */

Definition at line 103 of file snd_xmp.c.

◆ XMP_PLAYER_VOLUME

#define XMP_PLAYER_VOLUME   7 /* Player module volume */

Definition at line 102 of file snd_xmp.c.

◆ XMP_SMPCTL_SKIP

#define XMP_SMPCTL_SKIP   (1 << 0) /* Don't load samples */

Definition at line 118 of file snd_xmp.c.

◆ XMP_STATE_LOADED

#define XMP_STATE_LOADED   1 /* Module loaded */

Definition at line 114 of file snd_xmp.c.

◆ XMP_STATE_PLAYING

#define XMP_STATE_PLAYING   2 /* Module playing */

Definition at line 115 of file snd_xmp.c.

◆ XMP_STATE_UNLOADED

#define XMP_STATE_UNLOADED   0 /* Context created */

Definition at line 113 of file snd_xmp.c.

Typedef Documentation

◆ xmp_context

typedef char* xmp_context

Definition at line 141 of file snd_xmp.c.

Function Documentation

◆ XMP_CloseLibrary()

void XMP_CloseLibrary ( void )

Definition at line 398 of file snd_xmp.c.

399{
401}
static dllhandle_t xmp_dll
Definition snd_xmp.c:331
void Sys_FreeLibrary(dllhandle_t *handle)
Definition sys_shared.c:245

References Sys_FreeLibrary(), and xmp_dll.

Referenced by S_Terminate().

◆ XMP_FreeSfx()

static void XMP_FreeSfx ( sfx_t * sfx)
static

Definition at line 578 of file snd_xmp.c.

579{
580 xmp_stream_persfx_t* per_sfx = (xmp_stream_persfx_t *)sfx->fetcher_data;
581 // free the complete file we were keeping around
582 Mem_Free(per_sfx->file);
583 // free the file information structure
584 Mem_Free(per_sfx);
585}
#define Mem_Free(mem)
Definition zone.h:96

References xmp_stream_persfx_t::file, and Mem_Free.

◆ XMP_GetSamplesFloat()

static void XMP_GetSamplesFloat ( channel_t * ch,
sfx_t * sfx,
int firstsampleframe,
int numsampleframes,
float * outsamplesfloat )
static

Definition at line 436 of file snd_xmp.c.

437{
438 int i, len = numsampleframes * sfx->format.channels;
439 int f = sfx->format.width * sfx->format.channels; // bytes per frame in the buffer
441 xmp_stream_persfx_t* per_sfx = (xmp_stream_persfx_t *)sfx->fetcher_data;
442 const short *buf;
443 int newlength, done;
444 unsigned int format = 0;
445
446 // if this channel does not yet have a channel fetcher, make one
447 if (per_ch == NULL)
448 {
449 // allocate a struct to keep track of our file position and buffer
450 per_ch = (xmp_stream_perchannel_t *)Mem_Alloc(snd_mempool, sizeof(*per_ch));
451
452 // create an xmp file context
453 if ((per_ch->playercontext = qxmp_create_context()) == NULL)
454 {
455 //Con_Printf("error getting a libxmp file context; while trying to load file \"%s\"\n", filename);
456 Mem_Free(per_ch);
457 return;
458 }
459 // copy file to xmp
460 if (qxmp_load_module_from_memory(per_ch->playercontext, (void *)per_sfx->file, (long)per_sfx->filesize) < 0)
461 {
462 qxmp_free_context(per_ch->playercontext);
463 Mem_Free(per_ch);
464 return;
465 }
466
467 // start playing the loaded file
468 if (sfx->format.width == 1) { format |= XMP_FORMAT_8BIT | XMP_FORMAT_UNSIGNED; } // else 16bit
469 if (sfx->format.channels == 1) { format |= XMP_FORMAT_MONO; } // else stereo
470
471 if (qxmp_start_player(per_ch->playercontext, sfx->format.speed, format) < 0)
472 {
473 Mem_Free(per_ch);
474 return;
475 }
476 /* percentual left/right channel separation, default is 70. */
477 if (sfx->format.channels == 2 && (qxmp_set_player(per_ch->playercontext, XMP_PLAYER_MIX, 50) != 0))
478 {
479 Mem_Free(per_ch);
480 return;
481 }
482 /* interpolation type, default is XMP_INTERP_LINEAR */
483 if (qxmp_set_player(per_ch->playercontext, XMP_PLAYER_INTERP, XMP_INTERP_SPLINE) != 0)
484 {
485 Mem_Free(per_ch);
486 return;
487 }
488
489 per_ch->bs = 0;
490 per_ch->buffer_firstframe = 0;
491 per_ch->buffer_numframes = 0;
492 // attach the struct to our channel
493 ch->fetcher_data = (void *)per_ch;
494
495 // reset internal xmp state / syncs buffer start with frame start
496 qxmp_play_buffer(per_ch->playercontext, NULL, 0, 0);
497 }
498
499 // if the request is too large for our buffer, loop...
500 while (numsampleframes * f > (int)sizeof(per_ch->buffer))
501 {
502 done = sizeof(per_ch->buffer) / f;
503 XMP_GetSamplesFloat(ch, sfx, firstsampleframe, done, outsamplesfloat);
504 firstsampleframe += done;
505 numsampleframes -= done;
506 outsamplesfloat += done * sfx->format.channels;
507 }
508
509 // seek if the request is before the current buffer (loop back)
510 // seek if the request starts beyond the current buffer by at least one frame (channel was zero volume for a while)
511 // do not seek if the request overlaps the buffer end at all (expected behavior)
512 if (per_ch->buffer_firstframe > firstsampleframe || per_ch->buffer_firstframe + per_ch->buffer_numframes < firstsampleframe)
513 {
514 // we expect to decode forward from here so this will be our new buffer start
515 per_ch->buffer_firstframe = firstsampleframe;
516 per_ch->buffer_numframes = 0;
517 // no seeking at this time
518 }
519
520 // render the file to pcm as needed
521 if (firstsampleframe + numsampleframes > per_ch->buffer_firstframe + per_ch->buffer_numframes)
522 {
523 // first slide the buffer back, discarding any data preceding the range we care about
524 int offset = firstsampleframe - per_ch->buffer_firstframe;
525 int keeplength = per_ch->buffer_numframes - offset;
526 if (keeplength > 0)
527 memmove(per_ch->buffer, per_ch->buffer + offset * sfx->format.width * sfx->format.channels, keeplength * sfx->format.width * sfx->format.channels);
528 per_ch->buffer_firstframe = firstsampleframe;
529 per_ch->buffer_numframes -= offset;
530 // render as much as we can fit in the buffer
531 newlength = sizeof(per_ch->buffer) - per_ch->buffer_numframes * f;
532 done = 0;
533// while (newlength > done && qxmp_play_buffer(per_ch->playercontext, (void *)((char *)per_ch->buffer + done), (int)(newlength - done), 1) == 0) // don't loop by default (TODO: fix pcm duration calculation first)
534 while (newlength > done && qxmp_play_buffer(per_ch->playercontext, (void *)((char *)per_ch->buffer + done), (int)(newlength - done), 0) == 0) // loop forever
535 {
536 done += (int)(newlength - done);
537 }
538 // clear the missing space if any
539 if (done < newlength)
540 {
541 memset(per_ch->buffer + done, 0, newlength - done);
542 }
543 // we now have more data in the buffer
544 per_ch->buffer_numframes += done / f;
545 }
546
547 // convert the sample format for the caller
548 buf = (short *)((char *)per_ch->buffer + (firstsampleframe - per_ch->buffer_firstframe) * f);
549 for (i = 0;i < len;i++)
550 outsamplesfloat[i] = buf[i] * (1.0f / 32768.0f);
551}
static int(ZEXPORT *qz_inflate)(z_stream *strm
GLint GLint GLint GLsizei GLsizei GLenum format
Definition glquake.h:649
GLuint GLuint GLintptr offset
Definition glquake.h:632
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glquake.h:657
int i
#define NULL
Definition qtypes.h:12
float f
mempool_t * snd_mempool
Definition snd_main.c:144
#define XMP_INTERP_SPLINE
Definition snd_xmp.c:110
#define XMP_FORMAT_UNSIGNED
Definition snd_xmp.c:91
#define XMP_PLAYER_INTERP
Definition snd_xmp.c:97
#define XMP_FORMAT_MONO
Definition snd_xmp.c:92
static int(* qxmp_play_buffer)(xmp_context, void *, int, int)
Definition snd_xmp.c:240
#define XMP_PLAYER_MIX
Definition snd_xmp.c:96
static void XMP_GetSamplesFloat(channel_t *ch, sfx_t *sfx, int firstsampleframe, int numsampleframes, float *outsamplesfloat)
Definition snd_xmp.c:436
static xmp_context(* qxmp_create_context)(void)
Definition snd_xmp.c:232
static int(* qxmp_load_module_from_memory)(xmp_context, void *, long)
Definition snd_xmp.c:257
static void(* qxmp_free_context)(xmp_context)
Definition snd_xmp.c:233
static int(* qxmp_start_player)(xmp_context, int, int)
Definition snd_xmp.c:238
#define XMP_FORMAT_8BIT
Definition snd_xmp.c:90
static int(* qxmp_set_player)(xmp_context, int, int)
Definition snd_xmp.c:254
void * fetcher_data
Per-channel data for the sound fetching function.
Definition snd_main.h:96
unsigned char * file
Definition snd_xmp.c:416
#define Mem_Alloc(pool, size)
Definition zone.h:92

References xmp_stream_perchannel_t::bs, buf, xmp_stream_perchannel_t::buffer, xmp_stream_perchannel_t::buffer_firstframe, xmp_stream_perchannel_t::buffer_numframes, f, channel_t::fetcher_data, xmp_stream_persfx_t::file, xmp_stream_persfx_t::filesize, format, i, int(), Mem_Alloc, Mem_Free, NULL, offset, xmp_stream_perchannel_t::playercontext, qxmp_create_context, qxmp_free_context, qxmp_load_module_from_memory, qxmp_play_buffer, qxmp_set_player, qxmp_start_player, snd_mempool, XMP_FORMAT_8BIT, XMP_FORMAT_MONO, XMP_FORMAT_UNSIGNED, XMP_GetSamplesFloat(), XMP_INTERP_SPLINE, XMP_PLAYER_INTERP, and XMP_PLAYER_MIX.

Referenced by XMP_GetSamplesFloat().

◆ XMP_LoadModFile()

qbool XMP_LoadModFile ( const char * filename,
sfx_t * sfx )

Definition at line 596 of file snd_xmp.c.

597{
598 fs_offset_t filesize;
599 unsigned char *data;
600 xmp_context xc;
601 xmp_stream_persfx_t* per_sfx;
602 struct xmp_module_info mi;
603
604#ifndef LINK_TO_LIBXMP
605 if (!xmp_dll)
606 return false;
607#endif
608
609// COMMANDLINEOPTION: Sound: -noxmp disables xmp module sound support
610 if (Sys_CheckParm("-noxmp"))
611 return false;
612
613 // Return if already loaded
614 if (sfx->fetcher != NULL)
615 return true;
616
617 // Load the file
618 data = FS_LoadFile(filename, snd_mempool, false, &filesize);
619 if (data == NULL)
620 return false;
621
622 // Create an xmp file context
623 if ((xc = qxmp_create_context()) == NULL)
624 {
625 Con_Printf("error creating a libxmp file context; while trying to load file \"%s\"\n", filename);
626 Mem_Free(data);
627 return false;
628 }
629
630 if (developer_loading.integer >= 2)
631 Con_Printf("Loading Module file (libxmp) \"%s\"\n", filename);
632
633 if (qxmp_load_module_from_memory(xc, (void *)data, (long)filesize) < 0) // Added in libxmp 4.2
634 {
635 Con_Printf("error while trying to load xmp module \"%s\"\n", filename);
637 Mem_Free(data);
638 return false;
639 }
640
641 if (developer_loading.integer >= 2)
642 Con_Printf ("\"%s\" will be streamed\n", filename);
643
644 // keep the file around
645 per_sfx = (xmp_stream_persfx_t *)Mem_Alloc (snd_mempool, sizeof (*per_sfx));
646 per_sfx->file = data;
647 per_sfx->filesize = filesize;
648 // set dp sfx
649 sfx->memsize += sizeof(*per_sfx);
650 sfx->memsize += filesize; // total memory used (including sfx_t and fetcher data)
652 sfx->format.speed = 48000;
653 else if (S_GetSoundRate() < XMP_MIN_SRATE)
654 sfx->format.speed = 8000;
655 else
656 sfx->format.speed = S_GetSoundRate();
657 sfx->format.width = S_GetSoundWidth(); // 2 = 16 bit samples
658 sfx->format.channels = S_GetSoundChannels();
659 sfx->flags |= SFXFLAG_STREAMED; // cf SFXFLAG_* defines
660 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!)
661 sfx->loopstart = sfx->total_length; // (modplug does it) in sample frames. equals total_length if not looped
662 sfx->fetcher_data = per_sfx;
663 sfx->fetcher = &xmp_fetcher;
664 sfx->volume_peak = 0;
665
666 qxmp_get_module_info(xc, &mi);
667 if (developer_loading.integer >= 2)
668 {
669 Con_Printf("Decoding module (libxmp):\n"
670 " Module name : %s\n"
671 " Module type : %s\n"
672 " Module length: %i patterns\n"
673 " Patterns : %i\n"
674 " Instruments : %i\n"
675 " Samples : %i\n"
676 " Channels : %i\n"
677 " Initial Speed: %i\n"
678 " Initial BPM : %i\n"
679 " Restart Pos. : %i\n"
680 " Global Volume: %i\n",
681 mi.mod->name, mi.mod->type,
682 mi.mod->len, mi.mod->pat, mi.mod->ins, mi.mod->smp, mi.mod->chn,
683 mi.mod->spd, mi.mod->bpm, mi.mod->rst, mi.mod->gvl
684 );
685 }
686 else if (developer_loading.integer == 1)
687 Con_Printf("Decoding module (libxmp) \"%s\" (%s)\n", mi.mod->name, mi.mod->type);
688
690 return true;
691}
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
unsigned char * FS_LoadFile(const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
Definition fs.c:3540
int64_t fs_offset_t
Definition fs.h:37
GLsizeiptr const GLvoid * data
Definition glquake.h:639
cvar_t developer_loading
Definition host.c:52
int S_GetSoundRate(void)
Definition snd_main.c:377
int S_GetSoundChannels(void)
Definition snd_main.c:382
int S_GetSoundWidth(void)
Definition snd_main.c:387
#define SFXFLAG_STREAMED
informative only. You shouldn't need to know that
Definition snd_main.h:62
#define XMP_MAX_SRATE
Definition snd_xmp.c:125
char * xmp_context
Definition snd_xmp.c:141
static const snd_fetcher_t xmp_fetcher
Definition snd_xmp.c:587
static void(* qxmp_get_module_info)(xmp_context, struct xmp_module_info *)
Definition snd_xmp.c:244
#define XMP_MIN_SRATE
Definition snd_xmp.c:126
int integer
Definition cvar.h:73
int Sys_CheckParm(const char *parm)
Definition sys_shared.c:327

References xmp_module::bpm, xmp_module::chn, Con_Printf(), data, developer_loading, xmp_stream_persfx_t::file, xmp_stream_persfx_t::filesize, FS_LoadFile(), xmp_module::gvl, xmp_module::ins, cvar_t::integer, xmp_module::len, Mem_Alloc, Mem_Free, xmp_module_info::mod, xmp_module::name, NULL, xmp_module::pat, qxmp_create_context, qxmp_free_context, qxmp_get_module_info, qxmp_load_module_from_memory, xmp_module::rst, S_GetSoundChannels(), S_GetSoundRate(), S_GetSoundWidth(), SFXFLAG_STREAMED, xmp_module::smp, snd_mempool, xmp_module::spd, Sys_CheckParm(), xmp_module::type, xmp_dll, xmp_fetcher, XMP_MAX_SRATE, and XMP_MIN_SRATE.

Referenced by S_LoadSound().

◆ XMP_OpenLibrary()

qbool XMP_OpenLibrary ( void )

Definition at line 349 of file snd_xmp.c.

350{
351 const char* dllnames_xmp [] =
352 {
353#if defined(WIN32)
354 "libxmp-4.dll",
355 "libxmp.dll",
356#elif defined(MACOSX) // FIXME: untested, please test a mac os build
357 "libxmp.4.dylib",
358 "libxmp.dylib",
359#else
360 "libxmp.so.4",
361 "libxmp.so",
362#endif
363 NULL
364 };
365
366 if (xmp_dll) // Already loaded?
367 return true;
368
369// COMMANDLINEOPTION: Sound: -noxmp disables xmp module sound support
370 if (Sys_CheckParm("-noxmp"))
371 return false;
372
373 // Load the DLL
374 if (Sys_LoadDependency (dllnames_xmp, &xmp_dll, xmpfuncs))
375 {
376 if (*qxmp_vercode < 0x040200)
377 {
378 Con_Printf("Found incompatible XMP library version %s, not loading. (4.2.0 or higher required)\n", *qxmp_version);
380 return false;
381 }
382 if (developer_loading.integer >= 1)
383 Con_Printf("XMP library loaded, version %s (0x0%x)\n", *qxmp_version, *qxmp_vercode);
384 return true;
385 }
386 else
387 return false;
388}
static const unsigned int * qxmp_vercode
Definition snd_xmp.c:144
static const char ** qxmp_version
Definition snd_xmp.c:143
static dllfunction_t xmpfuncs[]
Definition snd_xmp.c:281
qbool Sys_LoadDependency(const char **dllnames, dllhandle_t *handle, const dllfunction_t *fcts)
Definition sys_shared.c:131

References Con_Printf(), developer_loading, cvar_t::integer, NULL, qxmp_vercode, qxmp_version, Sys_CheckParm(), Sys_FreeLibrary(), Sys_LoadDependency(), xmp_dll, and xmpfuncs.

Referenced by S_Init().

◆ XMP_StopChannel()

static void XMP_StopChannel ( channel_t * ch)
static

Definition at line 558 of file snd_xmp.c.

559{
561 if (per_ch != NULL)
562 {
563 // stop the player
564 qxmp_end_player(per_ch->playercontext);
565 // free the module
566 qxmp_release_module(per_ch->playercontext);
567 // free the xmp playercontext
568 qxmp_free_context(per_ch->playercontext);
569 Mem_Free(per_ch);
570 }
571}
static void(* qxmp_end_player)(xmp_context)
Definition snd_xmp.c:242
static void(* qxmp_release_module)(xmp_context)
Definition snd_xmp.c:237

References channel_t::fetcher_data, Mem_Free, NULL, xmp_stream_perchannel_t::playercontext, qxmp_end_player, qxmp_free_context, and qxmp_release_module.

Variable Documentation

◆ qxmp_create_context

xmp_context(* qxmp_create_context) (void) ( void )
static

Definition at line 232 of file snd_xmp.c.

Referenced by XMP_GetSamplesFloat(), and XMP_LoadModFile().

◆ qxmp_end_player

void(* qxmp_end_player) (xmp_context) ( xmp_context )
static

Definition at line 242 of file snd_xmp.c.

Referenced by XMP_StopChannel().

◆ qxmp_free_context

void(* qxmp_free_context) (xmp_context) ( xmp_context )
static

Definition at line 233 of file snd_xmp.c.

Referenced by XMP_GetSamplesFloat(), XMP_LoadModFile(), and XMP_StopChannel().

◆ qxmp_get_frame_info

void(* qxmp_get_frame_info) (xmp_context, struct xmp_frame_info *) ( xmp_context ,
struct xmp_frame_info *  )
static

Definition at line 241 of file snd_xmp.c.

◆ qxmp_get_module_info

void(* qxmp_get_module_info) (xmp_context, struct xmp_module_info *) ( xmp_context ,
struct xmp_module_info *  )
static

Definition at line 244 of file snd_xmp.c.

Referenced by XMP_LoadModFile().

◆ qxmp_get_player

int(* qxmp_get_player) (xmp_context, int) ( xmp_context ,
int  )
static

Definition at line 255 of file snd_xmp.c.

◆ qxmp_load_module_from_memory

int(* qxmp_load_module_from_memory) (xmp_context, void *, long) ( xmp_context ,
void * ,
long  )
static

Definition at line 257 of file snd_xmp.c.

Referenced by XMP_GetSamplesFloat(), and XMP_LoadModFile().

◆ qxmp_play_buffer

int(* qxmp_play_buffer) (xmp_context, void *, int, int) ( xmp_context ,
void * ,
int ,
int  )
static

Definition at line 240 of file snd_xmp.c.

Referenced by XMP_GetSamplesFloat().

◆ qxmp_play_frame

int(* qxmp_play_frame) (xmp_context) ( xmp_context )
static

Definition at line 239 of file snd_xmp.c.

◆ qxmp_release_module

void(* qxmp_release_module) (xmp_context) ( xmp_context )
static

Definition at line 237 of file snd_xmp.c.

Referenced by XMP_StopChannel().

◆ qxmp_set_player

int(* qxmp_set_player) (xmp_context, int, int) ( xmp_context ,
int ,
int  )
static

Definition at line 254 of file snd_xmp.c.

Referenced by XMP_GetSamplesFloat().

◆ qxmp_start_player

int(* qxmp_start_player) (xmp_context, int, int) ( xmp_context ,
int ,
int  )
static

Definition at line 238 of file snd_xmp.c.

Referenced by XMP_GetSamplesFloat().

◆ qxmp_vercode

const unsigned int* qxmp_vercode
static

Definition at line 144 of file snd_xmp.c.

Referenced by XMP_OpenLibrary().

◆ qxmp_version

const char** qxmp_version
static

Definition at line 143 of file snd_xmp.c.

Referenced by XMP_OpenLibrary().

◆ xmp_dll

dllhandle_t xmp_dll = NULL
static

Definition at line 331 of file snd_xmp.c.

Referenced by XMP_CloseLibrary(), XMP_LoadModFile(), and XMP_OpenLibrary().

◆ xmp_fetcher

const snd_fetcher_t xmp_fetcher = { XMP_GetSamplesFloat, XMP_StopChannel, XMP_FreeSfx }
static

Definition at line 587 of file snd_xmp.c.

static void XMP_FreeSfx(sfx_t *sfx)
Definition snd_xmp.c:578
static void XMP_StopChannel(channel_t *ch)
Definition snd_xmp.c:558

Referenced by XMP_LoadModFile().

◆ xmpfuncs

dllfunction_t xmpfuncs[]
static

Definition at line 281 of file snd_xmp.c.

282{
283 /* libxmp ABI */
284 // Version and player information
285 {"xmp_version", (void **) &qxmp_version},
286 {"xmp_vercode", (void **) &qxmp_vercode},
287// {"xmp_get_format_list", (void **) &qxmp_get_format_list},
288 // Context creation
289 {"xmp_create_context", (void **) &qxmp_create_context},
290 {"xmp_free_context", (void **) &qxmp_free_context},
291 // Module loading
292// {"xmp_test_module", (void **) &qxmp_test_module},
293// {"xmp_load_module", (void **) &qxmp_load_module},
294 {"xmp_load_module_from_memory", (void **) &qxmp_load_module_from_memory}, // since libxmp 4.2.0
295// {"xmp_load_module_from_file", (void **) &qxmp_load_module_from_file}, // since libxmp 4.3.0
296 {"xmp_release_module", (void **) &qxmp_release_module},
297// {"xmp_scan_module", (void **) &qxmp_scan_module},
298 {"xmp_get_module_info", (void **) &qxmp_get_module_info},
299 // Module playing
300 {"xmp_start_player", (void **) &qxmp_start_player},
301 {"xmp_play_frame", (void **) &qxmp_play_frame},
302 {"xmp_play_buffer", (void **) &qxmp_play_buffer},
303 {"xmp_get_frame_info", (void **) &qxmp_get_frame_info},
304 {"xmp_end_player", (void **) &qxmp_end_player},
305 // Player control
306// {"xmp_next_position", (void **) &qxmp_next_position},
307// {"xmp_prev_position", (void **) &qxmp_prev_position},
308// {"xmp_set_position", (void **) &qxmp_set_position},
309// {"xmp_stop_module", (void **) &qxmp_stop_module},
310// {"xmp_restart_module", (void **) &qxmp_restart_module},
311// {"xmp_seek_time", (void **) &qxmp_seek_time},
312// {"xmp_channel_mute", (void **) &qxmp_channel_mute},
313// {"xmp_channel_vol", (void **) &qxmp_channel_vol},
314// {"xmp_inject_event", (void **) &qxmp_inject_event},
315 // Player parameter setting
316// {"xmp_set_instrument_path", (void **) &qxmp_set_instrument_path},
317 {"xmp_get_player", (void **) &qxmp_get_player},
318 {"xmp_set_player", (void **) &qxmp_set_player},
319 /* smix */ // for completeness sake only, right now
320// {"xmp_start_smix", (void **) &qxmp_start_smix},
321// {"xmp_end_smix", (void **) &qxmp_end_smix},
322// {"xmp_smix_play_instrument", (void **) &qxmp_smix_play_instrument},
323// {"xmp_smix_play_sample", (void **) &qxmp_smix_play_sample},
324// {"xmp_smix_channel_pan", (void **) &qxmp_smix_channel_pan},
325// {"xmp_smix_load_sample", (void **) &qxmp_smix_load_sample},
326// {"xmp_smix_release_sample", (void **) &qxmp_smix_release_sample},
327 {NULL, NULL}
328};
static int(* qxmp_play_frame)(xmp_context)
Definition snd_xmp.c:239
static int(* qxmp_get_player)(xmp_context, int)
Definition snd_xmp.c:255
static void(* qxmp_get_frame_info)(xmp_context, struct xmp_frame_info *)
Definition snd_xmp.c:241

Referenced by XMP_OpenLibrary().