unsigned int total_channels;
int snd_blocked = 0;
-cvar_t snd_initialized = { CVAR_READONLY, "snd_initialized", "0"};
-cvar_t snd_streaming = { CVAR_SAVE, "snd_streaming", "1"};
+cvar_t snd_initialized = { CVAR_READONLY, "snd_initialized", "0", "indicates the sound subsystem is active"};
+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)"};
volatile dma_t *shm = 0;
volatile dma_t sn;
// isolating performance in the renderer.
qboolean fakedma = false;
-cvar_t bgmvolume = {CVAR_SAVE, "bgmvolume", "1"};
-cvar_t volume = {CVAR_SAVE, "volume", "0.7"};
-cvar_t snd_staticvolume = {CVAR_SAVE, "snd_staticvolume", "1"};
+cvar_t bgmvolume = {CVAR_SAVE, "bgmvolume", "1", "volume of background music (such as CD music or replacement files such as sound/cdtracks/track002.ogg)"};
+cvar_t volume = {CVAR_SAVE, "volume", "0.7", "volume of sound effects"};
+cvar_t snd_staticvolume = {CVAR_SAVE, "snd_staticvolume", "1", "volume of ambient sound effects (such as swampy sounds at the start of e1m2)"};
-cvar_t nosound = {0, "nosound", "0"};
-cvar_t snd_precache = {0, "snd_precache", "1"};
-cvar_t bgmbuffer = {0, "bgmbuffer", "4096"};
-cvar_t ambient_level = {0, "ambient_level", "0.3"};
-cvar_t ambient_fade = {0, "ambient_fade", "100"};
-cvar_t snd_noextraupdate = {0, "snd_noextraupdate", "0"};
-cvar_t snd_show = {0, "snd_show", "0"};
-cvar_t _snd_mixahead = {CVAR_SAVE, "_snd_mixahead", "0.1"};
-cvar_t snd_swapstereo = {CVAR_SAVE, "snd_swapstereo", "0"};
+cvar_t nosound = {0, "nosound", "0", "disables sound"};
+cvar_t snd_precache = {0, "snd_precache", "1", "loads sounds before they are used"};
+//cvar_t bgmbuffer = {0, "bgmbuffer", "4096", "unused quake cvar"};
+cvar_t ambient_level = {0, "ambient_level", "0.3", "volume of environment noises (water and wind)"};
+cvar_t ambient_fade = {0, "ambient_fade", "100", "rate of volume fading when moving from one environment to another"};
+cvar_t snd_noextraupdate = {0, "snd_noextraupdate", "0", "disables extra sound mixer calls that are meant to reduce the chance of sound breakup at very low framerates"};
+cvar_t snd_show = {0, "snd_show", "0", "shows some statistics about sound mixing"};
+cvar_t _snd_mixahead = {CVAR_SAVE, "_snd_mixahead", "0.1", "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"};
// Ambient sounds
sfx_t* ambient_sfxs [2] = { NULL, NULL };
if (COM_CheckParm("-simsound"))
fakedma = true;
- Cmd_AddCommand("play", S_Play);
- Cmd_AddCommand("play2", S_Play2);
- Cmd_AddCommand("playvol", S_PlayVol);
- Cmd_AddCommand("stopsound", S_StopAllSounds);
- Cmd_AddCommand("soundlist", S_SoundList);
- Cmd_AddCommand("soundinfo", S_SoundInfo_f);
- Cmd_AddCommand("snd_restart", S_Restart_f);
+ Cmd_AddCommand("play", S_Play, "play a sound at your current location (not heard by anyone else)");
+ Cmd_AddCommand("play2", S_Play2, "play a sound globally throughout the level (not heard by anyone else)");
+ Cmd_AddCommand("playvol", S_PlayVol, "play a sound at the specified volume level at your current location (not heard by anyone else)");
+ Cmd_AddCommand("stopsound", S_StopAllSounds, "silence");
+ Cmd_AddCommand("soundlist", S_SoundList, "list loaded sounds");
+ Cmd_AddCommand("soundinfo", S_SoundInfo_f, "print sound system information (such as channels and speed)");
+ Cmd_AddCommand("snd_restart", S_Restart_f, "restart sound system");
Cvar_RegisterVariable(&nosound);
Cvar_RegisterVariable(&snd_precache);
Cvar_RegisterVariable(&snd_initialized);
Cvar_RegisterVariable(&snd_streaming);
- Cvar_RegisterVariable(&bgmbuffer);
+ //Cvar_RegisterVariable(&bgmbuffer);
Cvar_RegisterVariable(&ambient_level);
Cvar_RegisterVariable(&ambient_fade);
Cvar_RegisterVariable(&snd_noextraupdate);
if (!snd_initialized.integer)
return NULL;
+ if (name == NULL || name[0] == 0)
+ return NULL;
+
sfx = S_FindName (name);
if (sfx == NULL)
return NULL;
return sfx;
}
+/*
+==================
+S_IsSoundPrecached
+==================
+*/
+qboolean S_IsSoundPrecached (const sfx_t *sfx)
+{
+ return (sfx != NULL && sfx->fetcher != NULL);
+}
+
/*
==================
S_LockSfx
vec3_t source_vec;
// update sound origin if we know about the entity
- if (ch->entnum > 0 && cls.state == ca_connected && cl_entities[ch->entnum].state_current.active)
+ if (ch->entnum > 0 && cls.state == ca_connected && cl.entities[ch->entnum].state_current.active)
{
- //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]);
- VectorCopy(cl_entities[ch->entnum].state_current.origin, ch->origin);
- 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)
- VectorMAMAM(1.0f, ch->origin, 0.5f, cl.model_precache[cl_entities[ch->entnum].state_current.modelindex]->normalmins, 0.5f, cl.model_precache[cl_entities[ch->entnum].state_current.modelindex]->normalmaxs, ch->origin);
+ //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]);
+ VectorCopy(cl.entities[ch->entnum].state_current.origin, ch->origin);
+ 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)
+ VectorMAMAM(1.0f, ch->origin, 0.5f, cl.model_precache[cl.entities[ch->entnum].state_current.modelindex]->normalmins, 0.5f, cl.model_precache[cl.entities[ch->entnum].state_current.modelindex]->normalmaxs, ch->origin);
}
mastervol = ch->master_vol;
for (i = 0;i < SND_LISTENERS;i++)
{
vol = mastervol * snd_speakerlayout.listeners[i].ambientvolume;
- ch->listener_volume[i] = bound(0, vol, 255);
+ ch->listener_volume[i] = (int)bound(0, vol, 255);
}
}
else
Matrix4x4_Transform(&listener_matrix[i], ch->origin, source_vec);
VectorNormalize(source_vec);
vol = intensity * max(0, source_vec[0] * snd_speakerlayout.listeners[i].dotscale + snd_speakerlayout.listeners[i].dotbias);
- ch->listener_volume[i] = bound(0, vol, 255);
+ ch->listener_volume[i] = (int)bound(0, vol, 255);
}
}
else
// Initialize the channel
memset (target_chan, 0, sizeof (*target_chan));
VectorCopy (origin, target_chan->origin);
- target_chan->master_vol = fvol * 255;
+ target_chan->master_vol = (int)(fvol * 255);
target_chan->sfx = sfx;
target_chan->end = paintedtime + sfx->total_length;
target_chan->lastptime = paintedtime;
return -1;
}
- if (entnum && entnum >= cl_max_entities)
+ if (entnum && entnum >= cl.max_entities)
CL_ExpandEntities(entnum);
// Pick a channel to play on
continue;
if (check->sfx == sfx && !check->pos)
{
- skip = 0.1 * sfx->format.speed;
+ skip = (int)(0.1 * sfx->format.speed);
if (skip > (int)sfx->total_length)
skip = (int)sfx->total_length;
if (skip > 0)
void S_SetChannelVolume (unsigned int ch_ind, float fvol)
{
- channels[ch_ind].master_vol = fvol * 255;
+ channels[ch_ind].master_vol = (int)(fvol * 255);
}
void S_UpdateAmbientSounds (void)
{
int i;
- float vol;
+ int vol;
int ambient_channel;
channel_t *chan;
unsigned char ambientlevels[NUM_AMBIENTS];
if (chan->sfx == NULL || chan->sfx->fetcher == NULL)
continue;
- vol = ambientlevels[ambient_channel];
+ vol = (int)ambientlevels[ambient_channel];
if (vol < 8)
vol = 0;
// Don't adjust volume too fast
+ // FIXME: this rounds off to an int each frame, meaning there is little to no fade at extremely high framerates!
if (chan->master_vol < vol)
{
- chan->master_vol += host_realframetime * ambient_fade.value;
+ chan->master_vol += (int)(cl.realframetime * ambient_fade.value);
if (chan->master_vol > vol)
chan->master_vol = vol;
}
else if (chan->master_vol > vol)
{
- chan->master_vol -= host_realframetime * ambient_fade.value;
+ chan->master_vol -= (int)(cl.realframetime * ambient_fade.value);
if (chan->master_vol < vol)
chan->master_vol = vol;
}
paintedtime = soundtime;
// mix ahead of current position
- endtime = soundtime + _snd_mixahead.value * shm->format.speed;
+ endtime = soundtime + (unsigned int)(_snd_mixahead.value * shm->format.speed);
endtime = min(endtime, (unsigned int)(soundtime + shm->sampleframes));
S_PaintChannels (endtime);