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: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@181 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Ozkan Sezer 2010-06-03 17:25:24 +00:00
parent 80a3a0df30
commit 5658a9e28d
3 changed files with 101 additions and 101 deletions

View file

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

View file

@ -148,7 +148,7 @@ void SNDDMA_UnblockSound(void);
#define MAX_DYNAMIC_CHANNELS 128 //johnfitz -- was 8 #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 // 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds
// MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc // MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc
// MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds // 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 vec3_t listener_up;
extern volatile dma_t *shm; extern volatile dma_t *shm;
extern volatile dma_t sn; extern volatile dma_t sn;
extern vec_t sound_nominal_clip_dist;
extern cvar_t loadas8bit; extern cvar_t loadas8bit;
extern cvar_t bgmvolume; extern cvar_t bgmvolume;