26 #include "../client.h"
34 #define COMPARE_VERSION(major, minor, micro) \
35 (SDL_MIXER_MAJOR_VERSION > (major) || \
36 (SDL_MIXER_MAJOR_VERSION == (major) && SDL_MIXER_MINOR_VERSION > (minor)) || \
37 (SDL_MIXER_MAJOR_VERSION == (major) && SDL_MIXER_MINOR_VERSION == (minor) && \
38 SDL_MIXER_PATCHLEVEL >= (micro)))
72 if (snd_init && snd_init->
modified) {
111 if (j == MAX_CHANNELS)
153 for (
char const*
const* extension = soundExtensions; *extension; ++extension) {
155 Com_sprintf(pattern,
sizeof(pattern),
"sound/**.%s", *extension);
157 char const*
const fileWithPath =
filename + strlen(
"sound/");
176 Com_Printf(
"\n------- sound initialization -------\n");
180 snd_init =
Cvar_Get(
"snd_init",
"1",
CVAR_ARCHIVE,
"Should the sound renderer get initialized");
187 Cvar_Get(
"snd_music",
"PsymongN3", 0,
"Background music track");
193 snd_distance_scale =
Cvar_Get(
"snd_distance_scale",
"0.1", 0,
"Sound distance scale");
195 snd_rate =
Cvar_Get(
"snd_rate",
"44100",
CVAR_ARCHIVE,
"Hz value for sound renderer - default is 44100");
196 snd_chunkbufsize =
Cvar_Get(
"snd_chunkbufsize",
"1024",
CVAR_ARCHIVE,
"The sound buffer chunk size");
201 Cmd_AddCommand(
"snd_play",
S_Play_f,
"Plays a sound fx file. Pass path relative to base/sound without file extension");
204 if (SDL_WasInit(SDL_INIT_AUDIO) == 0) {
205 if (SDL_Init(SDL_INIT_AUDIO) < 0) {
211 MIX_VERSION(&version)
212 Com_Printf(
"SDL_mixer version: %d.%d.%d\n", version.major, version.minor, version.patch);
215 if (Mix_OpenAudio(snd_rate->
integer, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, snd_chunkbufsize->
integer) == -1) {
225 #if SDL_VERSION_ATLEAST(2,0,0)
226 const int n = SDL_GetNumAudioDrivers();
228 Com_Printf(
"... no built-in audio drivers\n");
230 for (
int i = 0;
i < n; ++
i) {
231 Com_Printf(
"... available audio driver %s\n", SDL_GetAudioDriver(
i));
235 Com_Printf(
"... actual audio driver: %s\n", SDL_GetCurrentAudioDriver());
238 if (SDL_AudioDriverName(drivername,
sizeof(drivername)) ==
nullptr)
239 Q_strncpyz(drivername,
"(UNKNOWN)",
sizeof(drivername));
253 #if COMPARE_VERSION(1, 2, 10)
254 if (!(Mix_Init(MIX_INIT_OGG) & MIX_INIT_OGG)) {
255 Com_Printf(
"... could not load ogg vorbis support - sound initialization failed\n");
256 Mix_AllocateChannels(0);
258 SDL_QuitSubSystem(SDL_INIT_AUDIO);
261 Com_Printf(
"... loaded ogg vorbis support\n");
284 Mix_AllocateChannels(0);
290 if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_AUDIO)
293 SDL_QuitSubSystem(SDL_INIT_AUDIO);
300 #if COMPARE_VERSION(1, 2, 10)
335 S_PlaySample(origin, stdSoundPool[sId], attenuation, volume);
bool Q_strnull(const char *string)
stdsound_t
These sounds are precached in S_LoadSamples.
const char * Cmd_Argv(int arg)
Returns a given argument.
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
#define VectorCopy(src, dest)
const char * FS_NextFileFromFileList(const char *files)
Returns the next file that is found in the virtual filesystem identified by the given file pattern...
void S_MumbleUnlink(void)
void Cmd_RemoveCommand(const char *cmdName)
Removes a command from script interface.
void S_PlaySample(const vec3_t origin, s_sample_t *sample, float atten, float relVolume)
Validates the parms and queues the sound up.
int S_LoadSampleIdx(const char *soundFile)
Loads and registers a sound file for later use.
void S_Stop(void)
Stop all channels.
s_sample_t * S_LoadSample(const char *soundFile)
Loads and registers a sound file for later use.
bool CL_OnBattlescape(void)
Check whether we are in a tactical mission as server or as client. But this only means that we are ab...
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
memPool_t * cl_soundSysPool
void S_LoopSample(const vec3_t org, s_sample_t *sample, float relVolume, float attenuation)
Adds a loop sample for e.g. ambient sounds.
void S_MumbleUpdate(const vec3_t origin, const vec3_t forward, const vec3_t right, const vec3_t up)
bool S_LoadAndPlaySample(const char *s, const vec3_t origin, float attenuation, float volume)
does what the name implies in just one function to avoid exposing s_sample_t
void Com_Printf(const char *const fmt,...)
bool Cmd_GenericCompleteFunction(char const *candidate, char const *partial, char const **match)
s_sample_t * stdSoundPool[MAX_SOUNDIDS]
void S_PrecacheSamples(void)
s_channel_t channels[MAX_CHANNELS]
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
void S_PlayStdSample(const stdsound_t sId, const vec3_t origin, float attenuation, float volume)
plays one of the precached samples
int Cmd_Argc(void)
Return the number of arguments of the current command. "command parameter" will result in a argc of 2...
cvar_t * snd_distance_scale
static int S_CompleteSounds(const char *partial, const char **match)
#define Mem_CreatePool(name)
#define Mem_DeletePool(pool)
static cvar_t * snd_chunkbufsize
void S_SetSampleRepeatRate(int sampleRepeatRate)
Controls the repeat rate for the same sample.
void S_StartLocalSample(const char *s, float volume)
Plays a sample without spatialization.
le_t * LE_GetNextInUse(le_t *lastLE)
Iterate through the entities that are in use.
s_sample_t * S_GetSample(const int soundIdx)
#define SAMPLE_TYPES
Supported sound file extensions.
void S_SpatializeChannel(const s_channel_t *ch)
Set distance and stereo panning for the specified channel.
static void S_Restart_f(void)
Restart the sound subsystem so it can pick up new parameters and flush all sounds.
void Cmd_AddParamCompleteFunction(const char *cmdName, int(*function)(const char *partial, const char **match))
void Cmd_Dummy_f(void)
Dummy binding if you don't want unknown commands forwarded to the server.
#define MAX_CHANNELS
the sound environment
void S_FreeChannel(int c)
Callback that is called when a channel finished playing.
void S_LoadSamples(void)
Wrapper for S_PrecacheSamples to avoid exposing it via s_sample.h.
#define SND_VOLUME_DEFAULT
static void S_Play_f(void)
Plays sound fx files via console.