#include "snd_ogg.h"
#include "snd_modplug.h"
#include "csprogs.h"
+#include "cl_collision.h"
#define SND_MIN_SPEED 8000
static int current_channellayout = SND_CHANNELLAYOUT_AUTO;
static int current_channellayout_used = SND_CHANNELLAYOUT_AUTO;
-static double spatialpower, spatialmin, spatialdiff, spatialoffset, spatialfactor;
+static float spatialpower, spatialmin, spatialdiff, spatialoffset, spatialfactor;
typedef enum { SPATIAL_NONE, SPATIAL_LOG, SPATIAL_POW, SPATIAL_THRESH } spatialmethod_t;
spatialmethod_t spatialmethod;
cvar_t snd_spatialization_max = {CVAR_SAVE, "snd_spatialization_max", "0.95", "maximum spatialization of sounds"};
cvar_t snd_spatialization_power = {CVAR_SAVE, "snd_spatialization_power", "0", "exponent of the spatialization falloff curve (0: logarithmic)"};
cvar_t snd_spatialization_control = {CVAR_SAVE, "snd_spatialization_control", "0", "enable spatialization control (headphone friendly mode)"};
+cvar_t snd_spatialization_occlusion = {CVAR_SAVE, "snd_spatialization_occlusion", "1", "enable occlusion testing on spatialized sounds, which simply quiets sounds that are blocked by the world"};
// Cvars declared in snd_main.h (shared with other snd_*.c files)
-cvar_t _snd_mixahead = {CVAR_SAVE, "_snd_mixahead", "0.11", "how much sound to mix ahead of time"};
-cvar_t snd_streaming = { CVAR_SAVE, "snd_streaming", "1", "enables keeping compressed ogg sound files compressed, decompressing them only as needed, otherwise they will be decompressed completely at load (may use a lot of memory)"};
+cvar_t _snd_mixahead = {CVAR_SAVE, "_snd_mixahead", "0.15", "how much sound to mix ahead of time"};
cvar_t snd_swapstereo = {CVAR_SAVE, "snd_swapstereo", "0", "swaps left/right speakers for old ISA soundblaster cards"};
extern cvar_t v_flipped;
cvar_t snd_channellayout = {0, "snd_channellayout", "0", "channel layout. Can be 0 (auto - snd_restart needed), 1 (standard layout), or 2 (ALSA layout)"};
Cvar_RegisterVariable(&snd_spatialization_max);
Cvar_RegisterVariable(&snd_spatialization_power);
Cvar_RegisterVariable(&snd_spatialization_control);
+ Cvar_RegisterVariable(&snd_spatialization_occlusion);
Cvar_RegisterVariable(&snd_speed);
Cvar_RegisterVariable(&snd_width);
Cvar_RegisterVariable(&nosound);
Cvar_RegisterVariable(&snd_precache);
Cvar_RegisterVariable(&snd_initialized);
- Cvar_RegisterVariable(&snd_streaming);
Cvar_RegisterVariable(&ambient_level);
Cvar_RegisterVariable(&ambient_fade);
Cvar_RegisterVariable(&snd_noextraupdate);
S_FindName
==================
*/
+sfx_t changevolume_sfx = {""};
sfx_t *S_FindName (const char *name)
{
sfx_t *sfx;
if (!snd_initialized.integer)
return NULL;
+ if(!strcmp(name, changevolume_sfx.name))
+ return &changevolume_sfx;
+
if (strlen (name) >= sizeof (sfx->name))
{
Con_Printf ("S_FindName: sound name too long (%s)\n", name);
*/
qboolean S_IsSoundPrecached (const sfx_t *sfx)
{
- return (sfx != NULL && sfx->fetcher != NULL);
+ return (sfx != NULL && sfx->fetcher != NULL) || (sfx == &changevolume_sfx);
}
/*
// update sound origin if we know about the entity
if (ch->entnum > 0 && cls.state == ca_connected && cl_gameplayfix_soundsmovewithentities.integer)
{
- if (ch->entnum >= 32768)
+ if (ch->entnum >= MAX_EDICTS)
{
//Con_Printf("-- entnum %i origin %f %f %f neworigin %f %f %f\n", ch->entnum, ch->origin[0], ch->origin[1], ch->origin[2], cl.entities[ch->entnum].state_current.origin[0], cl.entities[ch->entnum].state_current.origin[1], cl.entities[ch->entnum].state_current.origin[2]);
- if (ch->entnum > 32768)
+ if (ch->entnum > MAX_EDICTS)
if (!CL_VM_GetEntitySoundOrigin(ch->entnum, ch->origin))
- ch->entnum = 32768; // entity was removed, disown sound
+ ch->entnum = MAX_EDICTS; // entity was removed, disown sound
}
else if (cl.entities[ch->entnum].state_current.active)
{
+ dp_model_t *model;
//Con_Printf("-- entnum %i origin %f %f %f neworigin %f %f %f\n", ch->entnum, ch->origin[0], ch->origin[1], ch->origin[2], cl.entities[ch->entnum].state_current.origin[0], cl.entities[ch->entnum].state_current.origin[1], cl.entities[ch->entnum].state_current.origin[2]);
- if (cl.entities[ch->entnum].state_current.modelindex && cl.model_precache[cl.entities[ch->entnum].state_current.modelindex] && cl.model_precache[cl.entities[ch->entnum].state_current.modelindex]->soundfromcenter)
+ model = CL_GetModelByIndex(cl.entities[ch->entnum].state_current.modelindex);
+ if (model && model->soundfromcenter)
VectorMAM(0.5f, cl.entities[ch->entnum].render.mins, 0.5f, cl.entities[ch->entnum].render.maxs, ch->origin);
else
Matrix4x4_OriginFromMatrix(&cl.entities[ch->entnum].render.matrix, ch->origin);
mastervol *= snd_staticvolume.value;
else if(!(ch->flags & CHANNELFLAG_FULLVOLUME)) // same as SND_PaintChannel uses
{
- if(ch->entnum >= 32768)
+ if(ch->entnum >= MAX_EDICTS)
{
switch(ch->entchannel)
{
VectorScale(source_vec, f, source_vec);
break;
case SPATIAL_POW:
- f = spatialmin + spatialdiff * bound(0, (pow(dist, spatialpower) - spatialoffset) * spatialfactor, 1);
+ f = (pow(dist, spatialpower) - spatialoffset) * spatialfactor;
+ f = spatialmin + spatialdiff * bound(0, f, 1);
VectorScale(source_vec, f, source_vec);
break;
case SPATIAL_THRESH:
}
vol = intensity * max(0, source_vec[0] * snd_speakerlayout.listeners[i].dotscale + snd_speakerlayout.listeners[i].dotbias);
+
+ if (snd_spatialization_occlusion.integer)
+ {
+ if (cl.worldmodel
+ && cl.worldmodel->brush.TraceLineOfSight
+ && !cl.worldmodel->brush.TraceLineOfSight(cl.worldmodel, listener_origin, ch->origin))
+ {
+ vol *= 0.5f;
+ }
+ }
+
ch->listener_volume[i] = (int)bound(0, vol, 255);
}
}
int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
{
- channel_t *target_chan, *check;
+ channel_t *target_chan, *check, *ch;
int ch_idx;
if (snd_renderbuffer == NULL || sfx == NULL || nosound.integer)
return -1;
+ if(sfx == &changevolume_sfx)
+ {
+ if(entchannel == 0)
+ return -1;
+ for (ch_idx=NUM_AMBIENTS ; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS ; ch_idx++)
+ {
+ ch = &channels[ch_idx];
+ if (ch->entnum == entnum && (ch->entchannel == entchannel || entchannel == -1) )
+ {
+ S_SetChannelVolume(ch_idx, fvol);
+ ch->dist_mult = attenuation / snd_soundradius.value;
+ SND_Spatialize(ch, false);
+ return ch_idx;
+ }
+ }
+ return -1;
+ }
+
if (sfx->fetcher == NULL)
return -1;
// thread is currently mixing this channel
// the SndSys_LockRenderBuffer function uses such a mutex in
// threaded sound backends
- if (lockmutex)
+ if (lockmutex && !simsound)
SndSys_LockRenderBuffer();
ch = &channels[channel_ind];
ch->fetcher_data = NULL;
ch->sfx = NULL;
}
- if (lockmutex)
+ if (lockmutex && !simsound)
SndSys_UnlockRenderBuffer();
}
// stop CD audio because it may be using a faketrack
CDAudio_Stop();
- for (i = 0; i < total_channels; i++)
- S_StopChannel (i, true);
-
- total_channels = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; // no statics
- memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
-
- // Mute the contents of the submittion buffer
if (simsound || SndSys_LockRenderBuffer ())
{
int clear;
size_t memsize;
+ for (i = 0; i < total_channels; i++)
+ S_StopChannel (i, false);
+
+ total_channels = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; // no statics
+ memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
+
+ // Mute the contents of the submittion buffer
clear = (snd_renderbuffer->format.width == 1) ? 0x80 : 0;
memsize = snd_renderbuffer->maxframes * snd_renderbuffer->format.width * snd_renderbuffer->format.channels;
memset(snd_renderbuffer->ring, clear, memsize);