Quake II RTX doxygen  1.0 dev
sound.h File Reference
#include "../client.h"

Go to the source code of this file.

Classes

struct  samplepair_s
 
struct  sfxcache_s
 
struct  sfx_s
 
struct  playsound_s
 
struct  channel_s
 
struct  wavinfo_t
 

Macros

#define SOUND_FULLVOLUME   80
 
#define SOUND_LOOPATTENUATE   0.003
 
#define MAX_CHANNELS   32
 
#define S_MAX_RAW_SAMPLES   8192
 
#define S_Malloc(x)   Z_TagMalloc(x, TAG_SOUND)
 
#define S_CopyString(x)   Z_TagCopyString(x, TAG_SOUND)
 

Typedefs

typedef struct samplepair_s samplepair_t
 
typedef struct sfxcache_s sfxcache_t
 
typedef struct sfx_s sfx_t
 
typedef struct playsound_s playsound_t
 
typedef struct channel_s channel_t
 

Functions

sfx_tS_SfxForHandle (qhandle_t hSfx)
 
sfxcache_tS_LoadSound (sfx_t *s)
 
channel_tS_PickChannel (int entnum, int entchannel)
 
void S_IssuePlaysound (playsound_t *ps)
 
void S_BuildSoundList (int *sounds)
 

Variables

qboolean s_active
 
channel_t channels [MAX_CHANNELS]
 
int s_numchannels
 
int paintedtime
 
playsound_t s_pendingplays
 
vec3_t listener_origin
 
vec3_t listener_forward
 
vec3_t listener_right
 
vec3_t listener_up
 
int listener_entnum
 
samplepair_t s_rawsamples [S_MAX_RAW_SAMPLES]
 
int s_rawend
 
wavinfo_t s_info
 
cvar_t * s_volume
 
cvar_t * s_ambient
 
cvar_t * s_show
 

Macro Definition Documentation

◆ MAX_CHANNELS

#define MAX_CHANNELS   32

Definition at line 141 of file sound.h.

◆ S_CopyString

#define S_CopyString (   x)    Z_TagCopyString(x, TAG_SOUND)

Definition at line 169 of file sound.h.

◆ S_Malloc

#define S_Malloc (   x)    Z_TagMalloc(x, TAG_SOUND)

Definition at line 168 of file sound.h.

◆ S_MAX_RAW_SAMPLES

#define S_MAX_RAW_SAMPLES   8192

Definition at line 154 of file sound.h.

◆ SOUND_FULLVOLUME

#define SOUND_FULLVOLUME   80

Definition at line 135 of file sound.h.

◆ SOUND_LOOPATTENUATE

#define SOUND_LOOPATTENUATE   0.003

Definition at line 137 of file sound.h.

Typedef Documentation

◆ channel_t

typedef struct channel_s channel_t

◆ playsound_t

typedef struct playsound_s playsound_t

◆ samplepair_t

typedef struct samplepair_s samplepair_t

◆ sfx_t

typedef struct sfx_s sfx_t

◆ sfxcache_t

typedef struct sfxcache_s sfxcache_t

Function Documentation

◆ S_BuildSoundList()

void S_BuildSoundList ( int sounds)

Definition at line 969 of file main.c.

970 {
971  int i;
972  int num;
973  entity_state_t *ent;
974 
975  for (i = 0; i < cl.frame.numEntities; i++) {
976  num = (cl.frame.firstEntity + i) & PARSE_ENTITIES_MASK;
977  ent = &cl.entityStates[num];
978  if (s_ambient->integer == 2 && !ent->modelindex) {
979  sounds[i] = 0;
980  } else if (s_ambient->integer == 3 && ent->number != listener_entnum) {
981  sounds[i] = 0;
982  } else {
983  sounds[i] = ent->sound;
984  }
985  }
986 }

Referenced by AL_AddLoopSounds().

◆ S_IssuePlaysound()

void S_IssuePlaysound ( playsound_t ps)

Definition at line 759 of file main.c.

760 {
761  channel_t *ch;
762  sfxcache_t *sc;
763 
764 #ifdef _DEBUG
765  if (s_show->integer)
766  Com_Printf("Issue %i\n", ps->begin);
767 #endif
768  // pick a channel to play on
769  ch = S_PickChannel(ps->entnum, ps->entchannel);
770  if (!ch) {
771  S_FreePlaysound(ps);
772  return;
773  }
774 
775  sc = S_LoadSound(ps->sfx);
776  if (!sc) {
777  Com_Printf("S_IssuePlaysound: couldn't load %s\n", ps->sfx->name);
778  S_FreePlaysound(ps);
779  return;
780  }
781 
782  // spatialize
783  if (ps->attenuation == ATTN_STATIC)
784  ch->dist_mult = ps->attenuation * 0.001;
785  else
786  ch->dist_mult = ps->attenuation * 0.0005;
787  ch->master_vol = ps->volume;
788  ch->entnum = ps->entnum;
789  ch->entchannel = ps->entchannel;
790  ch->sfx = ps->sfx;
791  VectorCopy(ps->origin, ch->origin);
792  ch->fixed_origin = ps->fixed_origin;
793 
794 #if USE_OPENAL
795  if (s_started == SS_OAL)
796  AL_PlayChannel(ch);
797 #endif
798 
799 #if USE_SNDDMA
800  if (s_started == SS_DMA)
801  S_Spatialize(ch);
802 #endif
803 
804  ch->pos = 0;
805  ch->end = paintedtime + sc->length;
806 
807  // free the playsound
808  S_FreePlaysound(ps);
809 }

Referenced by AL_IssuePlaysounds(), and S_PaintChannels().

◆ S_LoadSound()

sfxcache_t* S_LoadSound ( sfx_t s)

Definition at line 288 of file mem.c.

289 {
290  byte *data;
291  sfxcache_t *sc;
292  ssize_t len;
293  char *name;
294 
295  if (s->name[0] == '*')
296  return NULL;
297 
298 // see if still in memory
299  sc = s->cache;
300  if (sc)
301  return sc;
302 
303 // don't retry after error
304  if (s->error)
305  return NULL;
306 
307 // load it in
308  if (s->truename)
309  name = s->truename;
310  else
311  name = s->name;
312 
313  len = FS_LoadFile(name, (void **)&data);
314  if (!data) {
315  s->error = len;
316  return NULL;
317  }
318 
319  memset(&s_info, 0, sizeof(s_info));
320  s_info.name = name;
321 
322  iff_data = data;
323  iff_end = data + len;
324  if (!GetWavinfo()) {
325  s->error = Q_ERR_INVALID_FORMAT;
326  goto fail;
327  }
328 
329 #if USE_OPENAL
330  if (s_started == SS_OAL)
331  sc = AL_UploadSfx(s);
332 #endif
333 
334 #if USE_SNDDMA
335  if (s_started == SS_DMA)
336  sc = ResampleSfx(s);
337 #endif
338 
339 fail:
340  FS_FreeFile(data);
341  return sc;
342 }

Referenced by S_EndRegistration(), S_IssuePlaysound(), S_PaintChannels(), S_RegisterSexedSound(), S_RegisterSound(), and S_StartSound().

◆ S_PickChannel()

channel_t* S_PickChannel ( int  entnum,
int  entchannel 
)

Definition at line 579 of file main.c.

580 {
581  int ch_idx;
582  int first_to_die;
583  int life_left;
584  channel_t *ch;
585 
586  if (entchannel < 0)
587  Com_Error(ERR_DROP, "S_PickChannel: entchannel < 0");
588 
589 // Check for replacement sound, or find the best one to replace
590  first_to_die = -1;
591  life_left = 0x7fffffff;
592  for (ch_idx = 0; ch_idx < s_numchannels; ch_idx++) {
593  ch = &channels[ch_idx];
594  // channel 0 never overrides unless out of channels
595  if (ch->entnum == entnum && ch->entchannel == entchannel && entchannel != 0) {
596  if (entchannel == 256 && ch->sfx) {
597  return NULL; // channel 256 never overrides
598  }
599  // always override sound from same entity
600  first_to_die = ch_idx;
601  break;
602  }
603 
604  // don't let monster sounds override player sounds
605  if (ch->entnum == listener_entnum && entnum != listener_entnum && ch->sfx)
606  continue;
607 
608  if (ch->end - paintedtime < life_left) {
609  life_left = ch->end - paintedtime;
610  first_to_die = ch_idx;
611  }
612  }
613 
614  if (first_to_die == -1)
615  return NULL;
616 
617  ch = &channels[first_to_die];
618 #if USE_OPENAL
619  if (s_started == SS_OAL && ch->sfx)
620  AL_StopChannel(ch);
621 #endif
622  memset(ch, 0, sizeof(*ch));
623 
624  return ch;
625 }

Referenced by AL_AddLoopSounds(), and S_IssuePlaysound().

◆ S_SfxForHandle()

sfx_t* S_SfxForHandle ( qhandle_t  hSfx)

Definition at line 312 of file main.c.

313 {
314  if (!hSfx) {
315  return NULL;
316  }
317 
318  if (hSfx < 1 || hSfx > num_sfx) {
319  Com_Error(ERR_DROP, "S_SfxForHandle: %d out of range", hSfx);
320  }
321 
322  return &known_sfx[hSfx - 1];
323 }

Referenced by AL_AddLoopSounds(), and S_StartSound().

Variable Documentation

◆ channels

◆ listener_entnum

◆ listener_forward

vec3_t listener_forward

Definition at line 36 of file main.c.

Referenced by AL_Update(), and CL_CalcViewValues().

◆ listener_origin

vec3_t listener_origin

◆ listener_right

vec3_t listener_right

Definition at line 37 of file main.c.

Referenced by CL_CalcViewValues().

◆ listener_up

vec3_t listener_up

Definition at line 38 of file main.c.

Referenced by AL_Update(), and CL_CalcViewValues().

◆ paintedtime

◆ s_active

qboolean s_active

Definition at line 33 of file main.c.

Referenced by AL_Update(), DMA_Activate(), S_Activate(), S_Shutdown(), and S_StartSound().

◆ s_ambient

cvar_t* s_ambient

Definition at line 59 of file main.c.

Referenced by AL_AddLoopSounds(), S_BuildSoundList(), and S_Init().

◆ s_info

wavinfo_t s_info

Definition at line 22 of file mem.c.

Referenced by AL_UploadSfx(), GetWavinfo(), and S_LoadSound().

◆ s_numchannels

◆ s_pendingplays

playsound_t s_pendingplays

Definition at line 56 of file main.c.

Referenced by AL_IssuePlaysounds(), S_PaintChannels(), S_StartSound(), and S_StopAllSounds().

◆ s_rawend

int s_rawend

Definition at line 28 of file mix.c.

Referenced by AL_RawSamples(), OGG_Stream(), S_PaintChannels(), and S_RawSamples().

◆ s_rawsamples

Definition at line 27 of file mix.c.

Referenced by S_PaintChannels(), and S_RawSamples().

◆ s_show

◆ s_volume

cvar_t* s_volume

Definition at line 58 of file main.c.

Referenced by AL_Update(), S_Init(), S_InitScaletable(), S_RawSamples(), and S_Update().

client_state_s::frame
server_frame_t frame
Definition: client.h:212
edict_s::s
entity_state_t s
Definition: g_local.h:954
AL_PlayChannel
void AL_PlayChannel(channel_t *ch)
Definition: al.c:284
client_state_s::entityStates
entity_state_t entityStates[MAX_PARSE_ENTITIES]
Definition: client.h:204
s_info
wavinfo_t s_info
Definition: mem.c:22
AL_UploadSfx
sfxcache_t * AL_UploadSfx(sfx_t *s)
Definition: al.c:201
known_sfx
static sfx_t known_sfx[MAX_SFX]
Definition: main.c:50
s_show
cvar_t * s_show
channel_s::dist_mult
vec_t dist_mult
Definition: sound.h:78
channels
channel_t channels[MAX_CHANNELS]
Definition: main.c:29
iff_end
static byte * iff_end
Definition: mem.c:101
channel_s::origin
vec3_t origin
Definition: sound.h:77
iff_data
static byte * iff_data
Definition: mem.c:102
channel_s::end
int end
Definition: sound.h:72
sfxcache_s::length
int length
Definition: sound.h:34
paintedtime
int paintedtime
Definition: main.c:43
playsound_s::attenuation
float attenuation
Definition: sound.h:59
channel_s::entchannel
int entchannel
Definition: sound.h:76
S_FreePlaysound
static void S_FreePlaysound(playsound_t *ps)
Definition: main.c:737
playsound_s::begin
unsigned begin
Definition: sound.h:64
playsound_s::sfx
sfx_t * sfx
Definition: sound.h:57
channel_s::entnum
int entnum
Definition: sound.h:75
AL_StopChannel
void AL_StopChannel(channel_t *ch)
Definition: al.c:271
Com_Error
void Com_Error(error_type_t type, const char *fmt,...)
Definition: g_main.c:258
channel_s::pos
int pos
Definition: sound.h:73
GetWavinfo
static qboolean GetWavinfo(void)
Definition: mem.c:168
s_numchannels
int s_numchannels
Definition: main.c:30
edict_s::sounds
int sounds
Definition: g_local.h:1056
playsound_s::volume
float volume
Definition: sound.h:58
S_LoadSound
sfxcache_t * S_LoadSound(sfx_t *s)
Definition: mem.c:288
playsound_s::entchannel
int entchannel
Definition: sound.h:61
channel_s::sfx
sfx_t * sfx
Definition: sound.h:69
sfxcache_s
Definition: sound.h:33
S_PickChannel
channel_t * S_PickChannel(int entnum, int entchannel)
Definition: main.c:579
playsound_s::origin
vec3_t origin
Definition: sound.h:63
server_frame_t::numEntities
int numEntities
Definition: client.h:140
wavinfo_t::name
char * name
Definition: sound.h:89
channel_s
Definition: sound.h:68
playsound_s::entnum
int entnum
Definition: sound.h:60
channel_s::fixed_origin
qboolean fixed_origin
Definition: sound.h:80
listener_entnum
int listener_entnum
Definition: main.c:39
playsound_s::fixed_origin
qboolean fixed_origin
Definition: sound.h:62
cl
client_state_t cl
Definition: main.c:99
s_started
sndstarted_t s_started
Definition: main.c:32
num_sfx
static int num_sfx
Definition: main.c:51
channel_s::master_vol
float master_vol
Definition: sound.h:79
server_frame_t::firstEntity
int firstEntity
Definition: client.h:141
s_ambient
cvar_t * s_ambient
Definition: main.c:59
sfx_s::name
char name[MAX_QPATH]
Definition: sound.h:45