DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
sound.h File Reference
#include "matrixlib.h"
+ Include dependency graph for sound.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CHAN_ENGINE2CVAR(c)
 
#define CHAN_ENGINE2NET(c)
 
#define CHAN_ENGINE2USER(c)
 
#define CHAN_MAX_AUTO   0
 
#define CHAN_MAX_SINGLE   127
 
#define CHAN_MIN_AUTO   -128
 
#define CHAN_MIN_SINGLE   1
 
#define CHAN_NET2ENGINE(c)
 
#define CHAN_USER2ENGINE(c)
 
#define CHANNELFLAG_FORCELOOP   (1 << 1)
 
#define CHANNELFLAG_FULLVOLUME   (1 << 4)
 
#define CHANNELFLAG_LOCALSOUND   (1 << 2)
 
#define CHANNELFLAG_NONE   0
 
#define CHANNELFLAG_PAUSED   (1 << 3)
 
#define CHANNELFLAG_RELIABLE   (1 << 0)
 
#define DEFAULT_SOUND_PACKET_ATTENUATION   1.0
 
#define DEFAULT_SOUND_PACKET_VOLUME   255
 
#define IS_CHAN(n)
 
#define IS_CHAN_AUTO(n)
 
#define IS_CHAN_SINGLE(n)
 

Functions

void S_BlockSound (void)
 
void S_ClearUsed (void)
 
sfx_t * S_FindName (const char *name)
 
float S_GetChannelPosition (unsigned int ch_ind)
 
float S_GetEntChannelPosition (int entnum, int entchannel)
 
int S_GetSoundChannels (void)
 
int S_GetSoundRate (void)
 
int S_GetSoundWidth (void)
 
void S_Init (void)
 
qbool S_IsSoundPrecached (const sfx_t *sfx)
 
qbool S_LocalSound (const char *s)
 
qbool S_LocalSoundEx (const char *s, int chan, float fvol)
 
void S_PauseGameSounds (qbool toggle)
 
sfx_t * S_PrecacheSound (const char *sample, qbool complain, qbool levelsound)
 
void S_PurgeUnused (void)
 
qbool S_SetChannelFlag (unsigned int ch_ind, unsigned int flag, qbool value)
 
void S_SetChannelSpeed (unsigned int ch_ind, float fspeed)
 
void S_SetChannelVolume (unsigned int ch_ind, float fvol)
 
void S_Shutdown (void)
 
float S_SoundLength (const char *name)
 
int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
 S_StartSound returns the channel index, or -1 if an error occurred.
 
int S_StartSound_StartPosition_Flags (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float startposition, int flags, float fspeed)
 
void S_Startup (void)
 
void S_StaticSound (sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
 
void S_StopAllSounds (void)
 
void S_StopAllSounds_f (struct cmd_state_s *cmd)
 
void S_StopChannel (unsigned int channel_ind, qbool lockmutex, qbool freesfx)
 
void S_StopSound (int entnum, int entchannel)
 
void S_Terminate (void)
 
void S_UnblockSound (void)
 
void S_UnloadAllSounds_f (struct cmd_state_s *cmd)
 
void S_Update (const matrix4x4_t *listenermatrix)
 

Variables

cvar_t bgmvolume
 
cvar_t snd_initialized
 
cvar_t volume
 

Macro Definition Documentation

◆ CHAN_ENGINE2CVAR

#define CHAN_ENGINE2CVAR ( c)
Value:
(abs(c))

Definition at line 92 of file sound.h.

Referenced by SND_Spatialize_WithSfx().

◆ CHAN_ENGINE2NET

#define CHAN_ENGINE2NET ( c)
Value:
(c)

Definition at line 85 of file sound.h.

Referenced by SV_StartSound().

◆ CHAN_ENGINE2USER

#define CHAN_ENGINE2USER ( c)
Value:
(c)

Definition at line 91 of file sound.h.

Referenced by CL_VM_Event_Sound().

◆ CHAN_MAX_AUTO

#define CHAN_MAX_AUTO   0

Definition at line 77 of file sound.h.

◆ CHAN_MAX_SINGLE

#define CHAN_MAX_SINGLE   127

Definition at line 79 of file sound.h.

◆ CHAN_MIN_AUTO

#define CHAN_MIN_AUTO   -128

Definition at line 76 of file sound.h.

◆ CHAN_MIN_SINGLE

#define CHAN_MIN_SINGLE   1

Definition at line 78 of file sound.h.

◆ CHAN_NET2ENGINE

#define CHAN_NET2ENGINE ( c)
Value:
(c)

Definition at line 86 of file sound.h.

◆ CHAN_USER2ENGINE

#define CHAN_USER2ENGINE ( c)
Value:
(c)

Definition at line 90 of file sound.h.

Referenced by VM_getsoundtime(), and VM_SV_sound().

◆ CHANNELFLAG_FORCELOOP

#define CHANNELFLAG_FORCELOOP   (1 << 1)

◆ CHANNELFLAG_FULLVOLUME

#define CHANNELFLAG_FULLVOLUME   (1 << 4)

◆ CHANNELFLAG_LOCALSOUND

#define CHANNELFLAG_LOCALSOUND   (1 << 2)

◆ CHANNELFLAG_NONE

#define CHANNELFLAG_NONE   0

Definition at line 37 of file sound.h.

Referenced by CL_ParseStartSoundPacket(), and S_StartSound().

◆ CHANNELFLAG_PAUSED

#define CHANNELFLAG_PAUSED   (1 << 3)

◆ CHANNELFLAG_RELIABLE

#define CHANNELFLAG_RELIABLE   (1 << 0)

Definition at line 38 of file sound.h.

Referenced by VM_CL_sound(), and VM_SV_sound().

◆ DEFAULT_SOUND_PACKET_ATTENUATION

#define DEFAULT_SOUND_PACKET_ATTENUATION   1.0

Definition at line 33 of file sound.h.

Referenced by CL_ParseStartSoundPacket(), SV_StartPointSound(), and SV_StartSound().

◆ DEFAULT_SOUND_PACKET_VOLUME

#define DEFAULT_SOUND_PACKET_VOLUME   255

Definition at line 32 of file sound.h.

Referenced by CL_ParseStartSoundPacket(), SV_StartPointSound(), and SV_StartSound().

◆ IS_CHAN

#define IS_CHAN ( n)
Value:
#define n(x, y)
#define IS_CHAN_SINGLE(n)
Definition sound.h:81
#define IS_CHAN_AUTO(n)
Definition sound.h:80

Definition at line 82 of file sound.h.

Referenced by SV_StartSound(), VM_CL_sound(), VM_getsoundtime(), and VM_SV_sound().

◆ IS_CHAN_AUTO

#define IS_CHAN_AUTO ( n)
Value:
#define CHAN_MIN_AUTO
Definition sound.h:76
#define CHAN_MAX_AUTO
Definition sound.h:77

Definition at line 80 of file sound.h.

◆ IS_CHAN_SINGLE

#define IS_CHAN_SINGLE ( n)
Value:
#define CHAN_MIN_SINGLE
Definition sound.h:78
#define CHAN_MAX_SINGLE
Definition sound.h:79

Definition at line 81 of file sound.h.

Referenced by S_StartSound_StartPosition_Flags(), and SND_PickChannel().

Function Documentation

◆ S_BlockSound()

void S_BlockSound ( void )

◆ S_ClearUsed()

void S_ClearUsed ( void )

Definition at line 996 of file snd_main.c.

997{
998 sfx_t *sfx;
999// sfx_t *sfxnext;
1000 unsigned int i;
1001
1002 // Start the ambient sounds and make them loop
1003 for (i = 0; i < sizeof (ambient_sfxs) / sizeof (ambient_sfxs[0]); i++)
1004 {
1005 // Precache it if it's not done (and pass false for levelsound because these are permanent)
1006 if (ambient_sfxs[i] == NULL)
1007 ambient_sfxs[i] = S_PrecacheSound (ambient_names[i], false, false);
1008 if (ambient_sfxs[i] != NULL)
1009 {
1013 channels[i].basevolume = 0.0f;
1015 }
1016 }
1017
1018 // Clear SFXFLAG_LEVELSOUND flag so that sounds not precached this level will be purged
1019 for (sfx = known_sfx; sfx != NULL; sfx = sfx->next)
1020 sfx->flags &= ~SFXFLAG_LEVELSOUND;
1021}
int i
#define NULL
Definition qtypes.h:12
static sfx_t * ambient_sfxs[2]
Definition snd_main.c:258
static sfx_t * known_sfx
Definition snd_main.c:147
channel_t channels[MAX_CHANNELS]
Definition snd_main.c:128
sfx_t * S_PrecacheSound(const char *name, qbool complain, qbool levelsound)
Definition snd_main.c:1048
static const char * ambient_names[2]
Definition snd_main.c:259
#define SFXFLAG_LEVELSOUND
the sfx is part of the server or client precache list for this level
Definition snd_main.h:61
#define SFXFLAG_MENUSOUND
not freed during level change (menu sounds, music, etc)
Definition snd_main.h:63
#define CHANNELFLAG_FORCELOOP
Definition sound.h:39
unsigned int flags
cf CHANNELFLAG_* defines
Definition snd_main.h:91
float basevolume
0-1 master volume
Definition snd_main.h:90
float basespeed
playback rate multiplier for pitch variation
Definition snd_main.h:98
struct sfx_s * sfx
pointer to sound sample being used
Definition snd_main.h:89
float mixspeed
these are often updated while mixer is running, glitching should be minimized (mismatched channel vol...
Definition snd_main.h:102
unsigned int flags
cf SFXFLAG_* defines
Definition snd_main.h:73

References ambient_names, ambient_sfxs, channel_t::basespeed, channel_t::basevolume, CHANNELFLAG_FORCELOOP, channels, channel_t::flags, sfx_t::flags, i, known_sfx, channel_t::mixspeed, NULL, S_PrecacheSound(), channel_t::sfx, SFXFLAG_LEVELSOUND, and SFXFLAG_MENUSOUND.

Referenced by CL_ParseServerInfo(), and QW_CL_RequestNextDownload().

◆ S_FindName()

sfx_t * S_FindName ( const char * name)

Definition at line 895 of file snd_main.c.

896{
897 sfx_t *sfx;
898
900 return NULL;
901
902 if(!strcmp(name, changevolume_sfx.name))
903 return &changevolume_sfx;
904
905 if (strlen (name) >= sizeof (sfx->name))
906 {
907 Con_Printf ("S_FindName: sound name too long (%s)\n", name);
908 return NULL;
909 }
910
911 // Look for this sound in the list of known sfx
912 // TODO: hash table search?
913 for (sfx = known_sfx; sfx != NULL; sfx = sfx->next)
914 if(!strcmp (sfx->name, name))
915 return sfx;
916
917 // check for # in the beginning, try lookup by soundindex
918 if (name[0] == '#' && name[1])
919 {
920 int soundindex = atoi(name + 1);
921 if (soundindex > 0 && soundindex < MAX_SOUNDS)
922 if (cl.sound_precache[soundindex]->name[0])
923 return cl.sound_precache[soundindex];
924 }
925
926 // Add a sfx_t struct for this sound
927 sfx = (sfx_t *)Mem_Alloc (snd_mempool, sizeof (*sfx));
928 memset (sfx, 0, sizeof(*sfx));
929 dp_strlcpy (sfx->name, name, sizeof (sfx->name));
930 sfx->memsize = sizeof(*sfx);
931 sfx->next = known_sfx;
932 known_sfx = sfx;
933
934 return sfx;
935}
client_state_t cl
Definition cl_main.c:117
#define dp_strlcpy(dst, src, dsize)
Definition common.h:303
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
const GLchar * name
Definition glquake.h:601
float strlen(string s)
#define MAX_SOUNDS
max number of sounds loaded at once
Definition qdefs.h:107
mempool_t * snd_mempool
Definition snd_main.c:144
sfx_t changevolume_sfx
Definition snd_main.c:894
cvar_t snd_initialized
Definition snd_main.c:167
struct sfx_s * sound_precache[MAX_SOUNDS]
Definition client.h:889
int integer
Definition cvar.h:73
char name[MAX_QPATH]
Definition snd_main.h:68
#define Mem_Alloc(pool, size)
Definition zone.h:92

References changevolume_sfx, cl, Con_Printf(), dp_strlcpy, cvar_t::integer, known_sfx, MAX_SOUNDS, Mem_Alloc, name, sfx_t::name, NULL, snd_initialized, snd_mempool, client_state_t::sound_precache, and strlen().

Referenced by S_PrecacheSound(), S_SoundLength(), VM_CL_ambientsound(), VM_CL_pointsound(), and VM_CL_sound().

◆ S_GetChannelPosition()

float S_GetChannelPosition ( unsigned int ch_ind)

Definition at line 1773 of file snd_main.c.

1774{
1775 // note: this is NOT accurate yet
1776 double s;
1777 channel_t *ch = &channels[ch_ind];
1778 sfx_t *sfx = ch->sfx;
1779 if (!sfx)
1780 return -1;
1781
1782 s = ch->position / sfx->format.speed;
1783 /*
1784 if(!snd_usethreadedmixing)
1785 s += _snd_mixahead.value;
1786 */
1787 return (float)s;
1788}
double position
updated ONLY by mixer position in sfx, starts at 0, loops or stops at sfx->total_length
Definition snd_main.h:108

References channels, channel_t::position, and channel_t::sfx.

Referenced by CDAudio_GetPosition(), and S_GetEntChannelPosition().

◆ S_GetEntChannelPosition()

float S_GetEntChannelPosition ( int entnum,
int entchannel )

Definition at line 1790 of file snd_main.c.

1791{
1792 channel_t *ch;
1793 unsigned int i;
1794
1795 for (i = 0; i < total_channels; i++)
1796 {
1797 ch = &channels[i];
1798 if (ch->entnum == entnum && ch->entchannel == entchannel)
1799 return S_GetChannelPosition(i);
1800 }
1801 return -1; // no playing sound in this channel
1802}
float entnum
float S_GetChannelPosition(unsigned int ch_ind)
Definition snd_main.c:1773
unsigned int total_channels
Definition snd_main.c:129
int entchannel
which channel id on the entity
Definition snd_main.h:93
int entnum
makes sound follow entity origin (allows replacing interrupting existing sound on same id)
Definition snd_main.h:92

References channels, channel_t::entchannel, channel_t::entnum, entnum, i, S_GetChannelPosition(), and total_channels.

Referenced by VM_getsoundtime().

◆ S_GetSoundChannels()

int S_GetSoundChannels ( void )

Definition at line 382 of file snd_main.c.

383{
385}
snd_ringbuffer_t * snd_renderbuffer
Definition snd_main.c:131
unsigned short channels
Definition snd_main.h:34
snd_format_t format
Definition snd_main.h:47

References snd_format_t::channels, snd_ringbuffer_t::format, and snd_renderbuffer.

Referenced by XMP_LoadModFile().

◆ S_GetSoundRate()

int S_GetSoundRate ( void )

Definition at line 377 of file snd_main.c.

378{
380}
unsigned int speed
Definition snd_main.h:32

References snd_ringbuffer_t::format, snd_renderbuffer, and snd_format_t::speed.

Referenced by S_SoundLength(), and XMP_LoadModFile().

◆ S_GetSoundWidth()

int S_GetSoundWidth ( void )

Definition at line 387 of file snd_main.c.

388{
390}
unsigned short width
Definition snd_main.h:33

References snd_ringbuffer_t::format, snd_renderbuffer, and snd_format_t::width.

Referenced by XMP_LoadModFile().

◆ S_Init()

void S_Init ( void )

Definition at line 706 of file snd_main.c.

707{
752
755
765
773
776
779
780// COMMANDLINEOPTION: Sound: -nosound disables sound (including CD audio)
781 if (Sys_CheckParm("-nosound"))
782 {
783 // dummy out Play and Play2 because mods stuffcmd that
784 Cmd_AddCommand(CF_CLIENT, "play", Cmd_NoOperation_f, "does nothing because -nosound was specified");
785 Cmd_AddCommand(CF_CLIENT, "play2", Cmd_NoOperation_f, "does nothing because -nosound was specified");
786 return;
787 }
788
789 snd_mempool = Mem_AllocPool("sound", 0, NULL);
790
791// COMMANDLINEOPTION: Sound: -simsound runs sound mixing but with no output
792 if (Sys_CheckParm("-simsound"))
793 simsound = true;
794
795 Cmd_AddCommand(CF_CLIENT, "play", S_Play_f, "play a sound at your current location (not heard by anyone else)");
796 Cmd_AddCommand(CF_CLIENT, "play2", S_Play2_f, "play a sound globally throughout the level (not heard by anyone else)");
797 Cmd_AddCommand(CF_CLIENT, "playvol", S_PlayVol_f, "play a sound at the specified volume level at your current location (not heard by anyone else)");
798 Cmd_AddCommand(CF_CLIENT, "stopsound", S_StopAllSounds_f, "silence");
799 Cmd_AddCommand(CF_CLIENT, "pausesound", S_PauseSound_f, "temporary silence");
800 Cmd_AddCommand(CF_CLIENT, "soundlist", S_SoundList_f, "list loaded sounds");
801 Cmd_AddCommand(CF_CLIENT, "soundinfo", S_SoundInfo_f, "print sound system information (such as channels and speed)");
802 Cmd_AddCommand(CF_CLIENT, "snd_restart", S_Restart_f, "restart sound system");
803 Cmd_AddCommand(CF_CLIENT, "snd_unloadallsounds", S_UnloadAllSounds_f, "unload all sound files");
804
815 Cvar_RegisterVariable(&snd_swapstereo); // for people with backwards sound wiring
818
820
821 known_sfx = NULL;
822
824 memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
825
827#ifdef USEXMP
829#endif
830
831 CDAudio_Init();
832}
#define NUM_AMBIENTS
Definition bspfile.h:307
int CDAudio_Init(void)
Definition cd_shared.c:544
void Cmd_AddCommand(unsigned flags, const char *cmd_name, xcommand_t function, const char *description)
called by the init functions of other parts of the program to register commands and functions to call...
Definition cmd.c:1661
void Cmd_NoOperation_f(cmd_state_t *cmd)
Definition cmd.c:2240
#define CF_CLIENT
cvar/command that only the client can change/execute
Definition cmd.h:48
void Cvar_SetValueQuick(cvar_t *var, float value)
Definition cvar.c:473
void Cvar_RegisterVariable(cvar_t *variable)
registers a cvar that already has the name, string, and optionally the archive elements set.
Definition cvar.c:599
#define MAX_DYNAMIC_CHANNELS
Definition qdefs.h:146
#define MAX_CHANNELS
Definition qdefs.h:147
cvar_t snd_csqcchannel6volume
Definition snd_main.c:226
cvar_t snd_spatialization_max
Definition snd_main.c:184
static void S_PauseSound_f(cmd_state_t *cmd)
Definition snd_main.c:368
cvar_t snd_channel6volume
Definition snd_main.c:234
cvar_t snd_csqcchannel2volume
Definition snd_main.c:222
cvar_t snd_spatialization_min
Definition snd_main.c:183
static void S_SoundInfo_f(cmd_state_t *cmd)
Definition snd_main.c:353
cvar_t snd_attenuation_decibel
Definition snd_main.c:180
cvar_t snd_channellayout
Definition snd_main.c:170
static cvar_t snd_startloopingsounds
Definition snd_main.c:250
cvar_t snd_playerchannel2volume
Definition snd_main.c:206
cvar_t snd_entchannel3volume
Definition snd_main.c:199
cvar_t snd_attenuation_exponent
Definition snd_main.c:179
cvar_t snd_bufferlength
Definition snd_main.c:248
cvar_t snd_playerchannel1volume
Definition snd_main.c:205
cvar_t snd_csqcchannel4volume
Definition snd_main.c:224
static cvar_t snd_identicalsoundrandomization_tics
Definition snd_main.c:255
static cvar_t nosound
Definition snd_main.c:237
cvar_t snd_spatialization_min_radius
Definition snd_main.c:181
cvar_t snd_entchannel6volume
Definition snd_main.c:202
cvar_t snd_entchannel2volume
Definition snd_main.c:198
cvar_t snd_entchannel5volume
Definition snd_main.c:201
cvar_t snd_swapstereo
Definition snd_main.c:191
cvar_t snd_waterfx
Definition snd_main.c:173
cvar_t snd_mutewhenidle
Definition snd_main.c:193
cvar_t bgmvolume
Definition snd_main.c:165
qbool simsound
If simsound is true, the sound card is not initialized and no sound is submitted to it.
Definition snd_main.c:149
cvar_t snd_channel4volume
Definition snd_main.c:232
static cvar_t ambient_level
Definition snd_main.c:239
void S_StopAllSounds_f(cmd_state_t *cmd)
Definition snd_main.c:1743
cvar_t snd_entchannel7volume
Definition snd_main.c:203
cvar_t snd_staticvolume
Definition snd_main.c:177
cvar_t snd_worldchannel5volume
Definition snd_main.c:217
cvar_t snd_spatialization_power
Definition snd_main.c:185
static cvar_t snd_speed
Definition snd_main.c:245
static cvar_t snd_startnonloopingsounds
Definition snd_main.c:251
cvar_t snd_worldchannel3volume
Definition snd_main.c:215
cvar_t snd_playerchannel6volume
Definition snd_main.c:210
static cvar_t snd_identicalsoundrandomization_time
Definition snd_main.c:254
cvar_t snd_playerchannel4volume
Definition snd_main.c:208
cvar_t snd_streaming
Definition snd_main.c:171
cvar_t snd_csqcchannel0volume
Definition snd_main.c:220
cvar_t snd_channel3volume
Definition snd_main.c:231
cvar_t snd_csqcchannel1volume
Definition snd_main.c:221
cvar_t snd_soundradius
Definition snd_main.c:178
static void S_Play2_f(cmd_state_t *cmd)
Definition snd_main.c:311
cvar_t snd_playerchannel7volume
Definition snd_main.c:211
static cvar_t snd_channels
Definition snd_main.c:247
cvar_t snd_playerchannel0volume
Definition snd_main.c:204
cvar_t snd_maxchannelvolume
Definition snd_main.c:192
cvar_t snd_csqcchannel3volume
Definition snd_main.c:223
static cvar_t snd_precache
Definition snd_main.c:238
cvar_t snd_csqcchannel5volume
Definition snd_main.c:225
cvar_t snd_spatialization_prologic
Definition snd_main.c:187
cvar_t mastervolume
Definition snd_main.c:176
cvar_t snd_worldchannel7volume
Definition snd_main.c:219
cvar_t snd_playerchannel5volume
Definition snd_main.c:209
cvar_t snd_csqcchannel7volume
Definition snd_main.c:227
cvar_t snd_playerchannel3volume
Definition snd_main.c:207
cvar_t snd_spatialization_control
Definition snd_main.c:186
cvar_t snd_channel7volume
Definition snd_main.c:235
static cvar_t snd_show
Definition snd_main.c:241
cvar_t snd_worldchannel4volume
Definition snd_main.c:216
cvar_t snd_channel5volume
Definition snd_main.c:233
static void S_Play_f(cmd_state_t *cmd)
Definition snd_main.c:306
static cvar_t ambient_fade
Definition snd_main.c:240
cvar_t snd_channel1volume
Definition snd_main.c:229
void S_UnloadAllSounds_f(cmd_state_t *cmd)
Definition snd_main.c:864
cvar_t snd_channel0volume
Definition snd_main.c:228
cvar_t snd_entchannel4volume
Definition snd_main.c:200
static void S_SoundList_f(cmd_state_t *cmd)
Definition snd_main.c:321
cvar_t snd_spatialization_prologic_frontangle
Definition snd_main.c:188
static cvar_t snd_width
Definition snd_main.c:246
static void S_PlayVol_f(cmd_state_t *cmd)
Definition snd_main.c:316
cvar_t snd_channel2volume
Definition snd_main.c:230
cvar_t snd_entchannel1volume
Definition snd_main.c:197
cvar_t snd_worldchannel0volume
Definition snd_main.c:212
cvar_t snd_softclip
Definition snd_main.c:194
cvar_t snd_streaming_length
Definition snd_main.c:172
cvar_t snd_entchannel0volume
Definition snd_main.c:196
cvar_t snd_spatialization_occlusion
Definition snd_main.c:189
cvar_t snd_worldchannel2volume
Definition snd_main.c:214
cvar_t snd_worldchannel1volume
Definition snd_main.c:213
cvar_t snd_worldchannel6volume
Definition snd_main.c:218
cvar_t volume
Definition snd_main.c:166
cvar_t _snd_mixahead
Definition snd_main.c:190
cvar_t snd_spatialization_max_radius
Definition snd_main.c:182
static void S_Restart_f(cmd_state_t *cmd)
Definition snd_main.c:687
qbool OGG_OpenLibrary(void)
Definition snd_ogg.c:267
qbool XMP_OpenLibrary(void)
Definition snd_xmp.c:349
int Sys_CheckParm(const char *parm)
Definition sys_shared.c:327
#define Mem_AllocPool(name, flags, parent)
Definition zone.h:104

References _snd_mixahead, ambient_fade, ambient_level, bgmvolume, CDAudio_Init(), CF_CLIENT, channels, Cmd_AddCommand(), Cmd_NoOperation_f(), Cvar_RegisterVariable(), Cvar_SetValueQuick(), known_sfx, mastervolume, MAX_CHANNELS, MAX_DYNAMIC_CHANNELS, Mem_AllocPool, nosound, NULL, NUM_AMBIENTS, OGG_OpenLibrary(), S_PauseSound_f(), S_Play2_f(), S_Play_f(), S_PlayVol_f(), S_Restart_f(), S_SoundInfo_f(), S_SoundList_f(), S_StopAllSounds_f(), S_UnloadAllSounds_f(), simsound, snd_attenuation_decibel, snd_attenuation_exponent, snd_bufferlength, snd_channel0volume, snd_channel1volume, snd_channel2volume, snd_channel3volume, snd_channel4volume, snd_channel5volume, snd_channel6volume, snd_channel7volume, snd_channellayout, snd_channels, snd_csqcchannel0volume, snd_csqcchannel1volume, snd_csqcchannel2volume, snd_csqcchannel3volume, snd_csqcchannel4volume, snd_csqcchannel5volume, snd_csqcchannel6volume, snd_csqcchannel7volume, snd_entchannel0volume, snd_entchannel1volume, snd_entchannel2volume, snd_entchannel3volume, snd_entchannel4volume, snd_entchannel5volume, snd_entchannel6volume, snd_entchannel7volume, snd_identicalsoundrandomization_tics, snd_identicalsoundrandomization_time, snd_initialized, snd_maxchannelvolume, snd_mempool, snd_mutewhenidle, snd_playerchannel0volume, snd_playerchannel1volume, snd_playerchannel2volume, snd_playerchannel3volume, snd_playerchannel4volume, snd_playerchannel5volume, snd_playerchannel6volume, snd_playerchannel7volume, snd_precache, snd_show, snd_softclip, snd_soundradius, snd_spatialization_control, snd_spatialization_max, snd_spatialization_max_radius, snd_spatialization_min, snd_spatialization_min_radius, snd_spatialization_occlusion, snd_spatialization_power, snd_spatialization_prologic, snd_spatialization_prologic_frontangle, snd_speed, snd_startloopingsounds, snd_startnonloopingsounds, snd_staticvolume, snd_streaming, snd_streaming_length, snd_swapstereo, snd_waterfx, snd_width, snd_worldchannel0volume, snd_worldchannel1volume, snd_worldchannel2volume, snd_worldchannel3volume, snd_worldchannel4volume, snd_worldchannel5volume, snd_worldchannel6volume, snd_worldchannel7volume, Sys_CheckParm(), total_channels, volume, and XMP_OpenLibrary().

Referenced by CL_Init().

◆ S_IsSoundPrecached()

qbool S_IsSoundPrecached ( const sfx_t * sfx)

Definition at line 1105 of file snd_main.c.

1106{
1107 return (sfx != NULL && sfx->fetcher != NULL) || (sfx == &changevolume_sfx);
1108}

References changevolume_sfx, and NULL.

Referenced by CL_BeginDownloads().

◆ S_LocalSound()

◆ S_LocalSoundEx()

qbool S_LocalSoundEx ( const char * s,
int chan,
float fvol )

Definition at line 2217 of file snd_main.c.

2218{
2219 sfx_t *sfx;
2220 int ch_ind;
2221
2223 return true;
2224
2225 sfx = S_PrecacheSound (sound, true, false);
2226 if (!sfx)
2227 {
2228 Con_Printf("S_LocalSound: can't precache %s\n", sound);
2229 return false;
2230 }
2231
2232 // menu sounds must not be freed on level change
2233 sfx->flags |= SFXFLAG_MENUSOUND;
2234
2235 // fun fact: in Quake 1, this used -1 "replace any entity channel",
2236 // which we no longer support anyway
2237 // changed by Black in r4297 "Changed S_LocalSound to play multiple sounds at a time."
2238 ch_ind = S_StartSound (cl.viewentity, chan, sfx, vec3_origin, fvol, 0);
2239 if (ch_ind < 0)
2240 return false;
2241
2243 return true;
2244}
vec3_t vec3_origin
Definition mathlib.c:26
int S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
S_StartSound returns the channel index, or -1 if an error occurred.
Definition snd_main.c:1643
#define CHANNELFLAG_LOCALSOUND
Definition sound.h:40

References CHANNELFLAG_LOCALSOUND, channels, cl, Con_Printf(), channel_t::flags, cvar_t::integer, nosound, S_PrecacheSound(), S_StartSound(), SFXFLAG_MENUSOUND, snd_initialized, vec3_origin, and client_state_t::viewentity.

Referenced by S_LocalSound(), and VM_localsound().

◆ S_PauseGameSounds()

void S_PauseGameSounds ( qbool toggle)

Definition at line 1749 of file snd_main.c.

1750{
1751 unsigned int i;
1752
1753 for (i = 0; i < total_channels; i++)
1754 {
1755 channel_t *ch;
1756
1757 ch = &channels[i];
1758 if (ch->sfx != NULL && ! (ch->flags & CHANNELFLAG_LOCALSOUND))
1760 }
1761}
qbool S_SetChannelFlag(unsigned int ch_ind, unsigned int flag, qbool value)
Definition snd_main.c:1679
#define CHANNELFLAG_PAUSED
Definition sound.h:41

References CHANNELFLAG_LOCALSOUND, CHANNELFLAG_PAUSED, channels, channel_t::flags, i, NULL, S_SetChannelFlag(), channel_t::sfx, and total_channels.

Referenced by CL_ParseServerMessage(), and S_PauseSound_f().

◆ S_PrecacheSound()

sfx_t * S_PrecacheSound ( const char * sample,
qbool complain,
qbool levelsound )

Definition at line 1048 of file snd_main.c.

1049{
1050 sfx_t *sfx;
1051
1053 return NULL;
1054
1055 if (name == NULL || name[0] == 0)
1056 return NULL;
1057
1058 sfx = S_FindName (name);
1059
1060 if (sfx == NULL)
1061 return NULL;
1062
1063 // clear the FILEMISSING flag so that S_LoadSound will try again on a
1064 // previously missing file
1065 sfx->flags &= ~ SFXFLAG_FILEMISSING;
1066
1067 // set a flag to indicate this has been precached for this level or permanently
1068 if (levelsound)
1069 sfx->flags |= SFXFLAG_LEVELSOUND;
1070 else
1071 sfx->flags |= SFXFLAG_MENUSOUND;
1072
1074 S_LoadSound(sfx, complain);
1075
1076 return sfx;
1077}
sfx_t * S_FindName(const char *name)
Definition snd_main.c:895
qbool S_LoadSound(struct sfx_s *sfx, qbool complain)

References cvar_t::integer, name, nosound, NULL, S_FindName(), S_LoadSound(), SFXFLAG_LEVELSOUND, SFXFLAG_MENUSOUND, snd_initialized, and snd_precache.

Referenced by CDAudio_Play_byName(), CL_BeginDownloads(), CL_ParseServerInfo(), CL_ParseServerMessage(), dpvsimpledecode_open(), jam_open(), LibAvW_OpenVideo(), QW_CL_RequestNextDownload(), S_ClearUsed(), S_LocalSoundEx(), S_Play_Common(), and VM_precache_sound().

◆ S_PurgeUnused()

void S_PurgeUnused ( void )

Definition at line 1028 of file snd_main.c.

1029{
1030 sfx_t *sfx;
1031 sfx_t *sfxnext;
1032
1033 // Free all not-precached per-level sfx
1034 for (sfx = known_sfx;sfx;sfx = sfxnext)
1035 {
1036 sfxnext = sfx->next;
1037 if (!(sfx->flags & (SFXFLAG_LEVELSOUND | SFXFLAG_MENUSOUND)))
1038 S_FreeSfx (sfx, false);
1039 }
1040}
void S_FreeSfx(sfx_t *sfx, qbool force)
Definition snd_main.c:943

References known_sfx, S_FreeSfx(), SFXFLAG_LEVELSOUND, and SFXFLAG_MENUSOUND.

Referenced by CL_SignonReply().

◆ S_SetChannelFlag()

qbool S_SetChannelFlag ( unsigned int ch_ind,
unsigned int flag,
qbool value )

Definition at line 1679 of file snd_main.c.

1680{
1681 if (ch_ind >= total_channels)
1682 return false;
1683
1684 if (flag != CHANNELFLAG_FORCELOOP &&
1685 flag != CHANNELFLAG_PAUSED &&
1686 flag != CHANNELFLAG_FULLVOLUME &&
1687 flag != CHANNELFLAG_LOCALSOUND)
1688 return false;
1689
1690 if (value)
1691 channels[ch_ind].flags |= flag;
1692 else
1693 channels[ch_ind].flags &= ~flag;
1694
1695 return true;
1696}
GLsizei const GLfloat * value
Definition glquake.h:740
#define CHANNELFLAG_FULLVOLUME
Definition sound.h:42

References CHANNELFLAG_FORCELOOP, CHANNELFLAG_FULLVOLUME, CHANNELFLAG_LOCALSOUND, CHANNELFLAG_PAUSED, channels, channel_t::flags, total_channels, and value.

Referenced by CDAudio_Pause(), CDAudio_Resume(), S_PauseGameSounds(), and S_StartSound_StartPosition_Flags().

◆ S_SetChannelSpeed()

void S_SetChannelSpeed ( unsigned int ch_ind,
float fspeed )

Definition at line 1768 of file snd_main.c.

1769{
1770 channels[ch_ind].basespeed = fspeed;
1771}

References channel_t::basespeed, and channels.

Referenced by S_PlaySfxOnChannel(), and S_StartSound_StartPosition_Flags().

◆ S_SetChannelVolume()

void S_SetChannelVolume ( unsigned int ch_ind,
float fvol )

Definition at line 1763 of file snd_main.c.

1764{
1765 channels[ch_ind].basevolume = fvol;
1766}

References channel_t::basevolume, and channels.

Referenced by CDAudio_SetVolume(), S_PlaySfxOnChannel(), and S_StartSound_StartPosition_Flags().

◆ S_Shutdown()

void S_Shutdown ( void )

Definition at line 668 of file snd_main.c.

669{
670 if (snd_renderbuffer == NULL)
671 return;
672
674
676
677 if (simsound)
678 {
682 }
683 else
685}
void CDAudio_Shutdown(void)
Definition cd_shared.c:590
static unsigned int oldpaintedtime
Definition snd_main.c:133
void SndSys_Shutdown(void)
Stop the sound card, delete "snd_renderbuffer" and free its other resources.
Definition snd_sdl.c:174
unsigned char * ring
Definition snd_main.h:48
unsigned int endframe
index of the first EMPTY frame in the "ring" buffer may be smaller than startframe if the "ring" buff...
Definition snd_main.h:55
#define Mem_Free(mem)
Definition zone.h:96

References CDAudio_Shutdown(), snd_ringbuffer_t::endframe, Mem_Free, NULL, oldpaintedtime, snd_ringbuffer_t::ring, simsound, snd_renderbuffer, and SndSys_Shutdown().

Referenced by S_Restart_f(), and S_Terminate().

◆ S_SoundLength()

float S_SoundLength ( const char * name)

Definition at line 1085 of file snd_main.c.

1086{
1087 sfx_t *sfx;
1088
1090 return -1;
1091 if (name == NULL || name[0] == 0)
1092 return -1;
1093
1094 sfx = S_FindName(name);
1095 if (sfx == NULL)
1096 return -1;
1097 return sfx->total_length / (float) S_GetSoundRate();
1098}
precision highp float
Definition shader_glsl.h:53
int S_GetSoundRate(void)
Definition snd_main.c:377

References float, cvar_t::integer, name, NULL, S_FindName(), S_GetSoundRate(), and snd_initialized.

Referenced by VM_soundlength().

◆ S_StartSound()

int S_StartSound ( int entnum,
int entchannel,
sfx_t * sfx,
vec3_t origin,
float fvol,
float attenuation )

S_StartSound returns the channel index, or -1 if an error occurred.

Definition at line 1643 of file snd_main.c.

1644{
1645 return S_StartSound_StartPosition_Flags(entnum, entchannel, sfx, origin, fvol, attenuation, 0, CHANNELFLAG_NONE, 1.0f);
1646}
vector origin
int S_StartSound_StartPosition_Flags(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float startposition, int flags, float fspeed)
Definition snd_main.c:1571
#define CHANNELFLAG_NONE
Definition sound.h:37

References CHANNELFLAG_NONE, entnum, origin, and S_StartSound_StartPosition_Flags().

Referenced by CL_ParseTempEntity(), dpvsimpledecode_open(), jam_open(), libavw_decodeframe(), S_LocalSoundEx(), S_Play_Common(), VM_CL_pointsound(), VM_CL_te_explosion(), VM_CL_te_explosion2(), VM_CL_te_explosionquad(), VM_CL_te_gunshot(), VM_CL_te_gunshotquad(), VM_CL_te_knightspike(), VM_CL_te_spike(), VM_CL_te_spikequad(), VM_CL_te_superspike(), VM_CL_te_superspikequad(), VM_CL_te_tarexplosion(), and VM_CL_te_wizspike().

◆ S_StartSound_StartPosition_Flags()

int S_StartSound_StartPosition_Flags ( int entnum,
int entchannel,
sfx_t * sfx,
vec3_t origin,
float fvol,
float attenuation,
float startposition,
int flags,
float fspeed )

Definition at line 1571 of file snd_main.c.

1572{
1573 channel_t *target_chan, *check, *ch;
1574 int ch_idx, startpos, i;
1575
1576 if (snd_renderbuffer == NULL || sfx == NULL || nosound.integer)
1577 return -1;
1578
1579 if(sfx == &changevolume_sfx)
1580 {
1581 if (!IS_CHAN_SINGLE(entchannel))
1582 return -1;
1583 for (ch_idx=NUM_AMBIENTS ; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS ; ch_idx++)
1584 {
1585 ch = &channels[ch_idx];
1586 if (ch->entnum == entnum && ch->entchannel == entchannel)
1587 {
1588 S_SetChannelVolume(ch_idx, fvol);
1589 S_SetChannelSpeed(ch_idx, fspeed);
1590 for(i = 1; i > 0 && (i <= flags || i <= (int) channels[ch_idx].flags); i <<= 1)
1591 if((flags ^ channels[ch_idx].flags) & i)
1592 S_SetChannelFlag(ch_idx, i, (flags & i) != 0);
1593 ch->distfade = attenuation / snd_soundradius.value;
1594 SND_Spatialize(ch, false);
1595 return ch_idx;
1596 }
1597 }
1598 return -1;
1599 }
1600
1601 if (sfx->fetcher == NULL)
1602 return -1;
1603
1604 // Pick a channel to play on
1605 target_chan = SND_PickChannel(entnum, entchannel);
1606 if (!target_chan)
1607 return -1;
1608
1609 // if an identical sound has also been started this frame, offset the pos
1610 // a bit to keep it from just making the first one louder
1611 check = &channels[NUM_AMBIENTS];
1612 startpos = (int)(startposition * sfx->format.speed);
1613 if (startpos == 0)
1614 {
1615 for (ch_idx=NUM_AMBIENTS ; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS ; ch_idx++, check++)
1616 {
1617 if (check == target_chan)
1618 continue;
1619 if (check->sfx == sfx && check->position == 0 && check->basespeed == fspeed)
1620 {
1621 // calculate max offset
1624 float maxticsdelta = ((cls.state == ca_connected) ? (maxtics * (cl.mtime[0] - cl.mtime[1])) : 0);
1625 float maxdelta = 0;
1626 if(maxticsdelta == 0 || fabs(maxticsdelta) > fabs(maxtime))
1627 maxdelta = maxtime;
1628 else
1629 maxdelta = fabs(maxticsdelta) * ((maxtime > 0) ? 1 : -1);
1630
1631 // use negative pos offset to delay this sound effect
1632 startpos = lhrandom(0, maxdelta * sfx->format.speed);
1633 break;
1634 }
1635 }
1636 }
1637
1638 S_PlaySfxOnChannel (sfx, target_chan, flags, origin, fvol, attenuation, false, entnum, entchannel, startpos, fspeed);
1639
1640 return (target_chan - channels);
1641}
client_static_t cls
Definition cl_main.c:116
@ ca_connected
Definition client.h:532
float flags
static int(ZEXPORT *qz_inflate)(z_stream *strm
#define lhrandom(MIN, MAX)
LadyHavoc: this function never returns exactly MIN or exactly MAX, because of a QuakeC bug in id1 whe...
Definition mathlib.h:48
float fabs(float f)
void S_SetChannelVolume(unsigned int ch_ind, float fvol)
Definition snd_main.c:1763
static void SND_Spatialize(channel_t *ch, qbool isstatic)
Definition snd_main.c:1503
void S_SetChannelSpeed(unsigned int ch_ind, float fspeed)
Definition snd_main.c:1768
static void S_PlaySfxOnChannel(sfx_t *sfx, channel_t *target_chan, unsigned int flags, vec3_t origin, float fvol, float attenuation, qbool isstatic, int entnum, int entchannel, int startpos, float fspeed)
Definition snd_main.c:1514
static channel_t * SND_PickChannel(int entnum, int entchannel)
Definition snd_main.c:1118
vec_t distfade
distance multiplier (attenuation/clipK)
Definition snd_main.h:95
double mtime[2]
Definition client.h:861
cactive_t state
Definition client.h:568
float value
Definition cvar.h:74

References channel_t::basespeed, ca_connected, changevolume_sfx, channels, cl, cls, channel_t::distfade, channel_t::entchannel, channel_t::entnum, entnum, fabs(), channel_t::flags, flags, i, int(), cvar_t::integer, IS_CHAN_SINGLE, lhrandom, MAX_DYNAMIC_CHANNELS, client_state_t::mtime, nosound, NULL, NUM_AMBIENTS, origin, channel_t::position, S_PlaySfxOnChannel(), S_SetChannelFlag(), S_SetChannelSpeed(), S_SetChannelVolume(), channel_t::sfx, snd_identicalsoundrandomization_tics, snd_identicalsoundrandomization_time, SND_PickChannel(), snd_renderbuffer, snd_soundradius, SND_Spatialize(), client_static_t::state, and cvar_t::value.

Referenced by CDAudio_Play_byName(), CL_ParseStartSoundPacket(), S_StartSound(), and VM_CL_sound().

◆ S_Startup()

void S_Startup ( void )

Definition at line 476 of file snd_main.c.

477{
478 snd_format_t chosen_fmt;
479 static snd_format_t prev_render_format = {0, 0, 0};
480 char* env;
481#if _MSC_VER >= 1400
482 size_t envlen;
483#endif
484 int i;
485
487 return;
488
489 // Get the starting sound format from the cvars
490 chosen_fmt.speed = snd_speed.integer;
491 chosen_fmt.width = snd_width.integer;
492 chosen_fmt.channels = snd_channels.integer;
493
494 // Check the environment variables to see if the player wants a particular sound format
495#if _MSC_VER >= 1400
496 _dupenv_s(&env, &envlen, "QUAKE_SOUND_CHANNELS");
497#else
498 env = getenv("QUAKE_SOUND_CHANNELS");
499#endif
500 if (env != NULL)
501 {
502 chosen_fmt.channels = atoi (env);
503#if _MSC_VER >= 1400
504 free(env);
505#endif
506 }
507#if _MSC_VER >= 1400
508 _dupenv_s(&env, &envlen, "QUAKE_SOUND_SPEED");
509#else
510 env = getenv("QUAKE_SOUND_SPEED");
511#endif
512 if (env != NULL)
513 {
514 chosen_fmt.speed = atoi (env);
515#if _MSC_VER >= 1400
516 free(env);
517#endif
518 }
519#if _MSC_VER >= 1400
520 _dupenv_s(&env, &envlen, "QUAKE_SOUND_SAMPLEBITS");
521#else
522 env = getenv("QUAKE_SOUND_SAMPLEBITS");
523#endif
524 if (env != NULL)
525 {
526 chosen_fmt.width = atoi (env) / 8;
527#if _MSC_VER >= 1400
528 free(env);
529#endif
530 }
531
532 // Parse the command line to see if the player wants a particular sound format
533// COMMANDLINEOPTION: Sound: -sndquad sets sound output to 4 channel surround
534 if (Sys_CheckParm ("-sndquad") != 0)
535 {
536 chosen_fmt.channels = 4;
537 }
538// COMMANDLINEOPTION: Sound: -sndstereo sets sound output to stereo
539 else if (Sys_CheckParm ("-sndstereo") != 0)
540 {
541 chosen_fmt.channels = 2;
542 }
543// COMMANDLINEOPTION: Sound: -sndmono sets sound output to mono
544 else if (Sys_CheckParm ("-sndmono") != 0)
545 {
546 chosen_fmt.channels = 1;
547 }
548// COMMANDLINEOPTION: Sound: -sndspeed <hz> chooses sound output rate (supported values are 48000, 44100, 32000, 24000, 22050, 16000, 11025 (quake), 8000)
549 i = Sys_CheckParm ("-sndspeed");
550 if (0 < i && i < sys.argc - 1)
551 {
552 chosen_fmt.speed = atoi (sys.argv[i + 1]);
553 }
554// COMMANDLINEOPTION: Sound: -sndbits <bits> chooses 8 bit or 16 bit or 32bit float sound output
555 i = Sys_CheckParm ("-sndbits");
556 if (0 < i && i < sys.argc - 1)
557 {
558 chosen_fmt.width = atoi (sys.argv[i + 1]) / 8;
559 }
560
561#if 0
562 // LadyHavoc: now you can with the resampler...
563 // You can't change sound speed after start time (not yet supported)
564 if (prev_render_format.speed != 0)
565 {
566 if (chosen_fmt.speed != prev_render_format.speed)
567 {
568 Con_Printf("S_Startup: sound speed has changed! This is NOT supported yet. Falling back to previous speed (%u Hz)\n",
569 prev_render_format.speed);
570 chosen_fmt.speed = prev_render_format.speed;
571 }
572 }
573#endif
574
575 // Sanity checks
576 if (chosen_fmt.speed < SND_MIN_SPEED)
577 {
578 chosen_fmt.speed = SND_MIN_SPEED;
579 }
580 else if (chosen_fmt.speed > SND_MAX_SPEED)
581 {
582 chosen_fmt.speed = SND_MAX_SPEED;
583 }
584
585 if (chosen_fmt.width < SND_MIN_WIDTH)
586 {
587 chosen_fmt.width = SND_MIN_WIDTH;
588 }
589 else if (chosen_fmt.width == 3)
590 {
591 chosen_fmt.width = 4;
592 }
593 else if (chosen_fmt.width > SND_MAX_WIDTH)
594 {
595 chosen_fmt.width = SND_MAX_WIDTH;
596 }
597
598 if (chosen_fmt.channels < SND_MIN_CHANNELS)
599 {
600 chosen_fmt.channels = SND_MIN_CHANNELS;
601 }
602 else if (chosen_fmt.channels > SND_MAX_CHANNELS)
603 {
604 chosen_fmt.channels = SND_MAX_CHANNELS;
605 }
606
607 // create the sound buffer used for sumitting the samples to the plaform-dependent module
608 if (!simsound)
609 {
610 Con_Printf("S_Startup: initializing sound output format: %dHz, %d bit, %d channels...\n",
611 chosen_fmt.speed,
612 chosen_fmt.width,
613 chosen_fmt.channels);
614
615 if (!SndSys_Init(&chosen_fmt))
616 {
617 Con_Print("S_Startup: SndSys_Init failed.\n");
618 return;
619 }
620 }
621 else
622 {
623 snd_renderbuffer = Snd_CreateRingBuffer(&chosen_fmt, 0, NULL);
624 Con_Print ("S_Startup: simulating sound output\n");
625 }
626
627 memcpy(&prev_render_format, &snd_renderbuffer->format, sizeof(prev_render_format));
628 Con_Printf("Sound format: %dHz, %d channels, %d bits per sample\n",
629 chosen_fmt.speed, chosen_fmt.channels, chosen_fmt.width * 8);
630
631 // Update the cvars
632 if (snd_speed.integer != (int)chosen_fmt.speed)
633 Cvar_SetValueQuick(&snd_speed, chosen_fmt.speed);
634 if (snd_width.integer != chosen_fmt.width)
635 Cvar_SetValueQuick(&snd_width, chosen_fmt.width);
636 if (snd_channels.integer != chosen_fmt.channels)
638
641
643
644 // If the sound module has already run, add an extra time to make sure
645 // the sound time doesn't decrease, to not confuse playing SFXs
646 if (oldpaintedtime != 0)
647 {
648 // The extra time must be a multiple of the render buffer size
649 // to avoid modifying the current position in the buffer,
650 // some modules write directly to a shared (DMA) buffer
653 Con_Printf("S_Startup: extra sound time = %u\n", extrasoundtime);
654
656 }
657 else
658 extrasoundtime = 0;
661#ifdef CONFIG_VIDEO_CAPTURE
662 recording_sound = false;
663#endif
664
666}
int CDAudio_Startup(void)
Definition cd_shared.c:578
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
Definition console.c:1504
host_static_t host
Definition host.c:41
static unsigned int soundtime
Definition snd_main.c:132
static void S_SetChannelLayout(void)
Definition snd_main.c:395
#define SND_MAX_WIDTH
Definition snd_main.c:37
#define SND_MAX_CHANNELS
Definition snd_main.c:39
static unsigned int extrasoundtime
Definition snd_main.c:134
#define SND_MIN_CHANNELS
Definition snd_main.c:38
#define SND_MIN_SPEED
Definition snd_main.c:34
#define SND_MIN_WIDTH
Definition snd_main.c:36
static int current_channellayout_used
Definition snd_main.c:158
#define SND_MAX_SPEED
Definition snd_main.c:35
static double snd_starttime
Definition snd_main.c:135
snd_ringbuffer_t * Snd_CreateRingBuffer(const snd_format_t *format, unsigned int sampleframes, void *buffer)
If "buffer" is NULL, the function allocates one buffer of "sampleframes" sample frames itself (if "sa...
Definition snd_mem.c:43
qbool SndSys_Init(snd_format_t *fmt)
Create "snd_renderbuffer", attempting to use the chosen sound format, but accepting if the driver wan...
Definition snd_sdl.c:103
#define SND_CHANNELLAYOUT_AUTO
Definition snd_main.h:134
double realtime
the accumulated mainloop time since application started (with filtering), without any slowmo or clamp...
Definition host.h:46
unsigned int startframe
index of the first frame in the buffer if startframe == endframe, the bufffer is empty
Definition snd_main.h:52
unsigned int maxframes
max size (buffer size), in sample frames
Definition snd_main.h:49
int argc
Definition sys.h:146
const char ** argv
Definition sys.h:147
sys_t sys
Definition sys_shared.c:42

References sys_t::argc, sys_t::argv, CDAudio_Startup(), snd_format_t::channels, Con_Print(), Con_Printf(), current_channellayout_used, Cvar_SetValueQuick(), snd_ringbuffer_t::endframe, extrasoundtime, snd_ringbuffer_t::format, host, i, cvar_t::integer, snd_ringbuffer_t::maxframes, NULL, oldpaintedtime, host_static_t::realtime, S_SetChannelLayout(), simsound, SND_CHANNELLAYOUT_AUTO, snd_channels, Snd_CreateRingBuffer(), snd_initialized, SND_MAX_CHANNELS, SND_MAX_SPEED, SND_MAX_WIDTH, SND_MIN_CHANNELS, SND_MIN_SPEED, SND_MIN_WIDTH, snd_renderbuffer, snd_speed, snd_starttime, snd_width, SndSys_Init(), soundtime, snd_format_t::speed, snd_ringbuffer_t::startframe, sys, Sys_CheckParm(), and snd_format_t::width.

Referenced by Host_Init(), and S_Restart_f().

◆ S_StaticSound()

void S_StaticSound ( sfx_t * sfx,
vec3_t origin,
float fvol,
float attenuation )

Definition at line 1809 of file snd_main.c.

1810{
1811 channel_t *target_chan;
1812
1813 if (snd_renderbuffer == NULL || sfx == NULL || nosound.integer)
1814 return;
1815 if (!sfx->fetcher)
1816 {
1817 Con_Printf ("S_StaticSound: \"%s\" hasn't been precached\n", sfx->name);
1818 return;
1819 }
1820
1822 {
1823 Con_Print("S_StaticSound: total_channels == MAX_CHANNELS\n");
1824 return;
1825 }
1826
1827 target_chan = &channels[total_channels++];
1828 S_PlaySfxOnChannel (sfx, target_chan, CHANNELFLAG_FORCELOOP, origin, fvol, attenuation, true, 0, 0, 0, 1.0f);
1829}

References CHANNELFLAG_FORCELOOP, channels, Con_Print(), Con_Printf(), cvar_t::integer, MAX_CHANNELS, nosound, NULL, origin, S_PlaySfxOnChannel(), snd_renderbuffer, and total_channels.

Referenced by CL_ParseStaticSound(), and VM_CL_ambientsound().

◆ S_StopAllSounds()

void S_StopAllSounds ( void )

Definition at line 1710 of file snd_main.c.

1711{
1712 unsigned int i;
1713
1714 // TOCHECK: is this test necessary?
1715 if (snd_renderbuffer == NULL)
1716 return;
1717
1718 // stop CD audio because it may be using a faketrack
1719 CDAudio_Stop();
1720
1722 {
1723 int clear;
1724 size_t memsize;
1725
1726 for (i = 0; i < total_channels; i++)
1727 if (channels[i].sfx)
1728 S_StopChannel (i, false, false);
1729
1731 memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
1732
1733 // Mute the contents of the submittion buffer
1734 clear = (snd_renderbuffer->format.width == 1) ? 0x80 : 0;
1736 memset(snd_renderbuffer->ring, clear, memsize);
1737
1738 if (!simsound)
1740 }
1741}
void CDAudio_Stop(void)
Definition cd_shared.c:229
void S_StopChannel(unsigned int channel_ind, qbool lockmutex, qbool freesfx)
Definition snd_main.c:1648
qbool SndSys_LockRenderBuffer(void)
Get the exclusive lock on "snd_renderbuffer".
Definition snd_sdl.c:222
void SndSys_UnlockRenderBuffer(void)
Release the exclusive lock on "snd_renderbuffer".
Definition snd_sdl.c:236

References CDAudio_Stop(), channels, snd_format_t::channels, snd_ringbuffer_t::format, i, MAX_CHANNELS, MAX_DYNAMIC_CHANNELS, snd_ringbuffer_t::maxframes, NULL, NUM_AMBIENTS, snd_ringbuffer_t::ring, S_StopChannel(), simsound, snd_renderbuffer, SndSys_LockRenderBuffer(), SndSys_UnlockRenderBuffer(), total_channels, and snd_format_t::width.

Referenced by CL_ClearState(), CL_DisconnectEx(), CL_ParseServerInfo(), CL_Reconnect_f(), CL_Shutdown(), QW_CL_Changing_f(), S_StopAllSounds_f(), S_UnloadAllSounds_f(), SV_SpawnServer(), Sys_Error(), and Sys_HandleCrash().

◆ S_StopAllSounds_f()

void S_StopAllSounds_f ( struct cmd_state_s * cmd)

◆ S_StopChannel()

void S_StopChannel ( unsigned int channel_ind,
qbool lockmutex,
qbool freesfx )

Definition at line 1648 of file snd_main.c.

1649{
1650 channel_t *ch;
1651 sfx_t *sfx;
1652
1653 if (channel_ind >= total_channels)
1654 return;
1655
1656 // we have to lock an audio mutex to prevent crashes if an audio mixer
1657 // thread is currently mixing this channel
1658 // the SndSys_LockRenderBuffer function uses such a mutex in
1659 // threaded sound backends
1660 if (lockmutex && !simsound)
1662
1663 ch = &channels[channel_ind];
1664 sfx = ch->sfx;
1665 if (sfx != NULL)
1666 {
1667 if (sfx->fetcher != NULL && sfx->fetcher->stopchannel != NULL)
1668 sfx->fetcher->stopchannel(ch);
1669 ch->fetcher_data = NULL;
1670 ch->sfx = NULL;
1671 if (freesfx)
1672 S_FreeSfx(sfx, true);
1673 }
1674 if (lockmutex && !simsound)
1676}
void * fetcher_data
Per-channel data for the sound fetching function.
Definition snd_main.h:96

References channels, channel_t::fetcher_data, NULL, S_FreeSfx(), channel_t::sfx, simsound, SndSys_LockRenderBuffer(), SndSys_UnlockRenderBuffer(), and total_channels.

Referenced by CDAudio_Stop(), dpvsimpledecode_close(), jam_close(), libavw_close(), S_FreeSfx(), S_MixToBuffer(), S_PlaySfxOnChannel(), S_StopAllSounds(), S_StopSound(), and SND_PickChannel().

◆ S_StopSound()

void S_StopSound ( int entnum,
int entchannel )

Definition at line 1698 of file snd_main.c.

1699{
1700 unsigned int i;
1701
1702 for (i = 0; i < MAX_DYNAMIC_CHANNELS; i++)
1703 if (channels[i].entnum == entnum && channels[i].entchannel == entchannel)
1704 {
1705 S_StopChannel (i, true, false);
1706 return;
1707 }
1708}

References channels, entnum, i, MAX_DYNAMIC_CHANNELS, and S_StopChannel().

Referenced by CL_ParseServerMessage().

◆ S_Terminate()

void S_Terminate ( void )

Definition at line 842 of file snd_main.c.

843{
844 S_Shutdown ();
845#ifdef USEXMP
847#endif
849
850 // Free all SFXs
851 while (known_sfx != NULL)
852 S_FreeSfx (known_sfx, true);
853
856}
void S_Shutdown(void)
Definition snd_main.c:668
void OGG_CloseLibrary(void)
Definition snd_ogg.c:320
void XMP_CloseLibrary(void)
Definition snd_xmp.c:398
#define Mem_FreePool(pool)
Definition zone.h:105

References Cvar_SetValueQuick(), known_sfx, Mem_FreePool, NULL, OGG_CloseLibrary(), S_FreeSfx(), S_Shutdown(), snd_initialized, snd_mempool, and XMP_CloseLibrary().

Referenced by CL_Shutdown().

◆ S_UnblockSound()

void S_UnblockSound ( void )

◆ S_UnloadAllSounds_f()

void S_UnloadAllSounds_f ( struct cmd_state_s * cmd)

◆ S_Update()

void S_Update ( const matrix4x4_t * listenermatrix)

Definition at line 2061 of file snd_main.c.

2062{
2063 unsigned int i, j, k;
2064 channel_t *ch, *combine;
2065 matrix4x4_t rotatematrix;
2066
2068 return;
2069
2070 // enable/disable sound on focus gain/loss
2073 || cls.timedemo;
2074
2075 {
2076 double mindist_trans, maxdist_trans;
2077
2080
2082 {
2084
2085 if(spatialpower == 0)
2086 {
2088 mindist_trans = log(max(1, snd_spatialization_min_radius.value));
2089 maxdist_trans = log(max(1, snd_spatialization_max_radius.value));
2090 }
2091 else
2092 {
2096 }
2097
2098 if(mindist_trans - maxdist_trans == 0)
2099 {
2101 mindist_trans = snd_spatialization_min_radius.value;
2102 }
2103 else
2104 {
2105 spatialoffset = mindist_trans;
2106 spatialfactor = 1 / (maxdist_trans - mindist_trans);
2107 }
2108 }
2109 else
2111
2112 }
2113
2114 // If snd_swapstereo or snd_channellayout has changed, recompute the channel layout
2118
2121 if (cl.worldmodel && cl.worldmodel->brush.FatPVS && cl.worldmodel->brush.num_pvsclusterbytes && cl.worldmodel->brush.PointInLeaf)
2123 else
2124 {
2125 if(listener_pvs)
2126 {
2129 }
2131 }
2132
2133 // calculate the current matrices
2134 for (j = 0;j < SND_LISTENERS;j++)
2135 {
2136 Matrix4x4_CreateFromQuakeEntity(&rotatematrix, 0, 0, 0, 0, -snd_speakerlayout.listeners[j].yawangle, 0, 1);
2138 // I think this should now do this:
2139 // 1. create a rotation matrix for rotating by e.g. -90 degrees CCW
2140 // (note: the matrix will rotate the OBJECT, not the VIEWER, so its
2141 // angle has to be taken negative)
2142 // 2. create a transform which first rotates and moves its argument
2143 // into the player's view coordinates (using basematrix which is
2144 // an inverted "absolute" listener matrix), then applies the
2145 // rotation matrix for the ear
2146 // Isn't Matrix4x4_CreateFromQuakeEntity a bit misleading because this
2147 // does not actually refer to an entity?
2148 }
2149
2150 // update general area ambient sound sources
2152
2153 combine = NULL;
2154 R_TimeReport("audioprep");
2155
2156 // update spatialization for static and dynamic sounds
2160 for (i=NUM_AMBIENTS ; i<total_channels; i++, ch++)
2161 {
2162 if (!ch->sfx)
2163 continue;
2165
2166 // respatialize channel
2168
2169 // try to combine static sounds with a previous channel of the same
2170 // sound effect so we don't mix five torches every frame
2172 {
2173 // no need to merge silent channels
2174 for (j = 0;j < SND_LISTENERS;j++)
2175 if (ch->volume[j])
2176 break;
2177 if (j == SND_LISTENERS)
2178 continue;
2179 // if the last combine chosen isn't suitable, find a new one
2180 if (!(combine && combine != ch && combine->sfx == ch->sfx))
2181 {
2182 // search for one
2183 combine = NULL;
2184 for (j = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS;j < i;j++)
2185 {
2186 if (channels[j].sfx == ch->sfx)
2187 {
2188 combine = channels + j;
2189 break;
2190 }
2191 }
2192 }
2193 if (combine && combine != ch && combine->sfx == ch->sfx)
2194 {
2195 for (j = 0;j < SND_LISTENERS;j++)
2196 {
2197 combine->volume[j] += ch->volume[j];
2198 ch->volume[j] = 0;
2199 }
2200 }
2201 }
2202 for (k = 0;k < SND_LISTENERS;k++)
2203 if (ch->volume[k])
2204 break;
2205 if (k < SND_LISTENERS)
2207 }
2208 R_TimeReport("audiospatialize");
2209
2210 // debugging output
2211 if (snd_show.integer)
2212 Con_Printf("----(%u)----\n", cls.soundstats.mixedsounds);
2213
2215}
float log(float f)
#define max(A, B)
Definition mathlib.h:38
#define boolxor(a, b)
boolean XOR (why doesn't C have the ^^ operator for this purpose?)
Definition mathlib.h:60
void Matrix4x4_Concat(matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2)
Definition matrixlib.c:83
void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, double x, double y, double z, double pitch, double yaw, double roll, double scale)
Definition matrixlib.c:715
void Matrix4x4_Invert_Simple(matrix4x4_t *out, const matrix4x4_t *in1)
Definition matrixlib.c:422
void Matrix4x4_OriginFromMatrix(const matrix4x4_t *in, float *out)
Definition matrixlib.c:1792
float pow(float a, float b)
void R_TimeReport(const char *desc)
Definition r_stats.c:193
static float spatialmin
Definition snd_main.c:160
static bool current_swapstereo
Definition snd_main.c:156
cvar_t v_flipped
Definition gl_backend.c:20
static float spatialdiff
Definition snd_main.c:160
bool snd_blocked
When true, we submit silence to the audio device.
Definition snd_main.c:155
@ SPATIAL_NONE
Definition snd_main.c:161
@ SPATIAL_THRESH
Definition snd_main.c:161
@ SPATIAL_POW
Definition snd_main.c:161
@ SPATIAL_LOG
Definition snd_main.c:161
static int listener_pvsbytes
Definition snd_main.c:142
matrix4x4_t listener_matrix[SND_LISTENERS]
Definition snd_main.c:143
static unsigned char * listener_pvs
Definition snd_main.c:141
static int current_channellayout
Definition snd_main.c:157
static float spatialoffset
Definition snd_main.c:160
speakerlayout_t snd_speakerlayout
Definition snd_main.c:44
static void S_UpdateAmbientSounds(void)
Definition snd_main.c:1836
static float spatialfactor
Definition snd_main.c:160
matrix4x4_t listener_basematrix
Definition snd_main.c:140
vec3_t listener_origin
Definition snd_main.c:139
spatialmethod_t spatialmethod
Definition snd_main.c:162
static float spatialpower
Definition snd_main.c:160
static void S_PaintAndSubmit(void)
Definition snd_main.c:1895
#define SND_LISTENERS
Definition snd_main.h:84
float volume[SND_LISTENERS]
spatialized volume per speaker (mastervol * distanceattenuation * channelvolume cvars)
Definition snd_main.h:104
struct model_s * worldmodel
Definition client.h:934
cl_soundstats_t soundstats
Definition client.h:607
qbool timedemo
Definition client.h:589
float yawangle
Definition snd_main.h:203
listener_t listeners[SND_LISTENERS]
Definition snd_main.h:213
qbool vid_hidden
Definition vid_shared.c:74
qbool vid_activewindow
Definition vid_shared.c:77

References boolxor, channels, cl, cls, Con_Printf(), current_channellayout, current_swapstereo, i, cvar_t::integer, listener_basematrix, listener_matrix, listener_origin, listener_pvs, listener_pvsbytes, speakerlayout_t::listeners, log(), Matrix4x4_Concat(), Matrix4x4_CreateFromQuakeEntity(), Matrix4x4_Invert_Simple(), Matrix4x4_OriginFromMatrix(), max, MAX_DYNAMIC_CHANNELS, Mem_Free, cl_soundstats_t::mixedsounds, nosound, NULL, NUM_AMBIENTS, pow(), R_TimeReport(), S_PaintAndSubmit(), S_SetChannelLayout(), S_UpdateAmbientSounds(), channel_t::sfx, snd_blocked, snd_channellayout, SND_LISTENERS, snd_mempool, snd_mutewhenidle, snd_renderbuffer, snd_show, snd_spatialization_control, snd_spatialization_max, snd_spatialization_max_radius, snd_spatialization_min, snd_spatialization_min_radius, snd_spatialization_power, SND_Spatialize(), snd_speakerlayout, snd_swapstereo, client_static_t::soundstats, SPATIAL_LOG, SPATIAL_NONE, SPATIAL_POW, SPATIAL_THRESH, spatialdiff, spatialfactor, spatialmethod, spatialmin, spatialoffset, spatialpower, client_static_t::timedemo, total_channels, cl_soundstats_t::totalsounds, v_flipped, cvar_t::value, vid_activewindow, vid_hidden, channel_t::volume, client_state_t::worldmodel, and listener_t::yawangle.

Referenced by CL_Frame().

Variable Documentation

◆ bgmvolume

cvar_t bgmvolume
extern

Definition at line 165 of file snd_main.c.

165{CF_CLIENT | CF_ARCHIVE, "bgmvolume", "1", "volume of background music (such as CD music or replacement files such as sound/cdtracks/track002.ogg)"};
#define CF_ARCHIVE
cvar should have its set value saved to config.cfg and persist across sessions
Definition cmd.h:53

Referenced by CDAudio_Play_byName(), CDAudio_Update(), CL_ParseServerMessage(), M_Menu_Options_AdjustSliders(), M_Options_Draw(), and S_Init().

◆ snd_initialized

cvar_t snd_initialized
extern

Definition at line 167 of file snd_main.c.

167{CF_CLIENT | CF_READONLY, "snd_initialized", "0", "indicates the sound subsystem is active"};
#define CF_READONLY
cvar cannot be changed from the console or the command buffer, and is considered CF_PERSISTENT
Definition cmd.h:54

Referenced by CL_ParseServerMessage(), M_Options_Draw(), S_FindName(), S_Init(), S_LocalSoundEx(), S_PrecacheSound(), S_SoundLength(), S_Startup(), S_Terminate(), and VM_precache_sound().

◆ volume

cvar_t volume
extern

Definition at line 166 of file snd_main.c.

166{CF_CLIENT | CF_ARCHIVE, "volume", "0.7", "volume of sound effects"};

Referenced by M_Menu_Options_AdjustSliders(), M_Options_Draw(), S_Init(), S_UpdateAmbientSounds(), and SND_Spatialize_WithSfx().