summaryrefslogtreecommitdiff
path: root/src/snd_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/snd_main.c')
-rw-r--r--src/snd_main.c543
1 files changed, 282 insertions, 261 deletions
diff --git a/src/snd_main.c b/src/snd_main.c
index cc68b1d..61ce99b 100644
--- a/src/snd_main.c
+++ b/src/snd_main.c
@@ -8,7 +8,7 @@ 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.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -70,56 +70,58 @@ static cvar_t *s_auto_focus;
// Console functions
// =======================================================================
-static void S_SoundInfo_f( void ) {
- if( !s_started ) {
- Com_Printf( "Sound system not started.\n" );
+static void S_SoundInfo_f(void)
+{
+ if (!s_started) {
+ Com_Printf("Sound system not started.\n");
return;
}
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
AL_SoundInfo();
#endif
#if USE_SNDDMA
- if( s_started == SS_DMA )
+ if (s_started == SS_DMA)
DMA_SoundInfo();
#endif
}
-static void S_SoundList_f( void ) {
+static void S_SoundList_f(void)
+{
int i;
sfx_t *sfx;
sfxcache_t *sc;
int size, total;
total = 0;
- for( sfx=known_sfx, i=0 ; i<num_sfx ; i++, sfx++ ) {
- if( !sfx->name[0] )
+ for (sfx = known_sfx, i = 0; i < num_sfx; i++, sfx++) {
+ if (!sfx->name[0])
continue;
sc = sfx->cache;
- if( sc ) {
+ if (sc) {
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
size = sc->size;
else
#endif
size = sc->length * sc->width;
total += size;
- if( sc->loopstart >= 0 )
- Com_Printf( "L" );
+ if (sc->loopstart >= 0)
+ Com_Printf("L");
else
- Com_Printf( " " );
- Com_Printf( "(%2db) %6i : %s\n", sc->width * 8, size, sfx->name) ;
+ Com_Printf(" ");
+ Com_Printf("(%2db) %6i : %s\n", sc->width * 8, size, sfx->name) ;
} else {
- if( sfx->name[0] == '*' )
- Com_Printf( " placeholder : %s\n", sfx->name );
+ if (sfx->name[0] == '*')
+ Com_Printf(" placeholder : %s\n", sfx->name);
else
- Com_Printf( " not loaded : %s (%s)\n",
- sfx->name, Q_ErrorString( sfx->error ) );
+ Com_Printf(" not loaded : %s (%s)\n",
+ sfx->name, Q_ErrorString(sfx->error));
}
}
- Com_Printf( "Total resident: %i\n", total );
+ Com_Printf("Total resident: %i\n", total);
}
static const cmdreg_t c_sound[] = {
@@ -134,7 +136,8 @@ static const cmdreg_t c_sound[] = {
// Init sound engine
// =======================================================================
-static void s_auto_focus_changed( cvar_t *self ) {
+static void s_auto_focus_changed(cvar_t *self)
+{
S_Activate();
}
@@ -143,48 +146,49 @@ static void s_auto_focus_changed( cvar_t *self ) {
S_Init
================
*/
-void S_Init( void ) {
- s_enable = Cvar_Get( "s_enable", "1", CVAR_SOUND );
- if( s_enable->integer <= SS_NOT ) {
- Com_Printf( "Sound initialization disabled.\n" );
+void S_Init(void)
+{
+ s_enable = Cvar_Get("s_enable", "1", CVAR_SOUND);
+ if (s_enable->integer <= SS_NOT) {
+ Com_Printf("Sound initialization disabled.\n");
return;
}
- Com_Printf( "------- S_Init -------\n" );
+ Com_Printf("------- S_Init -------\n");
- s_volume = Cvar_Get( "s_volume", "0.7", CVAR_ARCHIVE );
- s_ambient = Cvar_Get( "s_ambient", "1", 0 );
+ s_volume = Cvar_Get("s_volume", "0.7", CVAR_ARCHIVE);
+ s_ambient = Cvar_Get("s_ambient", "1", 0);
#ifdef _DEBUG
- s_show = Cvar_Get( "s_show", "0", 0 );
+ s_show = Cvar_Get("s_show", "0", 0);
#endif
- s_auto_focus = Cvar_Get( "s_auto_focus", "0", 0 );
+ s_auto_focus = Cvar_Get("s_auto_focus", "0", 0);
// start one of available sound engines
s_started = SS_NOT;
#if USE_OPENAL
- if( s_started == SS_NOT && s_enable->integer >= SS_OAL && AL_Init() )
+ if (s_started == SS_NOT && s_enable->integer >= SS_OAL && AL_Init())
s_started = SS_OAL;
#endif
#if USE_SNDDMA
- if( s_started == SS_NOT && s_enable->integer >= SS_DMA && DMA_Init() )
+ if (s_started == SS_NOT && s_enable->integer >= SS_DMA && DMA_Init())
s_started = SS_DMA;
#endif
- if( s_started == SS_NOT ) {
- Com_EPrintf( "Sound failed to initialize.\n" );
+ if (s_started == SS_NOT) {
+ Com_EPrintf("Sound failed to initialize.\n");
goto fail;
}
- Cmd_Register( c_sound );
+ Cmd_Register(c_sound);
// init playsound list
// clear DMA buffer
S_StopAllSounds();
s_auto_focus->changed = s_auto_focus_changed;
- s_auto_focus_changed( s_auto_focus );
+ s_auto_focus_changed(s_auto_focus);
num_sfx = 0;
@@ -193,8 +197,8 @@ void S_Init( void ) {
s_registration_sequence = 1;
fail:
- Cvar_SetInteger( s_enable, s_started, FROM_CODE );
- Com_Printf( "----------------------\n" );
+ Cvar_SetInteger(s_enable, s_started, FROM_CODE);
+ Com_Printf("----------------------\n");
}
@@ -202,41 +206,44 @@ fail:
// Shutdown sound engine
// =======================================================================
-static void S_FreeSound( sfx_t *sfx ) {
+static void S_FreeSound(sfx_t *sfx)
+{
#if USE_OPENAL
- if( s_started == SS_OAL )
- AL_DeleteSfx( sfx );
+ if (s_started == SS_OAL)
+ AL_DeleteSfx(sfx);
#endif
- if( sfx->cache )
- Z_Free( sfx->cache );
- if( sfx->truename )
- Z_Free( sfx->truename );
- memset( sfx, 0, sizeof( *sfx ) );
+ if (sfx->cache)
+ Z_Free(sfx->cache);
+ if (sfx->truename)
+ Z_Free(sfx->truename);
+ memset(sfx, 0, sizeof(*sfx));
}
-void S_FreeAllSounds( void ) {
+void S_FreeAllSounds(void)
+{
int i;
sfx_t *sfx;
// free all sounds
- for( i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++ ) {
- if( !sfx->name[0] )
+ for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++) {
+ if (!sfx->name[0])
continue;
- S_FreeSound( sfx );
+ S_FreeSound(sfx);
}
num_sfx = 0;
}
-void S_Shutdown( void ) {
- if( !s_started )
+void S_Shutdown(void)
+{
+ if (!s_started)
return;
S_StopAllSounds();
S_FreeAllSounds();
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
AL_Shutdown();
else
#endif
@@ -250,36 +257,37 @@ void S_Shutdown( void ) {
s_auto_focus->changed = NULL;
- Cmd_Deregister( c_sound );
+ Cmd_Deregister(c_sound);
- Z_LeakTest( TAG_SOUND );
+ Z_LeakTest(TAG_SOUND);
}
-void S_Activate( void ) {
+void S_Activate(void)
+{
qboolean active;
active_t level;
- if( !s_started )
+ if (!s_started)
return;
- level = Cvar_ClampInteger( s_auto_focus, ACT_MINIMIZED, ACT_ACTIVATED );
+ level = Cvar_ClampInteger(s_auto_focus, ACT_MINIMIZED, ACT_ACTIVATED);
active = cls.active >= level;
- if( active == s_active )
+ if (active == s_active)
return;
s_active = active;
- Com_DDDPrintf( "%s: %d\n", __func__, s_active );
+ Com_DDDPrintf("%s: %d\n", __func__, s_active);
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
S_StopAllSounds();
#endif
#if USE_SNDDMA
- if( s_started == SS_DMA )
+ if (s_started == SS_DMA)
DMA_Activate();
#endif
}
@@ -294,34 +302,36 @@ void S_Activate( void ) {
S_SfxForHandle
==================
*/
-sfx_t *S_SfxForHandle( qhandle_t hSfx ) {
- if( !hSfx ) {
+sfx_t *S_SfxForHandle(qhandle_t hSfx)
+{
+ if (!hSfx) {
return NULL;
}
- if( hSfx < 1 || hSfx > num_sfx ) {
- Com_Error( ERR_DROP, "S_SfxForHandle: %d out of range", hSfx );
+ if (hSfx < 1 || hSfx > num_sfx) {
+ Com_Error(ERR_DROP, "S_SfxForHandle: %d out of range", hSfx);
}
return &known_sfx[hSfx - 1];
}
-static sfx_t *S_AllocSfx( void ) {
+static sfx_t *S_AllocSfx(void)
+{
sfx_t *sfx;
int i;
// find a free sfx
- for( i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++ ) {
- if( !sfx->name[0] )
+ for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++) {
+ if (!sfx->name[0])
break;
}
- if( i == num_sfx ) {
- if( num_sfx == MAX_SFX )
- Com_Error( ERR_DROP, "S_AllocSfx: out of sfx_t" );
+ if (i == num_sfx) {
+ if (num_sfx == MAX_SFX)
+ Com_Error(ERR_DROP, "S_AllocSfx: out of sfx_t");
num_sfx++;
}
-
+
return sfx;
}
@@ -331,13 +341,14 @@ S_FindName
==================
*/
-static sfx_t *S_FindName( const char *name, size_t namelen ) {
+static sfx_t *S_FindName(const char *name, size_t namelen)
+{
int i;
sfx_t *sfx;
// see if already loaded
- for( i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++ ) {
- if( !FS_pathcmp( sfx->name, name ) ) {
+ for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++) {
+ if (!FS_pathcmp(sfx->name, name)) {
sfx->registration_sequence = s_registration_sequence;
return sfx;
}
@@ -345,9 +356,9 @@ static sfx_t *S_FindName( const char *name, size_t namelen ) {
// allocate new one
sfx = S_AllocSfx();
- memcpy( sfx->name, name, namelen + 1 );
+ memcpy(sfx->name, name, namelen + 1);
sfx->registration_sequence = s_registration_sequence;
-
+
return sfx;
}
@@ -357,7 +368,8 @@ S_BeginRegistration
=====================
*/
-void S_BeginRegistration( void ) {
+void S_BeginRegistration(void)
+{
s_registration_sequence++;
s_registering = qtrue;
}
@@ -368,47 +380,48 @@ S_RegisterSound
==================
*/
-qhandle_t S_RegisterSound( const char *name ) {
+qhandle_t S_RegisterSound(const char *name)
+{
char buffer[MAX_QPATH];
sfx_t *sfx;
size_t len;
- if( !s_started )
+ if (!s_started)
return 0;
// empty names are legal, silently ignore them
- if( !*name )
+ if (!*name)
return 0;
- if( *name == '*' ) {
- len = Q_strlcpy( buffer, name, MAX_QPATH );
- } else if( *name == '#' ) {
- len = FS_NormalizePathBuffer( buffer, name + 1, MAX_QPATH );
+ if (*name == '*') {
+ len = Q_strlcpy(buffer, name, MAX_QPATH);
+ } else if (*name == '#') {
+ len = FS_NormalizePathBuffer(buffer, name + 1, MAX_QPATH);
} else {
- len = Q_concat( buffer, MAX_QPATH, "sound/", name, NULL );
- if( len < MAX_QPATH )
- len = FS_NormalizePath( buffer, buffer );
+ len = Q_concat(buffer, MAX_QPATH, "sound/", name, NULL);
+ if (len < MAX_QPATH)
+ len = FS_NormalizePath(buffer, buffer);
}
// this MAY happen after prepending "sound/"
- if( len >= MAX_QPATH ) {
- Com_DPrintf( "%s: oversize name\n", __func__ );
+ if (len >= MAX_QPATH) {
+ Com_DPrintf("%s: oversize name\n", __func__);
return 0;
}
// normalized to empty name?
- if( len == 0 ) {
- Com_DPrintf( "%s: empty name\n", __func__ );
+ if (len == 0) {
+ Com_DPrintf("%s: empty name\n", __func__);
return 0;
}
- sfx = S_FindName( buffer, len );
+ sfx = S_FindName(buffer, len);
- if( !s_registering ) {
- S_LoadSound( sfx );
+ if (!s_registering) {
+ S_LoadSound(sfx);
}
- return ( sfx - known_sfx ) + 1;
+ return (sfx - known_sfx) + 1;
}
/*
@@ -416,44 +429,45 @@ qhandle_t S_RegisterSound( const char *name ) {
S_RegisterSexedSound
====================
*/
-static sfx_t *S_RegisterSexedSound( int entnum, const char *base ) {
+static sfx_t *S_RegisterSexedSound(int entnum, const char *base)
+{
sfx_t *sfx;
char *model;
char buffer[MAX_QPATH];
size_t len;
// determine what model the client is using
- if( entnum > 0 && entnum <= MAX_CLIENTS )
- model = cl.clientinfo[ entnum - 1 ].model_name;
+ if (entnum > 0 && entnum <= MAX_CLIENTS)
+ model = cl.clientinfo[entnum - 1].model_name;
else
model = cl.baseclientinfo.model_name;
// if we can't figure it out, they're male
- if( !*model )
+ if (!*model)
model = "male";
// see if we already know of the model specific sound
- len = Q_concat( buffer, MAX_QPATH,
- "players/", model, "/", base + 1, NULL );
- if( len >= MAX_QPATH ) {
- len = Q_concat( buffer, MAX_QPATH,
- "players/", "male", "/", base + 1, NULL );
- if( len >= MAX_QPATH )
+ len = Q_concat(buffer, MAX_QPATH,
+ "players/", model, "/", base + 1, NULL);
+ if (len >= MAX_QPATH) {
+ len = Q_concat(buffer, MAX_QPATH,
+ "players/", "male", "/", base + 1, NULL);
+ if (len >= MAX_QPATH)
return NULL;
}
- len = FS_NormalizePath( buffer, buffer );
- sfx = S_FindName( buffer, len );
+ len = FS_NormalizePath(buffer, buffer);
+ sfx = S_FindName(buffer, len);
// see if it exists
- if( !sfx->truename && !S_LoadSound( sfx ) ) {
+ if (!sfx->truename && !S_LoadSound(sfx)) {
// no, revert to the male sound in the pak0.pak
- len = Q_concat( buffer, MAX_QPATH,
- "sound/player/male/", base + 1, NULL );
- if( len < MAX_QPATH ) {
- FS_NormalizePath( buffer, buffer );
+ len = Q_concat(buffer, MAX_QPATH,
+ "sound/player/male/", base + 1, NULL);
+ if (len < MAX_QPATH) {
+ FS_NormalizePath(buffer, buffer);
sfx->error = Q_ERR_SUCCESS;
- sfx->truename = S_CopyString( buffer );
+ sfx->truename = S_CopyString(buffer);
}
}
@@ -466,7 +480,8 @@ S_EndRegistration
=====================
*/
-void S_EndRegistration( void ) {
+void S_EndRegistration(void)
+{
int i;
sfx_t *sfx;
#if USE_SNDDMA
@@ -478,33 +493,33 @@ void S_EndRegistration( void ) {
S_StopAllSounds();
// free any sounds not from this registration sequence
- for( i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++ ) {
- if( !sfx->name[0] )
+ for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++) {
+ if (!sfx->name[0])
continue;
- if( sfx->registration_sequence != s_registration_sequence ) {
+ if (sfx->registration_sequence != s_registration_sequence) {
// don't need this sound
- S_FreeSound( sfx );
+ S_FreeSound(sfx);
continue;
}
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
continue;
#endif
#if USE_SNDDMA
// make sure it is paged in
sc = sfx->cache;
- if( sc ) {
+ if (sc) {
size = sc->length * sc->width;
- Com_PageInMemory( sc, size );
+ Com_PageInMemory(sc, size);
}
#endif
}
// load everything in
- for( i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++ ) {
- if( !sfx->name[0] )
+ for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++) {
+ if (!sfx->name[0])
continue;
- S_LoadSound( sfx );
+ S_LoadSound(sfx);
}
s_registering = qfalse;
@@ -520,23 +535,24 @@ S_PickChannel
picks a channel based on priorities, empty slots, number of channels
=================
*/
-channel_t *S_PickChannel( int entnum, int entchannel ) {
+channel_t *S_PickChannel(int entnum, int entchannel)
+{
int ch_idx;
int first_to_die;
int life_left;
channel_t *ch;
- if( entchannel < 0 )
- Com_Error( ERR_DROP, "S_PickChannel: entchannel < 0" );
+ if (entchannel < 0)
+ Com_Error(ERR_DROP, "S_PickChannel: entchannel < 0");
// Check for replacement sound, or find the best one to replace
first_to_die = -1;
life_left = 0x7fffffff;
- for( ch_idx = 0; ch_idx < s_numchannels; ch_idx++ ) {
+ for (ch_idx = 0; ch_idx < s_numchannels; ch_idx++) {
ch = &channels[ch_idx];
// channel 0 never overrides unless out of channels
- if( ch->entnum == entnum && ch->entchannel == entchannel && entchannel != 0 ) {
- if( entchannel == 256 && ch->sfx ) {
+ if (ch->entnum == entnum && ch->entchannel == entchannel && entchannel != 0) {
+ if (entchannel == 256 && ch->sfx) {
return NULL; // channel 256 never overrides
}
// always override sound from same entity
@@ -545,27 +561,27 @@ channel_t *S_PickChannel( int entnum, int entchannel ) {
}
// don't let monster sounds override player sounds
- if( ch->entnum == listener_entnum && entnum != listener_entnum && ch->sfx )
+ if (ch->entnum == listener_entnum && entnum != listener_entnum && ch->sfx)
continue;
- if( ch->end - paintedtime < life_left ) {
+ if (ch->end - paintedtime < life_left) {
life_left = ch->end - paintedtime;
first_to_die = ch_idx;
}
}
- if( first_to_die == -1 )
+ if (first_to_die == -1)
return NULL;
ch = &channels[first_to_die];
#if USE_OPENAL
- if( s_started == SS_OAL && ch->sfx )
- AL_StopChannel( ch );
+ if (s_started == SS_OAL && ch->sfx)
+ AL_StopChannel(ch);
#endif
- memset( ch, 0, sizeof( *ch ) );
+ memset(ch, 0, sizeof(*ch));
return ch;
-}
+}
#if USE_SNDDMA
@@ -576,47 +592,48 @@ S_SpatializeOrigin
Used for spatializing channels and autosounds
=================
*/
-static void S_SpatializeOrigin( const vec3_t origin, float master_vol, float dist_mult, int *left_vol, int *right_vol ) {
+static void S_SpatializeOrigin(const vec3_t origin, float master_vol, float dist_mult, int *left_vol, int *right_vol)
+{
vec_t dot;
vec_t dist;
vec_t lscale, rscale, scale;
vec3_t source_vec;
- if( cls.state != ca_active ) {
+ if (cls.state != ca_active) {
*left_vol = *right_vol = 255;
return;
}
// calculate stereo seperation and distance attenuation
- VectorSubtract( origin, listener_origin, source_vec );
+ VectorSubtract(origin, listener_origin, source_vec);
- dist = VectorNormalize( source_vec );
+ dist = VectorNormalize(source_vec);
dist -= SOUND_FULLVOLUME;
- if( dist < 0 )
+ if (dist < 0)
dist = 0; // close enough to be at full volume
dist *= dist_mult; // different attenuation levels
-
- dot = DotProduct( listener_right, source_vec );
- if( dma.channels == 1 || !dist_mult ) {
+ dot = DotProduct(listener_right, source_vec);
+
+ if (dma.channels == 1 || !dist_mult) {
// no attenuation = no spatialization
rscale = 1.0;
lscale = 1.0;
} else {
- rscale = 0.5 * ( 1.0 + dot );
- lscale = 0.5 * ( 1.0 - dot );
+ rscale = 0.5 * (1.0 + dot);
+ lscale = 0.5 * (1.0 - dot);
}
master_vol *= 255.0;
// add in distance effect
- scale = ( 1.0 - dist ) * rscale;
- *right_vol = (int)( master_vol * scale );
- if( *right_vol < 0 )
+ scale = (1.0 - dist) * rscale;
+ *right_vol = (int)(master_vol * scale);
+ if (*right_vol < 0)
*right_vol = 0;
- scale = ( 1.0 - dist ) * lscale;
- *left_vol = (int)( master_vol * scale );
+ scale = (1.0 - dist) * lscale;
+ *left_vol = (int)(master_vol * scale);
if (*left_vol < 0)
*left_vol = 0;
}
@@ -626,23 +643,24 @@ static void S_SpatializeOrigin( const vec3_t origin, float master_vol, float dis
S_Spatialize
=================
*/
-static void S_Spatialize( channel_t *ch ) {
+static void S_Spatialize(channel_t *ch)
+{
vec3_t origin;
// anything coming from the view entity will always be full volume
- if( ch->entnum == -1 || ch->entnum == listener_entnum ) {
+ if (ch->entnum == -1 || ch->entnum == listener_entnum) {
ch->leftvol = ch->master_vol * 255;
ch->rightvol = ch->master_vol * 255;
return;
}
- if( ch->fixed_origin ) {
- VectorCopy( ch->origin, origin );
+ if (ch->fixed_origin) {
+ VectorCopy(ch->origin, origin);
} else {
- CL_GetEntitySoundOrigin( ch->entnum, origin );
+ CL_GetEntitySoundOrigin(ch->entnum, origin);
}
- S_SpatializeOrigin( origin, ch->master_vol, ch->dist_mult, &ch->leftvol, &ch->rightvol );
+ S_SpatializeOrigin(origin, ch->master_vol, ch->dist_mult, &ch->leftvol, &ch->rightvol);
}
#endif
@@ -652,17 +670,18 @@ static void S_Spatialize( channel_t *ch ) {
S_AllocPlaysound
=================
*/
-static playsound_t *S_AllocPlaysound( void ) {
+static playsound_t *S_AllocPlaysound(void)
+{
playsound_t *ps;
ps = s_freeplays.next;
- if( ps == &s_freeplays )
+ if (ps == &s_freeplays)
return NULL; // no free playsounds
// unlink from freelist
ps->prev->next = ps->next;
ps->next->prev = ps->prev;
-
+
return ps;
}
@@ -672,7 +691,8 @@ static playsound_t *S_AllocPlaysound( void ) {
S_FreePlaysound
=================
*/
-static void S_FreePlaysound( playsound_t *ps ) {
+static void S_FreePlaysound(playsound_t *ps)
+{
// unlink from channel
ps->prev->next = ps->next;
ps->next->prev = ps->prev;
@@ -693,30 +713,31 @@ This is never called directly by S_Play*, but only
by the update loop.
===============
*/
-void S_IssuePlaysound( playsound_t *ps ) {
+void S_IssuePlaysound(playsound_t *ps)
+{
channel_t *ch;
sfxcache_t *sc;
#ifdef _DEBUG
- if( s_show->integer )
- Com_Printf( "Issue %i\n", ps->begin );
+ if (s_show->integer)
+ Com_Printf("Issue %i\n", ps->begin);
#endif
// pick a channel to play on
- ch = S_PickChannel( ps->entnum, ps->entchannel );
- if( !ch ) {
- S_FreePlaysound( ps );
+ ch = S_PickChannel(ps->entnum, ps->entchannel);
+ if (!ch) {
+ S_FreePlaysound(ps);
return;
}
- sc = S_LoadSound( ps->sfx );
- if( !sc ) {
- Com_Printf( "S_IssuePlaysound: couldn't load %s\n", ps->sfx->name );
- S_FreePlaysound( ps );
+ sc = S_LoadSound(ps->sfx);
+ if (!sc) {
+ Com_Printf("S_IssuePlaysound: couldn't load %s\n", ps->sfx->name);
+ S_FreePlaysound(ps);
return;
}
// spatialize
- if( ps->attenuation == ATTN_STATIC )
+ if (ps->attenuation == ATTN_STATIC)
ch->dist_mult = ps->attenuation * 0.001;
else
ch->dist_mult = ps->attenuation * 0.0005;
@@ -724,24 +745,24 @@ void S_IssuePlaysound( playsound_t *ps ) {
ch->entnum = ps->entnum;
ch->entchannel = ps->entchannel;
ch->sfx = ps->sfx;
- VectorCopy( ps->origin, ch->origin );
+ VectorCopy(ps->origin, ch->origin);
ch->fixed_origin = ps->fixed_origin;
#if USE_OPENAL
- if( s_started == SS_OAL )
- AL_PlayChannel( ch );
+ if (s_started == SS_OAL)
+ AL_PlayChannel(ch);
#endif
#if USE_SNDDMA
- if( s_started == SS_DMA )
- S_Spatialize( ch );
+ if (s_started == SS_DMA)
+ S_Spatialize(ch);
#endif
ch->pos = 0;
ch->end = paintedtime + sc->length;
// free the playsound
- S_FreePlaysound( ps );
+ S_FreePlaysound(ps);
}
// =======================================================================
@@ -757,38 +778,39 @@ if pos is NULL, the sound will be dynamically sourced from the entity
Entchannel 0 will never override a playing sound
====================
*/
-void S_StartSound( const vec3_t origin, int entnum, int entchannel, qhandle_t hSfx, float vol, float attenuation, float timeofs ) {
+void S_StartSound(const vec3_t origin, int entnum, int entchannel, qhandle_t hSfx, float vol, float attenuation, float timeofs)
+{
sfxcache_t *sc;
playsound_t *ps, *sort;
sfx_t *sfx;
- if( !s_started )
+ if (!s_started)
return;
- if( !s_active )
+ if (!s_active)
return;
- if( !( sfx = S_SfxForHandle( hSfx ) ) ) {
+ if (!(sfx = S_SfxForHandle(hSfx))) {
return;
}
- if( sfx->name[0] == '*' ) {
- sfx = S_RegisterSexedSound( entnum, sfx->name );
- if( !sfx )
+ if (sfx->name[0] == '*') {
+ sfx = S_RegisterSexedSound(entnum, sfx->name);
+ if (!sfx)
return;
}
// make sure the sound is loaded
- sc = S_LoadSound( sfx );
- if( !sc )
+ sc = S_LoadSound(sfx);
+ if (!sc)
return; // couldn't load the sound's data
// make the playsound_t
ps = S_AllocPlaysound();
- if( !ps )
+ if (!ps)
return;
- if( origin ) {
- VectorCopy( origin, ps->origin );
+ if (origin) {
+ VectorCopy(origin, ps->origin);
ps->fixed_origin = qtrue;
} else {
ps->fixed_origin = qfalse;
@@ -801,17 +823,17 @@ void S_StartSound( const vec3_t origin, int entnum, int entchannel, qhandle_t hS
ps->sfx = sfx;
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
ps->begin = paintedtime + timeofs * 1000;
#endif
#if USE_SNDDMA
- if( s_started == SS_DMA )
- ps->begin = DMA_DriftBeginofs( timeofs );
+ if (s_started == SS_DMA)
+ ps->begin = DMA_DriftBeginofs(timeofs);
#endif
// sort into the pending sound list
- for( sort = s_pendingplays.next ; sort != &s_pendingplays && sort->begin < ps->begin ; sort = sort->next )
+ for (sort = s_pendingplays.next; sort != &s_pendingplays && sort->begin < ps->begin; sort = sort->next)
;
ps->next = sort;
@@ -821,20 +843,21 @@ void S_StartSound( const vec3_t origin, int entnum, int entchannel, qhandle_t hS
ps->prev->next = ps;
}
-void S_ParseStartSound( void ) {
+void S_ParseStartSound(void)
+{
qhandle_t handle = cl.sound_precache[snd.index];
- if( !handle )
+ if (!handle)
return;
#ifdef _DEBUG
- if( developer->integer && !( snd.flags & SND_POS ) )
- CL_CheckEntityPresent( snd.entity, "sound" );
+ if (developer->integer && !(snd.flags & SND_POS))
+ CL_CheckEntityPresent(snd.entity, "sound");
#endif
- S_StartSound( ( snd.flags & SND_POS ) ? snd.pos : NULL,
- snd.entity, snd.channel, handle,
- snd.volume, snd.attenuation, snd.timeofs );
+ S_StartSound((snd.flags & SND_POS) ? snd.pos : NULL,
+ snd.entity, snd.channel, handle,
+ snd.volume, snd.attenuation, snd.timeofs);
}
/*
@@ -842,17 +865,19 @@ void S_ParseStartSound( void ) {
S_StartLocalSound
==================
*/
-void S_StartLocalSound( const char *sound ) {
- if( s_started ) {
- qhandle_t sfx = S_RegisterSound( sound );
- S_StartSound( NULL, listener_entnum, 0, sfx, 1, 1, 0 );
+void S_StartLocalSound(const char *sound)
+{
+ if (s_started) {
+ qhandle_t sfx = S_RegisterSound(sound);
+ S_StartSound(NULL, listener_entnum, 0, sfx, 1, 1, 0);
}
}
-void S_StartLocalSound_( const char *sound ) {
- if( s_started ) {
- qhandle_t sfx = S_RegisterSound( sound );
- S_StartSound( NULL, listener_entnum, 256, sfx, 1, 1, 0 );
+void S_StartLocalSound_(const char *sound)
+{
+ if (s_started) {
+ qhandle_t sfx = S_RegisterSound(sound);
+ S_StartSound(NULL, listener_entnum, 256, sfx, 1, 1, 0);
}
}
@@ -873,8 +898,7 @@ void S_StopAllSounds(void)
s_freeplays.next = s_freeplays.prev = &s_freeplays;
s_pendingplays.next = s_pendingplays.prev = &s_pendingplays;
- for (i=0 ; i<MAX_PLAYSOUNDS ; i++)
- {
+ for (i = 0; i < MAX_PLAYSOUNDS; i++) {
s_playsounds[i].prev = &s_freeplays;
s_playsounds[i].next = s_freeplays.next;
s_playsounds[i].prev->next = &s_playsounds[i];
@@ -882,12 +906,12 @@ void S_StopAllSounds(void)
}
#if USE_OPENAL
- if( s_started == SS_OAL )
+ if (s_started == SS_OAL)
AL_StopAllChannels();
#endif
#if USE_SNDDMA
- if( s_started == SS_DMA )
+ if (s_started == SS_DMA)
DMA_ClearBuffer();
#endif
@@ -899,17 +923,18 @@ void S_StopAllSounds(void)
// Update sound buffer
// =======================================================================
-void S_BuildSoundList( int *sounds ) {
+void S_BuildSoundList(int *sounds)
+{
int i;
int num;
entity_state_t *ent;
- for( i = 0; i < cl.frame.numEntities; i++ ) {
- num = ( cl.frame.firstEntity + i ) & PARSE_ENTITIES_MASK;
+ for (i = 0; i < cl.frame.numEntities; i++) {
+ num = (cl.frame.firstEntity + i) & PARSE_ENTITIES_MASK;
ent = &cl.entityStates[num];
- if( s_ambient->integer == 2 && !ent->modelindex ) {
+ if (s_ambient->integer == 2 && !ent->modelindex) {
sounds[i] = 0;
- } else if( s_ambient->integer == 3 && ent->number != listener_entnum ) {
+ } else if (s_ambient->integer == 3 && ent->number != listener_entnum) {
sounds[i] = 0;
} else {
sounds[i] = ent->sound;
@@ -928,7 +953,7 @@ that are automatically started, stopped, and merged together
as the entities are sent to the client
==================
*/
-static void S_AddLoopSounds (void)
+static void S_AddLoopSounds(void)
{
int i, j;
int sounds[MAX_PACKET_ENTITIES];
@@ -940,42 +965,41 @@ static void S_AddLoopSounds (void)
entity_state_t *ent;
vec3_t origin;
- if( cls.state != ca_active || !s_active || sv_paused->integer || !s_ambient->integer ) {
+ if (cls.state != ca_active || !s_active || sv_paused->integer || !s_ambient->integer) {
return;
}
- S_BuildSoundList( sounds );
+ S_BuildSoundList(sounds);
- for( i = 0; i < cl.frame.numEntities; i++ ) {
+ for (i = 0; i < cl.frame.numEntities; i++) {
if (!sounds[i])
continue;
- sfx = S_SfxForHandle( cl.sound_precache[sounds[i]] );
+ sfx = S_SfxForHandle(cl.sound_precache[sounds[i]]);
if (!sfx)
continue; // bad sound effect
sc = sfx->cache;
if (!sc)
continue;
- num = ( cl.frame.firstEntity + i ) & PARSE_ENTITIES_MASK;
+ num = (cl.frame.firstEntity + i) & PARSE_ENTITIES_MASK;
ent = &cl.entityStates[num];
// find the total contribution of all sounds of this type
- CL_GetEntitySoundOrigin( ent->number, origin );
- S_SpatializeOrigin (origin, 1.0, SOUND_LOOPATTENUATE,
- &left_total, &right_total);
- for (j=i+1 ; j<cl.frame.numEntities ; j++)
- {
+ CL_GetEntitySoundOrigin(ent->number, origin);
+ S_SpatializeOrigin(origin, 1.0, SOUND_LOOPATTENUATE,
+ &left_total, &right_total);
+ for (j = i + 1; j < cl.frame.numEntities; j++) {
if (sounds[j] != sounds[i])
continue;
sounds[j] = 0; // don't check this again later
- num = ( cl.frame.firstEntity + j ) & PARSE_ENTITIES_MASK;
+ num = (cl.frame.firstEntity + j) & PARSE_ENTITIES_MASK;
ent = &cl.entityStates[num];
- CL_GetEntitySoundOrigin( ent->number, origin );
- S_SpatializeOrigin (origin, 1.0, SOUND_LOOPATTENUATE,
- &left, &right);
+ CL_GetEntitySoundOrigin(ent->number, origin);
+ S_SpatializeOrigin(origin, 1.0, SOUND_LOOPATTENUATE,
+ &left, &right);
left_total += left;
right_total += right;
}
@@ -1010,14 +1034,15 @@ S_Update
Called once each time through the main loop
============
*/
-void S_Update( void ) {
+void S_Update(void)
+{
#if USE_SNDDMA
int i;
channel_t *ch;
#endif
- if( cvar_modified & CVAR_SOUND ) {
- Cbuf_AddText( &cmd_buffer, "snd_restart\n" );
+ if (cvar_modified & CVAR_SOUND) {
+ Cbuf_AddText(&cmd_buffer, "snd_restart\n");
cvar_modified &= ~CVAR_SOUND;
return;
}
@@ -1035,14 +1060,14 @@ void S_Update( void ) {
// set listener entity number
// other parameters should be already set up by CL_CalcViewValues
- if( cl.clientNum == -1 || cl.frame.clientNum == CLIENTNUM_NONE ) {
+ if (cl.clientNum == -1 || cl.frame.clientNum == CLIENTNUM_NONE) {
listener_entnum = -1;
} else {
listener_entnum = cl.frame.clientNum + 1;
}
#if USE_OPENAL
- if( s_started == SS_OAL ) {
+ if (s_started == SS_OAL) {
AL_Update();
return;
}
@@ -1051,47 +1076,43 @@ void S_Update( void ) {
#if USE_SNDDMA
// rebuild scale tables if volume is modified
if (s_volume->modified)
- S_InitScaletable ();
+ S_InitScaletable();
- // update spatialization for dynamic sounds
+ // update spatialization for dynamic sounds
ch = channels;
- for (i=0 ; i<s_numchannels; i++, ch++)
- {
+ for (i = 0; i < s_numchannels; i++, ch++) {
if (!ch->sfx)
continue;
- if (ch->autosound)
- { // autosounds are regenerated fresh each frame
- memset (ch, 0, sizeof(*ch));
+ if (ch->autosound) {
+ // autosounds are regenerated fresh each frame
+ memset(ch, 0, sizeof(*ch));
continue;
}
S_Spatialize(ch); // respatialize channel
- if (!ch->leftvol && !ch->rightvol)
- {
- memset (ch, 0, sizeof(*ch));
+ if (!ch->leftvol && !ch->rightvol) {
+ memset(ch, 0, sizeof(*ch));
continue;
}
}
// add loopsounds
- S_AddLoopSounds ();
+ S_AddLoopSounds();
#ifdef _DEBUG
//
// debugging output
//
- if (s_show->integer)
- {
+ if (s_show->integer) {
int total = 0;
ch = channels;
- for (i=0 ; i<s_numchannels; i++, ch++)
- if (ch->sfx && (ch->leftvol || ch->rightvol) )
- {
- Com_Printf ("%3i %3i %s\n", ch->leftvol, ch->rightvol, ch->sfx->name);
+ for (i = 0; i < s_numchannels; i++, ch++)
+ if (ch->sfx && (ch->leftvol || ch->rightvol)) {
+ Com_Printf("%3i %3i %s\n", ch->leftvol, ch->rightvol, ch->sfx->name);
total++;
}
-
- if( s_show->integer > 1 || total ) {
- Com_Printf ("----(%i)---- painted: %i\n", total, paintedtime);
+
+ if (s_show->integer > 1 || total) {
+ Com_Printf("----(%i)---- painted: %i\n", total, paintedtime);
}
}
#endif