renamed the global channels to snd_channels. removed the global variable

sound_nominal_clip_dist and made it into a macro in snd_dma.c.
snd_dma.c: general whitespace and formatting cleanup.
(S_StaticSound): Explicitly cast vol to int when assigning it to ss->master_vol.
(S_UpdateAmbientSounds): changed the type of vol from float to int. used int
casts in its calculations. added explicit int casts when assigning values to
chan->master_vol.
(S_Update_): added explicit unsigned int casts in endtime calculations.


git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@181 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2010-06-03 17:25:24 +00:00
parent 89b16b1ccd
commit 29b96547ed
3 changed files with 101 additions and 101 deletions

View file

@ -34,23 +34,24 @@ void S_StopAllSoundsC(void);
// Internal sound data & structures
// =======================================================================
channel_t channels[MAX_CHANNELS];
channel_t snd_channels[MAX_CHANNELS];
int total_channels;
int snd_blocked = 0;
qboolean snd_initialized = false;
volatile dma_t *shm = NULL;
volatile dma_t sn;
volatile dma_t *shm = NULL;
vec3_t listener_origin;
vec3_t listener_forward;
vec3_t listener_right;
vec3_t listener_up;
vec_t sound_nominal_clip_dist=1000.0;
#define sound_nominal_clip_dist 1000.0
int soundtime; // sample PAIRS
int paintedtime; // sample PAIRS
int paintedtime; // sample PAIRS
#define MAX_SFX 512
@ -99,7 +100,6 @@ void S_SoundInfo_f(void)
S_Startup
================
*/
void S_Startup (void)
{
if (!snd_initialized)
@ -158,10 +158,10 @@ void S_Init (void)
Cmd_AddCommand("soundlist", S_SoundList);
Cmd_AddCommand("soundinfo", S_SoundInfo_f);
if (COM_CheckParm("-sndspeed"))
{
sndspeed.value = Q_atoi(com_argv[COM_CheckParm("-sndspeed")+1]);
}
if (COM_CheckParm("-sndspeed"))
{
sndspeed.value = Q_atoi(com_argv[COM_CheckParm("-sndspeed")+1]);
}
if (host_parms.memsize < 0x800000)
{
@ -180,7 +180,7 @@ void S_Init (void)
if (sound_started == 0)
return;
// provides a tick sound until washed clean
// provides a tick sound until washed clean
// if (shm->buffer)
// shm->buffer[4] = shm->buffer[5] = 0x7f; // force a pop for debugging
@ -194,8 +194,7 @@ void S_Init (void)
// =======================================================================
// Shutdown sound engine
// =======================================================================
void S_Shutdown(void)
void S_Shutdown (void)
{
if (!sound_started)
return;
@ -232,7 +231,7 @@ sfx_t *S_FindName (char *name)
Sys_Error ("Sound name too long: %s", name);
// see if already loaded
for (i=0 ; i < num_sfx ; i++)
for (i = 0; i < num_sfx; i++)
{
if (!Q_strcmp(known_sfx[i].name, name))
{
@ -297,58 +296,62 @@ sfx_t *S_PrecacheSound (char *name)
/*
=================
SND_PickChannel
picks a channel based on priorities, empty slots, number of channels
=================
*/
channel_t *SND_PickChannel(int entnum, int entchannel)
channel_t *SND_PickChannel (int entnum, int entchannel)
{
int ch_idx;
int first_to_die;
int life_left;
int ch_idx;
int first_to_die;
int life_left;
// Check for replacement sound, or find the best one to replace
first_to_die = -1;
life_left = 0x7fffffff;
for (ch_idx=NUM_AMBIENTS ; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS ; ch_idx++)
{
first_to_die = -1;
life_left = 0x7fffffff;
for (ch_idx = NUM_AMBIENTS; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS; ch_idx++)
{
if (entchannel != 0 // channel 0 never overrides
&& channels[ch_idx].entnum == entnum
&& (channels[ch_idx].entchannel == entchannel || entchannel == -1) )
{ // allways override sound from same entity
&& snd_channels[ch_idx].entnum == entnum
&& (snd_channels[ch_idx].entchannel == entchannel || entchannel == -1) )
{ // always override sound from same entity
first_to_die = ch_idx;
break;
}
// don't let monster sounds override player sounds
if (channels[ch_idx].entnum == cl.viewentity && entnum != cl.viewentity && channels[ch_idx].sfx)
if (snd_channels[ch_idx].entnum == cl.viewentity && entnum != cl.viewentity && snd_channels[ch_idx].sfx)
continue;
if (channels[ch_idx].end - paintedtime < life_left)
if (snd_channels[ch_idx].end - paintedtime < life_left)
{
life_left = channels[ch_idx].end - paintedtime;
life_left = snd_channels[ch_idx].end - paintedtime;
first_to_die = ch_idx;
}
}
}
if (first_to_die == -1)
return NULL;
if (channels[first_to_die].sfx)
channels[first_to_die].sfx = NULL;
if (snd_channels[first_to_die].sfx)
snd_channels[first_to_die].sfx = NULL;
return &channels[first_to_die];
return &snd_channels[first_to_die];
}
/*
=================
SND_Spatialize
spatializes a channel
=================
*/
void SND_Spatialize(channel_t *ch)
void SND_Spatialize (channel_t *ch)
{
vec_t dot;
vec_t dist;
vec_t lscale, rscale, scale;
vec3_t source_vec;
vec_t dot;
vec_t dist;
vec_t lscale, rscale, scale;
vec3_t source_vec;
// anything coming from the view entity will always be full volume
if (ch->entnum == cl.viewentity)
@ -391,9 +394,9 @@ void SND_Spatialize(channel_t *ch)
// Start a sound effect
// =======================================================================
void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
void 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;
sfxcache_t *sc;
int ch_idx;
int skip;
@ -434,13 +437,13 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f
target_chan->sfx = sfx;
target_chan->pos = 0.0;
target_chan->end = paintedtime + sc->length;
target_chan->end = paintedtime + sc->length;
// 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
check = &channels[NUM_AMBIENTS];
for (ch_idx=NUM_AMBIENTS ; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS ; ch_idx++, check++)
{
check = &snd_channels[NUM_AMBIENTS];
for (ch_idx = NUM_AMBIENTS; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS; ch_idx++, check++)
{
if (check == target_chan)
continue;
if (check->sfx == sfx && !check->pos)
@ -455,23 +458,23 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f
}
}
void S_StopSound(int entnum, int entchannel)
void S_StopSound (int entnum, int entchannel)
{
int i;
int i;
for (i=0 ; i<MAX_DYNAMIC_CHANNELS ; i++)
for (i = 0; i < MAX_DYNAMIC_CHANNELS; i++)
{
if (channels[i].entnum == entnum
&& channels[i].entchannel == entchannel)
if (snd_channels[i].entnum == entnum
&& snd_channels[i].entchannel == entchannel)
{
channels[i].end = 0;
channels[i].sfx = NULL;
snd_channels[i].end = 0;
snd_channels[i].sfx = NULL;
return;
}
}
}
void S_StopAllSounds(qboolean clear)
void S_StopAllSounds (qboolean clear)
{
int i;
@ -480,13 +483,13 @@ void S_StopAllSounds(qboolean clear)
total_channels = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; // no statics
for (i=0 ; i<MAX_CHANNELS ; i++)
for (i = 0; i < MAX_CHANNELS; i++)
{
if (channels[i].sfx)
channels[i].sfx = NULL;
if (snd_channels[i].sfx)
snd_channels[i].sfx = NULL;
}
memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
memset(snd_channels, 0, MAX_CHANNELS * sizeof(channel_t));
if (clear)
S_ClearBuffer ();
@ -538,7 +541,7 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
return;
}
ss = &channels[total_channels];
ss = &snd_channels[total_channels];
total_channels++;
sc = S_LoadSound (sfx);
@ -553,9 +556,9 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
ss->sfx = sfx;
VectorCopy (origin, ss->origin);
ss->master_vol = vol;
ss->dist_mult = (attenuation/64) / sound_nominal_clip_dist;
ss->end = paintedtime + sc->length;
ss->master_vol = (int)vol;
ss->dist_mult = (attenuation / 64) / sound_nominal_clip_dist;
ss->end = paintedtime + sc->length;
SND_Spatialize (ss);
}
@ -571,8 +574,7 @@ S_UpdateAmbientSounds
void S_UpdateAmbientSounds (void)
{
mleaf_t *l;
float vol;
int ambient_channel;
int vol, ambient_channel;
channel_t *chan;
//johnfitz -- no ambients when disconnected
@ -587,30 +589,30 @@ void S_UpdateAmbientSounds (void)
l = Mod_PointInLeaf (listener_origin, cl.worldmodel);
if (!l || !ambient_level.value)
{
for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++)
channels[ambient_channel].sfx = NULL;
for (ambient_channel = 0; ambient_channel < NUM_AMBIENTS; ambient_channel++)
snd_channels[ambient_channel].sfx = NULL;
return;
}
for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++)
for (ambient_channel = 0; ambient_channel < NUM_AMBIENTS; ambient_channel++)
{
chan = &channels[ambient_channel];
chan = &snd_channels[ambient_channel];
chan->sfx = ambient_sfx[ambient_channel];
vol = ambient_level.value * l->ambient_sound_level[ambient_channel];
vol = (int) (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)
{
chan->master_vol += host_frametime * ambient_fade.value;
chan->master_vol += (int) (host_frametime * ambient_fade.value);
if (chan->master_vol > vol)
chan->master_vol = vol;
}
else if (chan->master_vol > vol)
{
chan->master_vol -= host_frametime * ambient_fade.value;
chan->master_vol -= (int) (host_frametime * ambient_fade.value);
if (chan->master_vol < vol)
chan->master_vol = vol;
}
@ -627,7 +629,7 @@ S_Update
Called once each time through the main loop
============
*/
void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
void S_Update (vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
{
int i, j;
int total;
@ -648,12 +650,12 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
combine = NULL;
// update spatialization for static and dynamic sounds
ch = channels+NUM_AMBIENTS;
for (i=NUM_AMBIENTS ; i<total_channels; i++, ch++)
ch = snd_channels + NUM_AMBIENTS;
for (i = NUM_AMBIENTS; i < total_channels; i++, ch++)
{
if (!ch->sfx)
continue;
SND_Spatialize(ch); // respatialize channel
SND_Spatialize(ch); // respatialize channel
if (!ch->leftvol && !ch->rightvol)
continue;
@ -671,8 +673,8 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
continue;
}
// search for one
combine = channels+MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS;
for (j=MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS ; j<i; j++, combine++)
combine = snd_channels + MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS;
for (j = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; j < i; j++, combine++)
{
if (combine->sfx == ch->sfx)
break;
@ -701,12 +703,12 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
if (snd_show.value)
{
total = 0;
ch = channels;
for (i=0 ; i<total_channels; i++, ch++)
ch = snd_channels;
for (i = 0; i < total_channels; i++, ch++)
{
if (ch->sfx && (ch->leftvol || ch->rightvol) )
{
//Con_Printf ("%3i %3i %s\n", ch->leftvol, ch->rightvol, ch->sfx->name);
// Con_Printf ("%3i %3i %s\n", ch->leftvol, ch->rightvol, ch->sfx->name);
total++;
}
}
@ -718,7 +720,7 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
S_Update_();
}
void GetSoundtime(void)
void GetSoundtime (void)
{
int samplepos;
static int buffers;
@ -737,7 +739,7 @@ void GetSoundtime(void)
if (samplepos < oldsamplepos)
{
buffers++; // buffer wrapped
buffers++; // buffer wrapped
if (paintedtime > 0x40000000)
{ // time to chop things off to avoid 32 bit limits
@ -779,15 +781,14 @@ void S_Update_(void)
// check to make sure that we haven't overshot
if (paintedtime < soundtime)
{
//Con_Printf ("S_Update_ : overflow\n");
// Con_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;
endtime = soundtime + (unsigned int)(_snd_mixahead.value * shm->speed);
samps = shm->samples >> (shm->channels - 1);
endtime = min(endtime, (unsigned int)(soundtime + samps));
S_PaintChannels (endtime);
@ -827,15 +828,15 @@ console functions
===============================================================================
*/
void S_Play(void)
void S_Play (void)
{
static int hash=345;
int i;
char name[256];
static int hash = 345;
int i;
char name[256];
sfx_t *sfx;
i = 1;
while (i<Cmd_Argc())
while (i < Cmd_Argc())
{
if (!Q_strrchr(Cmd_Argv(i), '.'))
{
@ -850,16 +851,16 @@ void S_Play(void)
}
}
void S_PlayVol(void)
void S_PlayVol (void)
{
static int hash=543;
int i;
float vol;
char name[256];
static int hash = 543;
int i;
float vol;
char name[256];
sfx_t *sfx;
i = 1;
while (i<Cmd_Argc())
while (i < Cmd_Argc())
{
if (!Q_strrchr(Cmd_Argv(i), '.'))
{
@ -869,13 +870,13 @@ void S_PlayVol(void)
else
Q_strcpy(name, Cmd_Argv(i));
sfx = S_PrecacheSound(name);
vol = Q_atof(Cmd_Argv(i+1));
vol = Q_atof(Cmd_Argv(i + 1));
S_StartSound(hash++, 0, sfx, listener_origin, vol, 1.0);
i+=2;
}
}
void S_SoundList(void)
void S_SoundList (void)
{
int i;
sfx_t *sfx;
@ -883,12 +884,12 @@ void S_SoundList(void)
int size, total;
total = 0;
for (sfx=known_sfx, i=0 ; i<num_sfx ; i++, sfx++)
for (sfx = known_sfx, i = 0; i < num_sfx; i++, sfx++)
{
sc = (sfxcache_t *) Cache_Check (&sfx->cache);
if (!sc)
continue;
size = sc->length*sc->width*(sc->stereo+1);
size = sc->length*sc->width*(sc->stereo + 1);
total += size;
if (sc->loopstart >= 0)
Con_SafePrintf ("L"); //johnfitz -- was Con_Printf

View file

@ -168,7 +168,7 @@ void S_PaintChannels (int endtime)
memset(paintbuffer, 0, (end - paintedtime) * sizeof(portable_samplepair_t));
// paint in the channels.
ch = channels;
ch = snd_channels;
for (i = 0; i < total_channels; i++, ch++)
{
if (!ch->sfx)

View file

@ -148,7 +148,7 @@ void SNDDMA_UnblockSound(void);
#define MAX_DYNAMIC_CHANNELS 128 //johnfitz -- was 8
extern channel_t channels[MAX_CHANNELS];
extern channel_t snd_channels[MAX_CHANNELS];
// 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds
// MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc
// MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds
@ -170,7 +170,6 @@ extern vec3_t listener_right;
extern vec3_t listener_up;
extern volatile dma_t *shm;
extern volatile dma_t sn;
extern vec_t sound_nominal_clip_dist;
extern cvar_t loadas8bit;
extern cvar_t bgmvolume;