2001-04-10 09:40:09 +00:00
|
|
|
/*
|
|
|
|
snd_mem.c
|
|
|
|
|
2022-06-04 09:45:11 +00:00
|
|
|
sound memory management
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2022-06-04 09:45:11 +00:00
|
|
|
Copyright (C) 2003 Bill Currie <bill@taniwha.org>
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-04-10 09:40:09 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2003-04-09 05:55:41 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-04-10 21:45:42 +00:00
|
|
|
#include "QF/sound.h"
|
2001-04-10 09:40:09 +00:00
|
|
|
#include "QF/sys.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/qendian.h"
|
|
|
|
#include "QF/quakefs.h"
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2003-04-11 01:17:48 +00:00
|
|
|
#include "compat.h"
|
2011-07-23 06:56:22 +00:00
|
|
|
#include "snd_internal.h"
|
2003-01-31 20:51:04 +00:00
|
|
|
|
2003-04-17 17:43:21 +00:00
|
|
|
#define SAMPLE_GAP 4
|
|
|
|
|
2022-06-04 09:45:11 +00:00
|
|
|
static uint32_t snd_mem_size;
|
|
|
|
static cvar_t snd_mem_size_cvar = {
|
|
|
|
.name = "snd_mem_size",
|
|
|
|
.description =
|
|
|
|
"Amount of LOCKED memory to allocate to the sound system in MB. "
|
|
|
|
"Defaults to 32MB.",
|
|
|
|
.default_value = "32",
|
|
|
|
.flags = CVAR_ROM,
|
|
|
|
.value = { .type = &cexpr_uint, .value = &snd_mem_size },
|
|
|
|
};
|
|
|
|
|
|
|
|
static memzone_t *snd_zone;
|
|
|
|
|
|
|
|
void
|
|
|
|
SND_Memory_Init_Cvars (void)
|
|
|
|
{
|
|
|
|
Cvar_Register (&snd_mem_size_cvar, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
snd_zone_error (void *data, const char *msg)
|
|
|
|
{
|
|
|
|
Sys_Error ("Sound: %s", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
snd_memory_shutdown (void *data)
|
|
|
|
{
|
|
|
|
if (snd_zone) {
|
|
|
|
size_t size = snd_mem_size * 1024 * 1024;
|
|
|
|
Sys_Free (snd_zone, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SND_Memory_Init (void)
|
|
|
|
{
|
|
|
|
size_t size = snd_mem_size * 1024 * 1024;
|
|
|
|
|
|
|
|
snd_zone = Sys_Alloc (size);
|
|
|
|
if (!snd_zone) {
|
|
|
|
Sys_Printf ("Sound: Unable to allocate %uMB buffer\n", snd_mem_size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!Sys_LockMemory (snd_zone, size)) {
|
|
|
|
Sys_Printf ("Sound: Unable to lock %uMB buffer\n", snd_mem_size);
|
|
|
|
Sys_Free (snd_zone, size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
Z_ClearZone (snd_zone, size, 0, 1);
|
|
|
|
Z_SetError (snd_zone, snd_zone_error, 0);
|
|
|
|
|
|
|
|
Sys_MaskPrintf (SYS_snd, "Sound: Initialized %uMB buffer\n", snd_mem_size);
|
|
|
|
|
|
|
|
Sys_RegisterShutdown (snd_memory_shutdown, 0);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sfxbuffer_t *
|
|
|
|
SND_Memory_AllocBuffer (unsigned samples)
|
|
|
|
{
|
|
|
|
size_t size = field_offset (sfxbuffer_t, data[samples]);
|
|
|
|
// Z_Malloc (currently) clears memory, don't need that for the whole
|
|
|
|
// buffer (just the header), but Z_TagMalloc // does not
|
|
|
|
// +4 for sentinel
|
|
|
|
sfxbuffer_t *buffer = Z_TagMalloc (snd_zone, size + 4, 1);
|
2022-06-04 16:42:30 +00:00
|
|
|
if (buffer) {
|
|
|
|
// place a sentinel at the end of the buffer for added safety
|
|
|
|
memcpy (&buffer->data[samples], "\xde\xad\xbe\xef", 4);
|
|
|
|
// clear buffer header
|
|
|
|
memset (buffer, 0, sizeof (sfxbuffer_t));
|
|
|
|
} else {
|
|
|
|
Sys_Printf ("Sound: out of memory: %uMB exhausted\n", snd_mem_size);
|
|
|
|
}
|
2022-06-04 09:45:11 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-06-05 07:57:13 +00:00
|
|
|
SND_Memory_Free (void *ptr)
|
2022-06-04 09:45:11 +00:00
|
|
|
{
|
2022-06-05 07:57:13 +00:00
|
|
|
Z_Free (snd_zone, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SND_Memory_SetTag (void *ptr, int tag)
|
|
|
|
{
|
|
|
|
Z_SetTag (snd_zone, ptr, tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SND_Memory_Retain (void *ptr)
|
|
|
|
{
|
|
|
|
return Z_IncRetainCount (snd_zone, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SND_Memory_Release (void *ptr)
|
|
|
|
{
|
|
|
|
int retain = Z_DecRetainCount (snd_zone, ptr);
|
|
|
|
if (!retain) {
|
|
|
|
Z_Free (snd_zone, ptr);
|
|
|
|
}
|
|
|
|
return retain;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SND_Memory_GetRetainCount (void *ptr)
|
|
|
|
{
|
|
|
|
return Z_GetRetainCount (snd_zone, ptr);
|
2022-06-04 09:45:11 +00:00
|
|
|
}
|
|
|
|
|
2003-04-11 01:17:48 +00:00
|
|
|
static sfxbuffer_t *
|
|
|
|
snd_fail (sfx_t *sfx)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
snd_noop (sfx_t *sfx)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-06-05 07:57:13 +00:00
|
|
|
static sfxbuffer_t *
|
2003-04-20 07:19:51 +00:00
|
|
|
snd_open (sfx_t *sfx)
|
|
|
|
{
|
2022-06-05 07:57:13 +00:00
|
|
|
sfxbuffer_t *buffer = sfx->block->buffer;
|
|
|
|
SND_Memory_Retain (buffer);
|
|
|
|
return buffer;
|
2003-04-20 07:19:51 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 07:57:13 +00:00
|
|
|
static sfxbuffer_t *
|
2007-05-21 21:40:59 +00:00
|
|
|
snd_open_fail (sfx_t *sfx)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-05 07:57:13 +00:00
|
|
|
sfxbuffer_t * __attribute__((pure))
|
2003-04-11 18:59:14 +00:00
|
|
|
SND_CacheTouch (sfx_t *sfx)
|
|
|
|
{
|
2022-06-05 07:57:13 +00:00
|
|
|
return sfx->block->buffer;
|
2003-04-11 18:59:14 +00:00
|
|
|
}
|
|
|
|
|
2007-03-18 10:32:01 +00:00
|
|
|
sfxbuffer_t *
|
|
|
|
SND_CacheGetBuffer (sfx_t *sfx)
|
|
|
|
{
|
2022-06-05 07:57:13 +00:00
|
|
|
return sfx->block->buffer;
|
2007-03-18 10:32:01 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 07:57:13 +00:00
|
|
|
sfxbuffer_t * __attribute__((pure))
|
2003-04-11 01:17:48 +00:00
|
|
|
SND_CacheRetain (sfx_t *sfx)
|
|
|
|
{
|
2022-06-05 07:57:13 +00:00
|
|
|
return sfx->block->buffer;
|
2003-04-11 01:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SND_CacheRelease (sfx_t *sfx)
|
|
|
|
{
|
2007-03-18 10:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sfxbuffer_t *
|
|
|
|
SND_StreamGetBuffer (sfx_t *sfx)
|
|
|
|
{
|
2022-06-05 07:57:13 +00:00
|
|
|
return sfx->stream->buffer;
|
2003-04-11 01:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sfxbuffer_t *
|
|
|
|
SND_StreamRetain (sfx_t *sfx)
|
|
|
|
{
|
2022-06-05 07:57:13 +00:00
|
|
|
return sfx->stream->buffer;
|
2003-04-11 01:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SND_StreamRelease (sfx_t *sfx)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-04-11 21:14:38 +00:00
|
|
|
wavinfo_t *
|
2022-06-05 07:57:13 +00:00
|
|
|
SND_CacheWavinfo (const sfx_t *sfx)
|
2003-04-11 21:14:38 +00:00
|
|
|
{
|
2022-06-05 07:57:13 +00:00
|
|
|
return &sfx->block->wavinfo;
|
2003-04-11 21:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wavinfo_t *
|
2022-06-05 07:57:13 +00:00
|
|
|
SND_StreamWavinfo (const sfx_t *sfx)
|
2003-04-11 21:14:38 +00:00
|
|
|
{
|
2022-06-05 07:57:13 +00:00
|
|
|
return &sfx->stream->wavinfo;
|
2003-04-11 21:14:38 +00:00
|
|
|
}
|
|
|
|
|
2003-04-14 06:11:53 +00:00
|
|
|
static void
|
2009-01-08 07:48:08 +00:00
|
|
|
read_samples (sfxbuffer_t *buffer, int count)
|
2003-04-14 06:11:53 +00:00
|
|
|
{
|
2003-04-17 17:43:21 +00:00
|
|
|
|
2022-06-04 08:05:03 +00:00
|
|
|
if (buffer->head + count > buffer->size) {
|
|
|
|
count -= buffer->size - buffer->head;
|
|
|
|
read_samples (buffer, buffer->size - buffer->head);
|
2009-01-08 07:48:08 +00:00
|
|
|
read_samples (buffer, count);
|
2003-04-14 06:11:53 +00:00
|
|
|
} else {
|
2022-06-05 07:57:13 +00:00
|
|
|
sfxstream_t *stream = buffer->stream;
|
|
|
|
const sfx_t *sfx = stream->sfx;
|
2003-04-14 06:11:53 +00:00
|
|
|
wavinfo_t *info = &stream->wavinfo;
|
2010-08-11 23:47:03 +00:00
|
|
|
float *data = buffer->data + buffer->head * info->channels;
|
|
|
|
int c;
|
2003-04-14 06:11:53 +00:00
|
|
|
|
2010-08-11 23:47:03 +00:00
|
|
|
if ((c = stream->read (stream, data, count)) != count)
|
|
|
|
Sys_Printf ("%s nr %d %d\n", sfx->name, count, c);
|
2003-04-14 06:11:53 +00:00
|
|
|
|
2022-05-21 06:43:18 +00:00
|
|
|
if (c > 0) {
|
|
|
|
buffer->head += count;
|
2022-06-04 08:05:03 +00:00
|
|
|
if (buffer->head >= buffer->size)
|
|
|
|
buffer->head -= buffer->size;
|
2022-05-21 06:43:18 +00:00
|
|
|
}
|
2003-04-14 06:11:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-26 04:30:07 +00:00
|
|
|
static void
|
2022-06-05 07:57:13 +00:00
|
|
|
fill_buffer (const sfx_t *sfx, sfxstream_t *stream, sfxbuffer_t *buffer,
|
2003-04-26 04:30:07 +00:00
|
|
|
wavinfo_t *info, unsigned int headpos)
|
|
|
|
{
|
|
|
|
unsigned int samples;
|
|
|
|
unsigned int loop_samples = 0;
|
|
|
|
|
|
|
|
// find out how many samples can be read into the buffer
|
|
|
|
samples = buffer->tail - buffer->head - SAMPLE_GAP;
|
|
|
|
if (buffer->tail <= buffer->head)
|
2022-06-04 08:05:03 +00:00
|
|
|
samples += buffer->size;
|
2003-04-26 04:30:07 +00:00
|
|
|
|
2022-06-05 07:57:13 +00:00
|
|
|
if (headpos + samples > buffer->sfx_length) {
|
2003-04-26 04:30:07 +00:00
|
|
|
if (sfx->loopstart == (unsigned int)-1) {
|
2022-06-05 07:57:13 +00:00
|
|
|
samples = buffer->sfx_length - headpos;
|
2003-04-26 04:30:07 +00:00
|
|
|
} else {
|
2022-06-05 07:57:13 +00:00
|
|
|
loop_samples = headpos + samples - buffer->sfx_length;
|
2003-04-26 04:30:07 +00:00
|
|
|
samples -= loop_samples;
|
|
|
|
}
|
|
|
|
}
|
2010-08-11 23:44:34 +00:00
|
|
|
if (samples)
|
2009-01-08 07:48:08 +00:00
|
|
|
read_samples (buffer, samples);
|
2003-04-26 04:30:07 +00:00
|
|
|
if (loop_samples) {
|
2010-08-11 23:47:03 +00:00
|
|
|
stream->seek (stream, info->loopstart);
|
2009-01-08 07:48:08 +00:00
|
|
|
read_samples (buffer, loop_samples);
|
2003-04-26 04:30:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SND_StreamSetPos (sfxbuffer_t *buffer, unsigned int pos)
|
|
|
|
{
|
|
|
|
float stepscale;
|
2022-06-05 07:57:13 +00:00
|
|
|
sfxstream_t *stream = buffer->stream;
|
|
|
|
const sfx_t *sfx = stream->sfx;
|
2003-04-26 04:30:07 +00:00
|
|
|
wavinfo_t *info = &stream->wavinfo;
|
|
|
|
|
2021-06-23 15:04:02 +00:00
|
|
|
stepscale = (float) info->rate / sfx->snd->speed;
|
2003-04-26 04:30:07 +00:00
|
|
|
|
|
|
|
buffer->head = buffer->tail = 0;
|
|
|
|
buffer->pos = pos;
|
|
|
|
stream->pos = pos;
|
2010-08-11 23:47:03 +00:00
|
|
|
stream->seek (stream, buffer->pos * stepscale);
|
2003-04-26 04:30:07 +00:00
|
|
|
fill_buffer (sfx, stream, buffer, info, pos);
|
|
|
|
}
|
|
|
|
|
2010-08-13 01:48:20 +00:00
|
|
|
int
|
2003-04-17 00:01:48 +00:00
|
|
|
SND_StreamAdvance (sfxbuffer_t *buffer, unsigned int count)
|
2003-04-14 06:11:53 +00:00
|
|
|
{
|
|
|
|
float stepscale;
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int headpos, samples;
|
2022-06-05 07:57:13 +00:00
|
|
|
sfxstream_t *stream = buffer->stream;
|
|
|
|
const sfx_t *sfx = stream->sfx;
|
2003-04-14 06:11:53 +00:00
|
|
|
wavinfo_t *info = &stream->wavinfo;
|
|
|
|
|
2003-04-20 03:42:19 +00:00
|
|
|
stream->pos += count;
|
|
|
|
count = (stream->pos - buffer->pos) & ~255;
|
|
|
|
if (!count)
|
2010-08-13 01:48:20 +00:00
|
|
|
return 1;
|
2003-04-20 03:42:19 +00:00
|
|
|
|
2021-06-23 15:04:02 +00:00
|
|
|
stepscale = (float) info->rate / sfx->snd->speed;
|
2003-04-14 06:11:53 +00:00
|
|
|
|
|
|
|
// find out how many samples the buffer currently holds
|
2003-04-17 02:40:17 +00:00
|
|
|
samples = buffer->head - buffer->tail;
|
|
|
|
if (buffer->head < buffer->tail)
|
2022-06-04 08:05:03 +00:00
|
|
|
samples += buffer->size;
|
2003-04-14 06:11:53 +00:00
|
|
|
|
|
|
|
// find out where head points to in the stream
|
|
|
|
headpos = buffer->pos + samples;
|
2022-06-05 07:57:13 +00:00
|
|
|
if (headpos >= buffer->sfx_length) {
|
2003-04-17 00:01:48 +00:00
|
|
|
if (sfx->loopstart == (unsigned int)-1)
|
2022-06-05 07:57:13 +00:00
|
|
|
headpos = buffer->sfx_length;
|
2003-04-14 06:11:53 +00:00
|
|
|
else
|
2022-06-05 07:57:13 +00:00
|
|
|
headpos -= buffer->sfx_length - sfx->loopstart;
|
2003-04-14 06:11:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (samples < count) {
|
|
|
|
buffer->head = buffer->tail = 0;
|
|
|
|
buffer->pos += count;
|
2022-06-05 07:57:13 +00:00
|
|
|
if (buffer->pos > buffer->sfx_length) {
|
2003-04-17 00:01:48 +00:00
|
|
|
if (sfx->loopstart == (unsigned int)-1) {
|
2003-04-14 06:11:53 +00:00
|
|
|
// reset the buffer and fill it incase it's needed again
|
2003-04-17 03:58:16 +00:00
|
|
|
buffer->pos = 0;
|
2003-04-14 06:11:53 +00:00
|
|
|
} else {
|
|
|
|
buffer->pos -= sfx->loopstart;
|
2022-06-05 07:57:13 +00:00
|
|
|
buffer->pos %= buffer->sfx_length - sfx->loopstart;
|
2003-04-14 06:11:53 +00:00
|
|
|
buffer->pos += sfx->loopstart;
|
|
|
|
}
|
2003-04-20 03:42:19 +00:00
|
|
|
stream->pos = buffer->pos;
|
2003-04-14 06:11:53 +00:00
|
|
|
}
|
2003-04-17 03:58:16 +00:00
|
|
|
headpos = buffer->pos;
|
2010-08-11 23:47:03 +00:00
|
|
|
stream->seek (stream, buffer->pos * stepscale);
|
2003-04-14 06:11:53 +00:00
|
|
|
} else {
|
|
|
|
buffer->pos += count;
|
2022-06-05 07:57:13 +00:00
|
|
|
if (buffer->pos >= buffer->sfx_length) {
|
2003-04-17 00:01:48 +00:00
|
|
|
if (sfx->loopstart == (unsigned int)-1) {
|
2004-03-01 11:51:01 +00:00
|
|
|
// reset the buffer and fill it in case it's needed again
|
2003-04-17 03:53:54 +00:00
|
|
|
headpos = buffer->pos = 0;
|
2003-04-14 06:11:53 +00:00
|
|
|
buffer->head = buffer->tail = 0;
|
|
|
|
count = 0;
|
2010-08-11 23:47:03 +00:00
|
|
|
stream->seek (stream, buffer->pos * stepscale);
|
2003-04-14 06:11:53 +00:00
|
|
|
} else {
|
2022-06-05 07:57:13 +00:00
|
|
|
buffer->pos -= buffer->sfx_length - sfx->loopstart;
|
2003-04-14 06:11:53 +00:00
|
|
|
}
|
2003-04-20 03:42:19 +00:00
|
|
|
stream->pos = buffer->pos;
|
2003-04-14 06:11:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buffer->tail += count;
|
2022-06-04 08:05:03 +00:00
|
|
|
if (buffer->tail >= buffer->size)
|
|
|
|
buffer->tail -= buffer->size;
|
2003-04-14 06:11:53 +00:00
|
|
|
}
|
2003-04-26 04:30:07 +00:00
|
|
|
fill_buffer (sfx, stream, buffer, info, headpos);
|
2010-08-13 01:48:20 +00:00
|
|
|
return !stream->error;
|
2003-04-14 06:11:53 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 03:02:55 +00:00
|
|
|
int
|
2003-04-11 01:17:48 +00:00
|
|
|
SND_Load (sfx_t *sfx)
|
|
|
|
{
|
|
|
|
char *realname;
|
|
|
|
char buf[4];
|
|
|
|
QFile *file;
|
|
|
|
|
|
|
|
sfx->touch = sfx->retain = snd_fail;
|
|
|
|
sfx->release = snd_noop;
|
2007-05-21 21:40:59 +00:00
|
|
|
sfx->open = snd_open_fail;
|
2003-04-11 01:17:48 +00:00
|
|
|
|
2014-01-23 02:57:57 +00:00
|
|
|
file = QFS_FOpenFile (sfx->name);
|
2003-04-11 01:17:48 +00:00
|
|
|
if (!file) {
|
2004-01-21 02:52:12 +00:00
|
|
|
Sys_Printf ("Couldn't load %s\n", sfx->name);
|
2010-08-08 03:02:55 +00:00
|
|
|
return -1;
|
2003-04-11 01:17:48 +00:00
|
|
|
}
|
2007-05-21 21:40:59 +00:00
|
|
|
sfx->open = snd_open;
|
2013-11-24 13:45:42 +00:00
|
|
|
if (!strequal (qfs_foundfile.realname, sfx->name)) {
|
|
|
|
realname = strdup (qfs_foundfile.realname);
|
2003-04-11 01:17:48 +00:00
|
|
|
} else {
|
2004-01-21 02:52:12 +00:00
|
|
|
realname = (char *) sfx->name; // won't free if realname == sfx->name
|
2003-04-11 01:17:48 +00:00
|
|
|
}
|
|
|
|
Qread (file, buf, 4);
|
|
|
|
Qseek (file, 0, SEEK_SET);
|
2003-04-11 14:38:31 +00:00
|
|
|
#ifdef HAVE_VORBIS
|
2003-04-11 01:17:48 +00:00
|
|
|
if (strnequal ("OggS", buf, 4)) {
|
2022-06-05 08:39:44 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "SND_Load: ogg file\n");
|
2010-08-08 03:02:55 +00:00
|
|
|
if (SND_LoadOgg (file, sfx, realname) == -1)
|
|
|
|
goto bail;
|
|
|
|
return 0;
|
2003-04-11 01:17:48 +00:00
|
|
|
}
|
2003-09-10 05:20:51 +00:00
|
|
|
#endif
|
2005-06-19 05:24:19 +00:00
|
|
|
#ifdef HAVE_FLAC
|
2005-06-15 10:02:50 +00:00
|
|
|
if (strnequal ("fLaC", buf, 4)) {
|
2022-06-05 08:39:44 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "SND_Load: flac file\n");
|
2010-08-08 03:02:55 +00:00
|
|
|
if (SND_LoadFLAC (file, sfx, realname) == -1)
|
|
|
|
goto bail;
|
|
|
|
return 0;
|
2005-06-15 10:02:50 +00:00
|
|
|
}
|
|
|
|
#endif
|
2003-09-10 05:20:51 +00:00
|
|
|
#ifdef HAVE_WILDMIDI
|
|
|
|
if (strnequal ("MThd", buf, 4)) {
|
2022-06-05 08:39:44 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "SND_Load: midi file\n");
|
2010-08-08 03:02:55 +00:00
|
|
|
if (SND_LoadMidi (file, sfx, realname) == -1)
|
|
|
|
goto bail;
|
|
|
|
return 0;
|
2003-09-10 05:20:51 +00:00
|
|
|
}
|
2003-04-11 14:38:31 +00:00
|
|
|
#endif
|
2003-04-11 01:17:48 +00:00
|
|
|
if (strnequal ("RIFF", buf, 4)) {
|
2022-06-05 08:39:44 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "SND_Load: wav file\n");
|
2010-08-08 03:02:55 +00:00
|
|
|
if (SND_LoadWav (file, sfx, realname) == -1)
|
|
|
|
goto bail;
|
|
|
|
return 0;
|
2003-04-11 01:17:48 +00:00
|
|
|
}
|
2010-08-08 03:02:55 +00:00
|
|
|
bail:
|
2003-04-15 02:34:17 +00:00
|
|
|
Qclose (file);
|
2004-01-21 02:52:12 +00:00
|
|
|
if (realname != sfx->name)
|
|
|
|
free (realname);
|
2010-08-08 03:02:55 +00:00
|
|
|
return -1;
|
2003-04-11 01:17:48 +00:00
|
|
|
}
|