2001-04-10 09:40:09 +00:00
|
|
|
/*
|
|
|
|
snd_dma.c
|
|
|
|
|
|
|
|
main control for any streaming sound output device
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
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
|
2001-08-23 04:01:46 +00:00
|
|
|
Boston, MA 02111-1307, USA
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2001-04-10 09:40:09 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2001-10-16 21:40:45 +00:00
|
|
|
#include "winquake.h"
|
2001-04-10 20:07:11 +00:00
|
|
|
|
2001-04-10 09:40:09 +00:00
|
|
|
#include "QF/cmd.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2003-05-08 23:24:02 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-04-10 09:40:09 +00:00
|
|
|
#include "QF/model.h"
|
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/sys.h"
|
2001-04-10 21:45:42 +00:00
|
|
|
#include "QF/sound.h"
|
2001-05-19 00:05:35 +00:00
|
|
|
#include "QF/plugin.h"
|
2004-01-21 02:52:12 +00:00
|
|
|
#include "QF/va.h"
|
2004-02-03 03:01:06 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2003-01-31 20:51:04 +00:00
|
|
|
#include "snd_render.h"
|
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// Internal sound data & structures ===========================================
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2004-01-08 00:25:52 +00:00
|
|
|
volatile dma_t *shm = 0;
|
|
|
|
unsigned int paintedtime; // sample PAIRS
|
|
|
|
|
|
|
|
cvar_t *snd_loadas8bit;
|
|
|
|
cvar_t *volume;
|
|
|
|
cvar_t *snd_interp;
|
|
|
|
|
2003-01-31 20:51:04 +00:00
|
|
|
channel_t channels[MAX_CHANNELS];
|
|
|
|
int total_channels;
|
|
|
|
|
2004-01-21 02:52:12 +00:00
|
|
|
static channel_t *ambient_channels[NUM_AMBIENTS];
|
|
|
|
static channel_t *dynamic_channels[MAX_DYNAMIC_CHANNELS];
|
|
|
|
static channel_t *static_channels[MAX_CHANNELS];
|
|
|
|
static int num_statics;
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static qboolean snd_initialized = false;
|
|
|
|
static int snd_blocked = 0;
|
2001-04-10 09:40:09 +00:00
|
|
|
static qboolean snd_ambient = 1;
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static vec3_t listener_origin;
|
|
|
|
static vec3_t listener_forward;
|
|
|
|
static vec3_t listener_right;
|
|
|
|
static vec3_t listener_up;
|
|
|
|
static vec_t sound_nominal_clip_dist = 1000.0;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static unsigned soundtime; // sample PAIRS
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
#define MAX_SFX 512
|
2004-01-08 01:48:02 +00:00
|
|
|
static sfx_t *known_sfx; // hunk allocated [MAX_SFX]
|
|
|
|
static int num_sfx;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static sfx_t *ambient_sfx[NUM_AMBIENTS];
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static int sound_started = 0;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static cvar_t *ambient_fade;
|
|
|
|
static cvar_t *ambient_level;
|
|
|
|
static cvar_t *nosound;
|
|
|
|
static cvar_t *precache;
|
|
|
|
static cvar_t *snd_mixahead;
|
|
|
|
static cvar_t *snd_noextraupdate;
|
|
|
|
static cvar_t *snd_phasesep;
|
|
|
|
static cvar_t *snd_show;
|
|
|
|
static cvar_t *snd_volumesep;
|
2001-08-23 04:01:46 +00:00
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static general_data_t plugin_info_general_data;
|
|
|
|
static snd_render_data_t render_data = {
|
2003-04-20 02:05:28 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&soundtime,
|
|
|
|
&paintedtime,
|
|
|
|
0,
|
|
|
|
};
|
2001-08-04 18:18:33 +00:00
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static snd_output_funcs_t *snd_output_funcs;
|
2003-01-31 20:19:42 +00:00
|
|
|
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// User-setable variables =====================================================
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
// Fake dma is a synchronous faking of the DMA progress used for
|
|
|
|
// isolating performance in the renderer. The fakedma_updates is
|
2004-01-09 03:48:00 +00:00
|
|
|
// number of times s_update() is called per second.
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static qboolean fakedma = false;
|
|
|
|
//static int fakedma_updates = 15;
|
2001-05-22 12:31:43 +00:00
|
|
|
|
2001-08-27 01:00:03 +00:00
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_ambient_off (void)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
|
|
|
snd_ambient = false;
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_ambient_on (void)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
|
|
|
snd_ambient = true;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_soundinfo_f (void)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
|
|
|
if (!sound_started || !shm) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("sound system not started\n");
|
2001-04-10 09:40:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%5d stereo\n", shm->channels - 1);
|
|
|
|
Sys_Printf ("%5d samples\n", shm->samples);
|
|
|
|
Sys_Printf ("%5d samplepos\n", shm->samplepos);
|
|
|
|
Sys_Printf ("%5d samplebits\n", shm->samplebits);
|
|
|
|
Sys_Printf ("%5d submission_chunk\n", shm->submission_chunk);
|
|
|
|
Sys_Printf ("%5d speed\n", shm->speed);
|
|
|
|
Sys_Printf ("0x%lx dma buffer\n", (unsigned long) shm->buffer);
|
|
|
|
Sys_Printf ("%5d total_channels\n", total_channels);
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_startup (void)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
|
|
|
if (!snd_initialized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!fakedma) {
|
2004-01-08 03:46:11 +00:00
|
|
|
shm = snd_output_funcs->pS_O_Init ();
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2004-01-08 03:46:11 +00:00
|
|
|
if (!shm) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("S_Startup: S_O_Init failed.\n");
|
2001-04-10 09:40:09 +00:00
|
|
|
sound_started = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sound_started = 1;
|
|
|
|
}
|
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// Load a sound ===============================================================
|
2003-01-06 18:28:13 +00:00
|
|
|
static sfx_t *
|
2004-01-21 02:52:12 +00:00
|
|
|
s_load_sound (const char *name)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2001-08-23 04:01:46 +00:00
|
|
|
int i;
|
|
|
|
sfx_t *sfx;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2004-01-26 01:21:06 +00:00
|
|
|
if (!known_sfx)
|
|
|
|
return 0;
|
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// see if already loaded
|
2001-04-10 09:40:09 +00:00
|
|
|
for (i = 0; i < num_sfx; i++)
|
2003-04-11 01:17:48 +00:00
|
|
|
if (known_sfx[i].name && !strcmp (known_sfx[i].name, name)) {
|
2001-04-10 09:40:09 +00:00
|
|
|
return &known_sfx[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_sfx == MAX_SFX)
|
|
|
|
Sys_Error ("S_FindName: out of sfx_t");
|
|
|
|
|
|
|
|
sfx = &known_sfx[i];
|
2003-04-11 01:17:48 +00:00
|
|
|
if (sfx->name)
|
|
|
|
free ((char *) sfx->name);
|
|
|
|
sfx->name = strdup (name);
|
|
|
|
SND_Load (sfx);
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
num_sfx++;
|
|
|
|
|
|
|
|
return sfx;
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_touch_sound (const char *name)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2001-08-23 04:01:46 +00:00
|
|
|
sfx_t *sfx;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
if (!sound_started)
|
|
|
|
return;
|
|
|
|
|
2004-01-21 02:52:12 +00:00
|
|
|
if (!name)
|
|
|
|
Sys_Error ("s_touch_sound: NULL");
|
|
|
|
|
|
|
|
name = va ("sound/%s", name);
|
|
|
|
sfx = s_load_sound (name);
|
2003-04-11 01:17:48 +00:00
|
|
|
sfx->touch (sfx);
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static sfx_t *
|
2004-01-09 03:48:00 +00:00
|
|
|
s_precache_sound (const char *name)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2001-08-23 04:01:46 +00:00
|
|
|
sfx_t *sfx;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
if (!sound_started || nosound->int_val)
|
|
|
|
return NULL;
|
|
|
|
|
2004-01-21 02:52:12 +00:00
|
|
|
if (!name)
|
|
|
|
Sys_Error ("s_precache_sound: NULL");
|
|
|
|
|
|
|
|
name = va ("sound/%s", name);
|
|
|
|
sfx = s_load_sound (name);
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// cache it in
|
2003-04-11 01:17:48 +00:00
|
|
|
if (precache->int_val) {
|
|
|
|
if (sfx->retain (sfx))
|
|
|
|
sfx->release (sfx);
|
|
|
|
}
|
2001-04-10 09:40:09 +00:00
|
|
|
return sfx;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
2004-01-21 02:52:12 +00:00
|
|
|
static channel_t *
|
|
|
|
s_alloc_channel (void)
|
|
|
|
{
|
|
|
|
if (total_channels < MAX_CHANNELS)
|
|
|
|
return &channels[total_channels++];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static channel_t *
|
2004-01-09 03:48:00 +00:00
|
|
|
s_pick_channel (int entnum, int entchannel)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2004-01-21 02:52:12 +00:00
|
|
|
int ch_idx;
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned life_left;
|
2004-01-21 02:52:12 +00:00
|
|
|
channel_t *ch, *first_to_die;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// Check for replacement sound, or find the best one to replace
|
2004-01-21 02:52:12 +00:00
|
|
|
first_to_die = 0;
|
2001-04-10 09:40:09 +00:00
|
|
|
life_left = 0x7fffffff;
|
2004-01-21 02:52:12 +00:00
|
|
|
for (ch_idx = 0; ch_idx < MAX_DYNAMIC_CHANNELS; ch_idx++) {
|
|
|
|
ch = dynamic_channels[ch_idx];
|
2001-04-10 09:40:09 +00:00
|
|
|
if (entchannel != 0 // channel 0 never overrides
|
2004-01-21 02:52:12 +00:00
|
|
|
&& ch->entnum == entnum
|
|
|
|
&& (ch->entchannel == entchannel || entchannel == -1)) {
|
2001-04-10 09:40:09 +00:00
|
|
|
// always override sound from same entity
|
2004-01-21 02:52:12 +00:00
|
|
|
first_to_die = ch;
|
2001-04-10 09:40:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// don't let monster sounds override player sounds
|
2004-01-21 02:52:12 +00:00
|
|
|
if (ch->entnum == *render_data.viewentity
|
2003-04-20 02:05:28 +00:00
|
|
|
&& entnum != *render_data.viewentity
|
2004-01-21 02:52:12 +00:00
|
|
|
&& ch->sfx)
|
2001-04-10 09:40:09 +00:00
|
|
|
continue;
|
|
|
|
|
2004-01-21 02:52:12 +00:00
|
|
|
if (paintedtime + life_left > ch->end) {
|
|
|
|
life_left = ch->end - paintedtime;
|
|
|
|
first_to_die = ch;
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-21 02:52:12 +00:00
|
|
|
if (!first_to_die)
|
2001-04-10 09:40:09 +00:00
|
|
|
return NULL;
|
|
|
|
|
2004-01-21 02:52:12 +00:00
|
|
|
if (first_to_die->sfx) {
|
|
|
|
first_to_die->sfx->close (first_to_die->sfx);
|
|
|
|
first_to_die->sfx = NULL;
|
2003-04-20 07:19:51 +00:00
|
|
|
}
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2004-01-21 02:52:12 +00:00
|
|
|
return first_to_die;
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_spatialize (channel_t *ch)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2001-08-23 04:01:46 +00:00
|
|
|
int phase; // in samples
|
2001-09-09 21:41:35 +00:00
|
|
|
vec_t dist, dot, lscale, rscale, scale;
|
2001-08-23 04:01:46 +00:00
|
|
|
vec3_t source_vec;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// anything coming from the view entity will always be full volume
|
2003-05-28 04:49:09 +00:00
|
|
|
if (ch->entnum == *render_data.viewentity) {
|
2001-04-10 09:40:09 +00:00
|
|
|
ch->leftvol = ch->master_vol;
|
|
|
|
ch->rightvol = ch->master_vol;
|
|
|
|
ch->phase = 0;
|
|
|
|
return;
|
|
|
|
}
|
2001-05-22 12:31:43 +00:00
|
|
|
// calculate stereo seperation and distance attenuation
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
VectorSubtract (ch->origin, listener_origin, source_vec);
|
|
|
|
|
|
|
|
dist = VectorNormalize (source_vec) * ch->dist_mult;
|
|
|
|
|
|
|
|
dot = DotProduct (listener_right, source_vec);
|
|
|
|
|
|
|
|
if (shm->channels == 1) {
|
|
|
|
rscale = 1.0;
|
|
|
|
lscale = 1.0;
|
|
|
|
phase = 0;
|
|
|
|
} else {
|
|
|
|
rscale = 1.0 + dot * snd_volumesep->value;
|
|
|
|
lscale = 1.0 - dot * snd_volumesep->value;
|
|
|
|
phase = snd_phasesep->value * 0.001 * shm->speed * dot;
|
|
|
|
}
|
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// add in distance effect
|
2001-04-10 09:40:09 +00:00
|
|
|
scale = (1.0 - dist) * rscale;
|
|
|
|
ch->rightvol = (int) (ch->master_vol * scale);
|
|
|
|
if (ch->rightvol < 0)
|
|
|
|
ch->rightvol = 0;
|
|
|
|
|
|
|
|
scale = (1.0 - dist) * lscale;
|
|
|
|
ch->leftvol = (int) (ch->master_vol * scale);
|
|
|
|
if (ch->leftvol < 0)
|
|
|
|
ch->leftvol = 0;
|
|
|
|
|
|
|
|
ch->phase = phase;
|
|
|
|
}
|
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// Start a sound effect =======================================================
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_start_sound (int entnum, int entchannel, sfx_t *sfx, const vec3_t origin,
|
2001-08-22 20:26:25 +00:00
|
|
|
float fvol, float attenuation)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2004-03-01 11:51:01 +00:00
|
|
|
int ch_idx, vol;
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int skip;
|
2004-03-01 11:51:01 +00:00
|
|
|
channel_t *target_chan, *check;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
if (!sound_started)
|
|
|
|
return;
|
|
|
|
if (!sfx)
|
|
|
|
return;
|
|
|
|
if (nosound->int_val)
|
|
|
|
return;
|
2001-05-22 12:31:43 +00:00
|
|
|
// pick a channel to play on
|
2004-01-09 03:48:00 +00:00
|
|
|
target_chan = s_pick_channel (entnum, entchannel);
|
2001-04-10 09:40:09 +00:00
|
|
|
if (!target_chan)
|
|
|
|
return;
|
|
|
|
|
2004-03-01 11:51:01 +00:00
|
|
|
vol = fvol * 255;
|
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// spatialize
|
2001-04-10 09:40:09 +00:00
|
|
|
memset (target_chan, 0, sizeof (*target_chan));
|
|
|
|
VectorCopy (origin, target_chan->origin);
|
|
|
|
target_chan->dist_mult = attenuation / sound_nominal_clip_dist;
|
|
|
|
target_chan->master_vol = vol;
|
|
|
|
target_chan->entnum = entnum;
|
|
|
|
target_chan->entchannel = entchannel;
|
2004-01-09 03:48:00 +00:00
|
|
|
s_spatialize (target_chan);
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
if (!target_chan->leftvol && !target_chan->rightvol)
|
|
|
|
return; // not audible at all
|
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// new channel
|
2003-04-11 01:17:48 +00:00
|
|
|
if (!sfx->retain (sfx)) {
|
2003-04-20 07:19:51 +00:00
|
|
|
if (target_chan->sfx)
|
|
|
|
target_chan->sfx->close (target_chan->sfx);
|
2001-04-10 09:40:09 +00:00
|
|
|
target_chan->sfx = NULL;
|
2003-04-11 01:17:48 +00:00
|
|
|
return; // couldn't load the sound's data
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
2003-04-20 07:19:51 +00:00
|
|
|
if (!(target_chan->sfx = sfx->open (sfx))) {
|
|
|
|
sfx->release (sfx);
|
|
|
|
return;
|
|
|
|
}
|
2001-04-10 09:40:09 +00:00
|
|
|
target_chan->pos = 0.0;
|
2003-04-20 07:19:51 +00:00
|
|
|
target_chan->end = paintedtime + target_chan->sfx->length;
|
2003-04-11 01:17:48 +00:00
|
|
|
sfx->release (sfx);
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// if an identical sound has also been started this frame, offset the pos
|
|
|
|
// a bit to keep it from just making the first one louder
|
2004-01-21 02:52:12 +00:00
|
|
|
for (ch_idx = 0; ch_idx < MAX_DYNAMIC_CHANNELS; ch_idx++) {
|
|
|
|
check = dynamic_channels[ch_idx];
|
2001-04-10 09:40:09 +00:00
|
|
|
if (check == target_chan)
|
|
|
|
continue;
|
|
|
|
if (check->sfx == sfx && !check->pos) {
|
|
|
|
skip = rand () % (int) (0.1 * shm->speed);
|
|
|
|
if (skip >= target_chan->end)
|
|
|
|
skip = target_chan->end - 1;
|
|
|
|
target_chan->pos += skip;
|
|
|
|
target_chan->end -= skip;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_stop_sound (int entnum, int entchannel)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2001-08-23 04:01:46 +00:00
|
|
|
int i;
|
2004-01-21 02:52:12 +00:00
|
|
|
channel_t *ch;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2001-08-30 22:11:45 +00:00
|
|
|
if (!sound_started)
|
|
|
|
return;
|
|
|
|
|
2001-04-10 09:40:09 +00:00
|
|
|
for (i = 0; i < MAX_DYNAMIC_CHANNELS; i++) {
|
2004-01-21 02:52:12 +00:00
|
|
|
ch = dynamic_channels[i];
|
|
|
|
if (ch->entnum == entnum && ch->entchannel == entchannel) {
|
|
|
|
ch->end = 0;
|
|
|
|
if (ch->sfx)
|
|
|
|
ch->sfx->close (ch->sfx);
|
|
|
|
ch->sfx = NULL;
|
2001-04-10 09:40:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_clear_buffer (void)
|
2004-01-08 01:48:02 +00:00
|
|
|
{
|
2004-03-01 11:51:01 +00:00
|
|
|
int clear, i;
|
2004-01-08 01:48:02 +00:00
|
|
|
|
|
|
|
if (!sound_started || !shm || !shm->buffer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (shm->samplebits == 8)
|
|
|
|
clear = 0x80;
|
|
|
|
else
|
|
|
|
clear = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < shm->samples * shm->samplebits / 8; i++)
|
|
|
|
shm->buffer[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_stop_all_sounds (qboolean clear)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2001-08-23 04:01:46 +00:00
|
|
|
int i;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
if (!sound_started)
|
|
|
|
return;
|
|
|
|
|
2004-01-21 02:52:12 +00:00
|
|
|
num_statics = 0;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_CHANNELS; i++)
|
2003-04-20 07:19:51 +00:00
|
|
|
if (channels[i].sfx) {
|
|
|
|
channels[i].sfx->close (channels[i].sfx);
|
2001-04-10 09:40:09 +00:00
|
|
|
channels[i].sfx = NULL;
|
2003-04-20 07:19:51 +00:00
|
|
|
}
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
memset (channels, 0, MAX_CHANNELS * sizeof (channel_t));
|
|
|
|
|
|
|
|
if (clear)
|
2004-01-09 03:48:00 +00:00
|
|
|
s_clear_buffer ();
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_stop_all_sounds_f (void)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2004-01-09 03:48:00 +00:00
|
|
|
s_stop_all_sounds (true);
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_static_sound (sfx_t *sfx, const vec3_t origin, float vol,
|
2002-01-03 05:29:38 +00:00
|
|
|
float attenuation)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
|
|
|
channel_t *ss;
|
|
|
|
|
2001-08-30 22:11:45 +00:00
|
|
|
if (!sound_started || !sfx)
|
2001-04-10 09:40:09 +00:00
|
|
|
return;
|
|
|
|
|
2004-01-21 02:52:12 +00:00
|
|
|
if (!static_channels[num_statics]) {
|
|
|
|
if (!(static_channels[num_statics] = s_alloc_channel ())) {
|
|
|
|
Sys_Printf ("ran out of channels\n");
|
|
|
|
return;
|
|
|
|
}
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
2004-01-21 02:52:12 +00:00
|
|
|
ss = static_channels[num_statics];
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2003-04-11 01:17:48 +00:00
|
|
|
if (!sfx->retain (sfx))
|
2001-04-10 09:40:09 +00:00
|
|
|
return;
|
|
|
|
|
2004-03-01 11:51:01 +00:00
|
|
|
if (sfx->loopstart == (unsigned int) -1) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Sound %s not looped\n", sfx->name);
|
2003-04-11 01:17:48 +00:00
|
|
|
sfx->release (sfx);
|
2001-04-10 09:40:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-20 07:19:51 +00:00
|
|
|
if (!(ss->sfx = sfx->open (sfx))) {
|
|
|
|
sfx->release (sfx);
|
|
|
|
return;
|
|
|
|
}
|
2001-04-10 09:40:09 +00:00
|
|
|
VectorCopy (origin, ss->origin);
|
|
|
|
ss->master_vol = vol;
|
|
|
|
ss->dist_mult = (attenuation / 64) / sound_nominal_clip_dist;
|
2003-04-11 01:17:48 +00:00
|
|
|
ss->end = paintedtime + sfx->length;
|
|
|
|
sfx->release (sfx);
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2004-01-09 03:48:00 +00:00
|
|
|
s_spatialize (ss);
|
2001-04-10 09:40:09 +00:00
|
|
|
ss->oldphase = ss->phase;
|
2004-01-21 02:52:12 +00:00
|
|
|
num_statics++;
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_updateAmbientSounds (void)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2001-08-23 04:01:46 +00:00
|
|
|
float vol;
|
|
|
|
int ambient_channel;
|
2001-04-10 09:40:09 +00:00
|
|
|
channel_t *chan;
|
2001-09-09 21:41:35 +00:00
|
|
|
mleaf_t *l;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
if (!snd_ambient)
|
|
|
|
return;
|
2001-05-22 12:31:43 +00:00
|
|
|
// calc ambient sound levels
|
2003-04-20 02:05:28 +00:00
|
|
|
if (!*render_data.worldmodel)
|
2001-04-10 09:40:09 +00:00
|
|
|
return;
|
|
|
|
|
2003-04-20 02:05:28 +00:00
|
|
|
l = Mod_PointInLeaf (listener_origin, *render_data.worldmodel);
|
2001-04-10 09:40:09 +00:00
|
|
|
if (!l || !ambient_level->value) {
|
|
|
|
for (ambient_channel = 0; ambient_channel < NUM_AMBIENTS;
|
2003-04-20 07:19:51 +00:00
|
|
|
ambient_channel++) {
|
2004-01-21 02:52:12 +00:00
|
|
|
chan = ambient_channels[ambient_channel];
|
|
|
|
if (chan->sfx)
|
|
|
|
chan->sfx->close (chan->sfx);
|
|
|
|
chan->sfx = NULL;
|
2003-04-20 07:19:51 +00:00
|
|
|
}
|
2001-04-10 09:40:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-22 20:26:25 +00:00
|
|
|
for (ambient_channel = 0; ambient_channel < NUM_AMBIENTS;
|
|
|
|
ambient_channel++) {
|
2004-01-21 02:52:12 +00:00
|
|
|
chan = ambient_channels[ambient_channel];
|
2003-04-21 01:24:53 +00:00
|
|
|
if (!ambient_sfx[ambient_channel]) {
|
|
|
|
chan->sfx = 0;
|
|
|
|
continue;
|
2003-04-21 01:39:07 +00:00
|
|
|
} else if (!chan->sfx)
|
|
|
|
chan->sfx = ambient_sfx[ambient_channel]->open (ambient_sfx[ambient_channel]);
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
vol = ambient_level->value * l->ambient_sound_level[ambient_channel];
|
|
|
|
if (vol < 8)
|
|
|
|
vol = 0;
|
|
|
|
|
|
|
|
// don't adjust volume too fast
|
|
|
|
if (chan->master_vol < vol) {
|
2003-04-20 02:05:28 +00:00
|
|
|
chan->master_vol += *render_data.host_frametime
|
2001-05-22 12:31:43 +00:00
|
|
|
* ambient_fade->value;
|
2001-04-10 09:40:09 +00:00
|
|
|
if (chan->master_vol > vol)
|
|
|
|
chan->master_vol = vol;
|
|
|
|
} else if (chan->master_vol > vol) {
|
2003-04-20 02:05:28 +00:00
|
|
|
chan->master_vol -= *render_data.host_frametime
|
2001-05-22 12:31:43 +00:00
|
|
|
* ambient_fade->value;
|
2001-04-10 09:40:09 +00:00
|
|
|
if (chan->master_vol < vol)
|
|
|
|
chan->master_vol = vol;
|
|
|
|
}
|
|
|
|
|
|
|
|
chan->leftvol = chan->rightvol = chan->master_vol;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_get_soundtime (void)
|
2002-11-05 19:12:51 +00:00
|
|
|
{
|
|
|
|
int fullsamples, samplepos;
|
|
|
|
static int buffers, oldsamplepos;
|
|
|
|
|
|
|
|
fullsamples = shm->samples / shm->channels;
|
|
|
|
|
|
|
|
// it is possible to miscount buffers if it has wrapped twice between
|
2004-01-09 03:48:00 +00:00
|
|
|
// calls to s_update. Oh well.
|
2003-03-10 21:28:18 +00:00
|
|
|
if ((samplepos = snd_output_funcs->pS_O_GetDMAPos ()) == -1)
|
|
|
|
return;
|
|
|
|
|
2002-11-05 19:12:51 +00:00
|
|
|
if (samplepos < oldsamplepos) {
|
|
|
|
buffers++; // buffer wrapped
|
|
|
|
|
|
|
|
if (paintedtime > 0x40000000) { // time to chop things off to avoid
|
|
|
|
// 32 bit limits
|
|
|
|
buffers = 0;
|
|
|
|
paintedtime = fullsamples;
|
2004-01-09 03:48:00 +00:00
|
|
|
s_stop_all_sounds (true);
|
2002-11-05 19:12:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
oldsamplepos = samplepos;
|
|
|
|
|
|
|
|
soundtime = buffers * fullsamples + samplepos / shm->channels;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_update_ (void)
|
2002-11-05 19:12:51 +00:00
|
|
|
{
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int endtime, samps;
|
2002-11-05 19:12:51 +00:00
|
|
|
|
|
|
|
if (!sound_started || (snd_blocked > 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Updates DMA time
|
2004-01-09 03:48:00 +00:00
|
|
|
s_get_soundtime ();
|
2002-11-05 19:12:51 +00:00
|
|
|
|
|
|
|
// check to make sure that we haven't overshot
|
|
|
|
if (paintedtime < soundtime) {
|
|
|
|
// Sys_Printf ("S_Update_ : overflow\n");
|
|
|
|
paintedtime = soundtime;
|
|
|
|
}
|
|
|
|
// mix ahead of current position
|
|
|
|
endtime = soundtime + snd_mixahead->value * shm->speed;
|
|
|
|
samps = shm->samples >> (shm->channels - 1);
|
|
|
|
if (endtime - soundtime > samps)
|
|
|
|
endtime = soundtime + samps;
|
|
|
|
|
|
|
|
SND_PaintChannels (endtime);
|
2003-01-31 20:19:42 +00:00
|
|
|
snd_output_funcs->pS_O_Submit ();
|
2002-11-05 19:12:51 +00:00
|
|
|
}
|
|
|
|
|
2004-01-21 02:52:12 +00:00
|
|
|
static inline int
|
|
|
|
s_update_channel (channel_t *ch)
|
|
|
|
{
|
|
|
|
if (!ch->sfx)
|
|
|
|
return 0;
|
|
|
|
ch->oldphase = ch->phase; // prepare to lerp from prev to next phase
|
|
|
|
s_spatialize (ch); // respatialize channel
|
|
|
|
if (!ch->leftvol && !ch->rightvol)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-04-10 09:40:09 +00:00
|
|
|
/*
|
2004-01-09 03:48:00 +00:00
|
|
|
s_update
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
Called once each time through the main loop
|
|
|
|
*/
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_update (const vec3_t origin, const vec3_t forward, const vec3_t right,
|
2002-01-03 05:29:38 +00:00
|
|
|
const vec3_t up)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2001-09-09 21:41:35 +00:00
|
|
|
int total, i, j;
|
|
|
|
channel_t *ch, *combine;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
if (!sound_started || (snd_blocked > 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
VectorCopy (origin, listener_origin);
|
|
|
|
VectorCopy (forward, listener_forward);
|
|
|
|
VectorCopy (right, listener_right);
|
|
|
|
VectorCopy (up, listener_up);
|
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// update general area ambient sound sources
|
2004-01-09 03:48:00 +00:00
|
|
|
s_updateAmbientSounds ();
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
combine = NULL;
|
|
|
|
|
2001-08-23 04:01:46 +00:00
|
|
|
// update spatialization for static and dynamic sounds
|
2004-01-21 02:52:12 +00:00
|
|
|
for (i = 0; i < MAX_DYNAMIC_CHANNELS; i++)
|
|
|
|
s_update_channel (dynamic_channels[i]);
|
|
|
|
|
|
|
|
for (i = 0; i < num_statics; i++) {
|
|
|
|
ch = static_channels[i];
|
|
|
|
if (!s_update_channel (ch))
|
2001-04-10 09:40:09 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// try to combine static sounds with a previous channel of the same
|
|
|
|
// sound effect so we don't mix five torches every frame
|
2004-01-21 02:52:12 +00:00
|
|
|
// see if it can just use the last one
|
|
|
|
if (combine && combine->sfx == ch->sfx) {
|
|
|
|
combine->leftvol += ch->leftvol;
|
|
|
|
combine->rightvol += ch->rightvol;
|
|
|
|
ch->leftvol = ch->rightvol = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// search for one
|
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
combine = static_channels[j];
|
|
|
|
if (combine->sfx == ch->sfx)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == i) {
|
|
|
|
combine = NULL;
|
|
|
|
} else {
|
|
|
|
if (combine != ch) {
|
2001-04-10 09:40:09 +00:00
|
|
|
combine->leftvol += ch->leftvol;
|
|
|
|
combine->rightvol += ch->rightvol;
|
|
|
|
ch->leftvol = ch->rightvol = 0;
|
|
|
|
}
|
2004-01-21 02:52:12 +00:00
|
|
|
continue;
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-22 12:31:43 +00:00
|
|
|
// debugging output
|
2001-04-10 09:40:09 +00:00
|
|
|
if (snd_show->int_val) {
|
|
|
|
total = 0;
|
|
|
|
ch = channels;
|
|
|
|
for (i = 0; i < total_channels; i++, ch++)
|
|
|
|
if (ch->sfx && (ch->leftvol || ch->rightvol)) {
|
2001-09-21 04:22:46 +00:00
|
|
|
// Sys_Printf ("%3i %3i %s\n", ch->leftvol, ch->rightvol,
|
2001-04-10 09:40:09 +00:00
|
|
|
// ch->sfx->name);
|
|
|
|
total++;
|
|
|
|
}
|
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("----(%i)----\n", total);
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
2001-05-22 12:31:43 +00:00
|
|
|
|
|
|
|
// mix some sound
|
2004-01-09 03:48:00 +00:00
|
|
|
s_update_ ();
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_extra_update (void)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2001-08-30 22:11:45 +00:00
|
|
|
if (!sound_started || snd_noextraupdate->int_val)
|
2001-04-10 09:40:09 +00:00
|
|
|
return; // don't pollute timings
|
2004-01-09 03:48:00 +00:00
|
|
|
s_update_ ();
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
2001-08-27 01:00:03 +00:00
|
|
|
/* console functions */
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_play (void)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2003-05-08 23:24:02 +00:00
|
|
|
dstring_t *name = dstring_new ();
|
2001-09-09 21:41:35 +00:00
|
|
|
int i;
|
|
|
|
static int hash = 345;
|
2001-08-23 04:01:46 +00:00
|
|
|
sfx_t *sfx;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
i = 1;
|
|
|
|
while (i < Cmd_Argc ()) {
|
|
|
|
if (!strrchr (Cmd_Argv (i), '.')) {
|
2003-05-08 23:24:02 +00:00
|
|
|
dsprintf (name, "%s.wav", Cmd_Argv (i));
|
2001-10-26 00:20:00 +00:00
|
|
|
} else {
|
2003-05-08 23:24:02 +00:00
|
|
|
dsprintf (name, "%s", Cmd_Argv (i));
|
2001-10-26 00:20:00 +00:00
|
|
|
}
|
2004-01-09 03:48:00 +00:00
|
|
|
sfx = s_precache_sound (name->str);
|
|
|
|
s_start_sound (hash++, 0, sfx, listener_origin, 1.0, 1.0);
|
2001-04-10 09:40:09 +00:00
|
|
|
i++;
|
|
|
|
}
|
2003-05-08 23:24:02 +00:00
|
|
|
dstring_delete (name);
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
2003-05-15 22:39:34 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_playcenter_f (void)
|
2003-05-15 22:39:34 +00:00
|
|
|
{
|
|
|
|
dstring_t *name = dstring_new ();
|
|
|
|
int i;
|
|
|
|
sfx_t *sfx;
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
while (i < Cmd_Argc ()) {
|
|
|
|
if (!strrchr (Cmd_Argv (i), '.')) {
|
|
|
|
dsprintf (name, "%s.wav", Cmd_Argv (i));
|
|
|
|
} else {
|
|
|
|
dsprintf (name, "%s", Cmd_Argv (i));
|
|
|
|
}
|
2004-01-09 03:48:00 +00:00
|
|
|
sfx = s_precache_sound (name->str);
|
|
|
|
s_start_sound (*render_data.viewentity, 0, sfx, listener_origin, 1.0, 1.0);
|
2003-05-15 22:39:34 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
dstring_delete (name);
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_playvol_f (void)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2003-05-08 23:24:02 +00:00
|
|
|
dstring_t *name = dstring_new ();
|
2001-09-09 21:41:35 +00:00
|
|
|
float vol;
|
|
|
|
int i;
|
|
|
|
static int hash = 543;
|
2001-08-23 04:01:46 +00:00
|
|
|
sfx_t *sfx;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
i = 1;
|
|
|
|
while (i < Cmd_Argc ()) {
|
|
|
|
if (!strrchr (Cmd_Argv (i), '.')) {
|
2003-05-08 23:24:02 +00:00
|
|
|
dsprintf (name, "%s.wav", Cmd_Argv (i));
|
2001-10-26 00:20:00 +00:00
|
|
|
} else {
|
2003-05-08 23:24:02 +00:00
|
|
|
dsprintf (name, "%s", Cmd_Argv (i));
|
2001-10-26 00:20:00 +00:00
|
|
|
}
|
2004-01-09 03:48:00 +00:00
|
|
|
sfx = s_precache_sound (name->str);
|
2001-04-10 09:40:09 +00:00
|
|
|
vol = atof (Cmd_Argv (i + 1));
|
2004-01-09 03:48:00 +00:00
|
|
|
s_start_sound (hash++, 0, sfx, listener_origin, vol, 1.0);
|
2001-04-10 09:40:09 +00:00
|
|
|
i += 2;
|
|
|
|
}
|
2003-05-08 23:24:02 +00:00
|
|
|
dstring_delete (name);
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_soundlist_f (void)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2003-04-11 01:17:48 +00:00
|
|
|
int load, total, i;
|
2001-08-23 04:01:46 +00:00
|
|
|
sfx_t *sfx;
|
2001-08-30 11:37:50 +00:00
|
|
|
|
2001-08-31 03:48:26 +00:00
|
|
|
if (Cmd_Argc() >= 2 && Cmd_Argv (1)[0])
|
2001-08-30 11:37:50 +00:00
|
|
|
load = 1;
|
|
|
|
else
|
|
|
|
load = 0;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
total = 0;
|
|
|
|
for (sfx = known_sfx, i = 0; i < num_sfx; i++, sfx++) {
|
2003-04-11 01:17:48 +00:00
|
|
|
if (load) {
|
|
|
|
if (!sfx->retain (sfx))
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
if (!sfx->touch (sfx))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
total += sfx->length;
|
2003-04-12 00:03:56 +00:00
|
|
|
Sys_Printf ("%6d %6d %s\n", sfx->loopstart, sfx->length, sfx->name);
|
2001-08-30 11:37:50 +00:00
|
|
|
|
|
|
|
if (load)
|
2003-04-11 01:17:48 +00:00
|
|
|
sfx->release (sfx);
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Total resident: %i\n", total);
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_local_sound (const char *sound)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
2001-08-23 04:01:46 +00:00
|
|
|
sfx_t *sfx;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
|
|
|
if (!sound_started)
|
|
|
|
return;
|
2001-08-30 22:11:45 +00:00
|
|
|
if (nosound->int_val)
|
|
|
|
return;
|
2001-04-10 09:40:09 +00:00
|
|
|
|
2004-01-09 03:48:00 +00:00
|
|
|
sfx = s_precache_sound (sound);
|
2001-04-10 09:40:09 +00:00
|
|
|
if (!sfx) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("S_LocalSound: can't cache %s\n", sound);
|
2001-04-10 09:40:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-01-09 03:48:00 +00:00
|
|
|
s_start_sound (*render_data.viewentity, -1, sfx, vec3_origin, 1, 1);
|
2001-04-10 09:40:09 +00:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_clear_precache (void)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_begin_precaching (void)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_end_precaching (void)
|
2001-04-10 09:40:09 +00:00
|
|
|
{
|
|
|
|
}
|
2001-07-05 20:18:23 +00:00
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_block_sound (void)
|
2001-07-05 20:18:23 +00:00
|
|
|
{
|
2003-01-31 19:55:21 +00:00
|
|
|
if (++snd_blocked == 1) {
|
2003-01-31 20:19:42 +00:00
|
|
|
snd_output_funcs->pS_O_BlockSound ();
|
2004-01-09 03:48:00 +00:00
|
|
|
s_clear_buffer ();
|
2003-01-31 19:55:21 +00:00
|
|
|
}
|
2001-07-05 20:18:23 +00:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_unblock_sound (void)
|
2001-07-05 20:18:23 +00:00
|
|
|
{
|
|
|
|
if (!snd_blocked)
|
|
|
|
return;
|
2004-03-01 11:51:01 +00:00
|
|
|
|
2003-01-31 19:55:21 +00:00
|
|
|
if (!--snd_blocked) {
|
2004-01-09 03:48:00 +00:00
|
|
|
s_clear_buffer ();
|
2003-01-31 20:19:42 +00:00
|
|
|
snd_output_funcs->pS_O_UnblockSound ();
|
2003-01-31 19:55:21 +00:00
|
|
|
}
|
2001-08-23 04:01:46 +00:00
|
|
|
}
|
|
|
|
|
2004-02-03 03:01:06 +00:00
|
|
|
static void
|
|
|
|
s_gamedir (void)
|
|
|
|
{
|
|
|
|
num_sfx = 0;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_init (void)
|
2002-11-05 19:12:51 +00:00
|
|
|
{
|
2004-01-21 02:52:12 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_AMBIENTS; i++)
|
|
|
|
ambient_channels[i] = s_alloc_channel ();
|
|
|
|
for (i = 0; i < MAX_DYNAMIC_CHANNELS; i++)
|
|
|
|
dynamic_channels[i] = s_alloc_channel ();
|
|
|
|
|
2004-01-09 03:48:00 +00:00
|
|
|
snd_output_funcs = render_data.output->functions->snd_output;
|
|
|
|
Sys_Printf ("\nSound Initialization\n");
|
|
|
|
|
|
|
|
Cmd_AddCommand ("play", s_play,
|
|
|
|
"Play selected sound effect (play pathto/sound.wav)");
|
|
|
|
Cmd_AddCommand ("playcenter", s_playcenter_f,
|
|
|
|
"Play selected sound effect without 3D spatialization.");
|
|
|
|
Cmd_AddCommand ("playvol", s_playvol_f, "Play selected sound effect at "
|
|
|
|
"selected volume (playvol pathto/sound.wav num");
|
|
|
|
Cmd_AddCommand ("stopsound", s_stop_all_sounds_f,
|
|
|
|
"Stops all sounds currently being played");
|
|
|
|
Cmd_AddCommand ("soundlist", s_soundlist_f,
|
|
|
|
"Reports a list of sounds in the cache");
|
|
|
|
Cmd_AddCommand ("soundinfo", s_soundinfo_f,
|
|
|
|
"Report information on the sound system");
|
|
|
|
|
2004-01-08 00:25:52 +00:00
|
|
|
snd_interp = Cvar_Get ("snd_interp", "1", CVAR_ARCHIVE, NULL,
|
|
|
|
"control sample interpolation");
|
2002-11-05 19:12:51 +00:00
|
|
|
ambient_fade = Cvar_Get ("ambient_fade", "100", CVAR_NONE, NULL,
|
|
|
|
"How quickly ambient sounds fade in or out");
|
|
|
|
ambient_level = Cvar_Get ("ambient_level", "0.3", CVAR_NONE, NULL,
|
|
|
|
"Ambient sounds' volume");
|
|
|
|
nosound = Cvar_Get ("nosound", "0", CVAR_NONE, NULL,
|
|
|
|
"Set to turn sound off");
|
|
|
|
precache = Cvar_Get ("precache", "1", CVAR_NONE, NULL,
|
|
|
|
"Toggle the use of a precache");
|
|
|
|
volume = Cvar_Get ("volume", "0.7", CVAR_ARCHIVE, NULL,
|
|
|
|
"Set the volume for sound playback");
|
|
|
|
snd_interp = Cvar_Get ("snd_interp", "1", CVAR_ARCHIVE, NULL,
|
|
|
|
"control sample interpolation");
|
|
|
|
snd_loadas8bit = Cvar_Get ("snd_loadas8bit", "0", CVAR_NONE, NULL,
|
|
|
|
"Toggles loading sounds as 8-bit samples");
|
|
|
|
snd_mixahead = Cvar_Get ("snd_mixahead", "0.1", CVAR_ARCHIVE, NULL,
|
|
|
|
"Delay time for sounds");
|
|
|
|
snd_noextraupdate = Cvar_Get ("snd_noextraupdate", "0", CVAR_NONE, NULL,
|
|
|
|
"Toggles the correct value display in "
|
|
|
|
"host_speeds. Usually messes up sound "
|
|
|
|
"playback when in effect");
|
|
|
|
snd_phasesep = Cvar_Get ("snd_phasesep", "0.0", CVAR_ARCHIVE, NULL,
|
|
|
|
"max stereo phase separation in ms. 0.6 is for "
|
|
|
|
"20cm head");
|
|
|
|
snd_show = Cvar_Get ("snd_show", "0", CVAR_NONE, NULL,
|
|
|
|
"Toggles display of sounds currently being played");
|
|
|
|
snd_volumesep = Cvar_Get ("snd_volumesep", "1.0", CVAR_ARCHIVE, NULL,
|
|
|
|
"max stereo volume separation. 1.0 is max");
|
|
|
|
|
|
|
|
if (COM_CheckParm ("-nosound"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (COM_CheckParm ("-simsound"))
|
|
|
|
fakedma = true;
|
|
|
|
|
|
|
|
// FIXME
|
|
|
|
// if (host_parms.memsize < 0x800000) {
|
|
|
|
// Cvar_Set (snd_loadas8bit, "1");
|
|
|
|
// Sys_Printf ("loading all sounds as 8bit\n");
|
|
|
|
// }
|
|
|
|
|
|
|
|
snd_initialized = true;
|
|
|
|
|
2004-01-09 03:48:00 +00:00
|
|
|
s_startup ();
|
2002-11-05 19:12:51 +00:00
|
|
|
|
|
|
|
if (sound_started == 0) // sound startup failed? Bail out.
|
|
|
|
return;
|
|
|
|
|
|
|
|
SND_InitScaletable ();
|
|
|
|
|
|
|
|
known_sfx = Hunk_AllocName (MAX_SFX * sizeof (sfx_t), "sfx_t");
|
|
|
|
|
|
|
|
num_sfx = 0;
|
|
|
|
|
|
|
|
// create a piece of DMA memory
|
|
|
|
if (fakedma) {
|
|
|
|
shm = (void *) Hunk_AllocName (sizeof (*shm), "shm");
|
|
|
|
shm->splitbuffer = 0;
|
|
|
|
shm->samplebits = 16;
|
|
|
|
shm->speed = 22050;
|
|
|
|
shm->channels = 2;
|
|
|
|
shm->samples = 32768;
|
|
|
|
shm->samplepos = 0;
|
|
|
|
shm->soundalive = true;
|
|
|
|
shm->gamealive = true;
|
|
|
|
shm->submission_chunk = 1;
|
|
|
|
shm->buffer = Hunk_AllocName (1 << 16, "shmbuf");
|
|
|
|
}
|
|
|
|
// Sys_Printf ("Sound sampling rate: %i\n", shm->speed);
|
|
|
|
|
|
|
|
// provides a tick sound until washed clean
|
|
|
|
|
|
|
|
// if (shm->buffer)
|
|
|
|
// shm->buffer[4] = shm->buffer[5] = 0x7f; // force a pop for debugging
|
|
|
|
|
2004-01-09 03:48:00 +00:00
|
|
|
ambient_sfx[AMBIENT_WATER] = s_precache_sound ("ambience/water1.wav");
|
|
|
|
ambient_sfx[AMBIENT_SKY] = s_precache_sound ("ambience/wind2.wav");
|
2002-11-05 19:12:51 +00:00
|
|
|
|
2004-01-09 03:48:00 +00:00
|
|
|
s_stop_all_sounds (true);
|
2004-02-03 03:01:06 +00:00
|
|
|
|
|
|
|
QFS_GamedirCallback (s_gamedir);
|
2002-11-05 19:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Shutdown sound engine ======================================================
|
2004-01-08 01:48:02 +00:00
|
|
|
static void
|
2004-01-09 03:48:00 +00:00
|
|
|
s_shutdown (void)
|
2002-11-05 19:12:51 +00:00
|
|
|
{
|
|
|
|
if (!sound_started)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (shm)
|
|
|
|
shm->gamealive = 0;
|
|
|
|
|
|
|
|
sound_started = 0;
|
|
|
|
|
|
|
|
if (!fakedma) {
|
2003-01-31 20:19:42 +00:00
|
|
|
snd_output_funcs->pS_O_Shutdown ();
|
2002-11-05 19:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
shm = 0;
|
|
|
|
}
|
|
|
|
|
2003-04-20 02:05:28 +00:00
|
|
|
static general_funcs_t plugin_info_general_funcs = {
|
2004-01-09 03:48:00 +00:00
|
|
|
s_init,
|
|
|
|
s_shutdown,
|
2003-04-20 02:05:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static snd_render_funcs_t plugin_info_render_funcs = {
|
2004-01-09 03:48:00 +00:00
|
|
|
s_ambient_off,
|
|
|
|
s_ambient_on,
|
|
|
|
s_touch_sound,
|
|
|
|
s_static_sound,
|
|
|
|
s_start_sound,
|
|
|
|
s_stop_sound,
|
|
|
|
s_precache_sound,
|
|
|
|
s_clear_precache,
|
|
|
|
s_update,
|
|
|
|
s_stop_all_sounds,
|
|
|
|
s_begin_precaching,
|
|
|
|
s_end_precaching,
|
|
|
|
s_extra_update,
|
|
|
|
s_local_sound,
|
|
|
|
s_block_sound,
|
|
|
|
s_unblock_sound,
|
2004-01-21 02:52:12 +00:00
|
|
|
s_load_sound,
|
|
|
|
s_alloc_channel,
|
2003-04-20 02:05:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_funcs_t plugin_info_funcs = {
|
|
|
|
&plugin_info_general_funcs,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&plugin_info_render_funcs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_data_t plugin_info_data = {
|
|
|
|
&plugin_info_general_data,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&render_data,
|
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_t plugin_info = {
|
|
|
|
qfp_snd_render,
|
|
|
|
0,
|
|
|
|
QFPLUGIN_VERSION,
|
|
|
|
"0.1",
|
|
|
|
"Sound Renderer",
|
|
|
|
"Copyright (C) 1996-1997 id Software, Inc.\n"
|
|
|
|
"Copyright (C) 1999,2000,2001 contributors of the QuakeForge "
|
|
|
|
"project\n"
|
|
|
|
"Please see the file \"AUTHORS\" for a list of contributors",
|
|
|
|
&plugin_info_funcs,
|
|
|
|
&plugin_info_data,
|
|
|
|
};
|
|
|
|
|
2003-08-01 19:53:46 +00:00
|
|
|
PLUGIN_INFO(snd_render, default)
|
2001-09-09 21:41:35 +00:00
|
|
|
{
|
2001-08-23 04:01:46 +00:00
|
|
|
return &plugin_info;
|
2001-07-05 20:18:23 +00:00
|
|
|
}
|