UFO: Alien Invasion
Loading...
Searching...
No Matches
s_sample.cpp File Reference

Main control for any streaming sound output device. More...

#include "s_sample.h"
#include "s_main.h"
#include "../../common/filesys.h"
#include "../../common/common.h"
Include dependency graph for s_sample.cpp:

Go to the source code of this file.

Macros

#define SAMPLE_HASH_SIZE   64
#define SAMPLE_MAX_COUNT   1000

Functions

static s_sample_tS_FindByName (const char *name)
 Searches the hash for a given sound file.
static Mix_Chunk * S_LoadSampleChunk (const char *sound)
int S_LoadSampleIdx (const char *soundFile)
 Loads and registers a sound file for later use.
s_sample_tS_GetSample (const int soundIdx)
void S_FreeSamples (void)
void S_PrecacheSamples (void)

Variables

static s_sample_tsampleHash [SAMPLE_HASH_SIZE]
static s_sample_tsampleIndex [SAMPLE_MAX_COUNT]
static int sampleIndexLast = 0
s_sample_tstdSoundPool [MAX_SOUNDIDS]

Detailed Description

Main control for any streaming sound output device.

Definition in file s_sample.cpp.

Macro Definition Documentation

◆ SAMPLE_HASH_SIZE

#define SAMPLE_HASH_SIZE   64

Definition at line 31 of file s_sample.cpp.

Referenced by S_FindByName(), S_FreeSamples(), and S_LoadSampleIdx().

◆ SAMPLE_MAX_COUNT

#define SAMPLE_MAX_COUNT   1000

Definition at line 35 of file s_sample.cpp.

Function Documentation

◆ S_FindByName()

s_sample_t * S_FindByName ( const char * name)
static

Searches the hash for a given sound file.

Parameters
nameThe soundfile (relative to the sound dir and without extension)
Returns
nullptr if not yet loaded

Definition at line 47 of file s_sample.cpp.

References Com_HashKey(), hash, name, Q_streq, SAMPLE_HASH_SIZE, and sampleHash.

Referenced by S_LoadSampleIdx().

◆ S_FreeSamples()

void S_FreeSamples ( void )

Definition at line 139 of file s_sample.cpp.

References s_sample_t::hashNext, i, Mem_Free, OBJZERO, SAMPLE_HASH_SIZE, sampleHash, and sampleIndex.

Referenced by S_Shutdown().

◆ S_GetSample()

s_sample_t * S_GetSample ( const int soundIdx)

Definition at line 132 of file s_sample.cpp.

References sampleIndex, and sampleIndexLast.

Referenced by S_Frame(), and S_LoadSample().

◆ S_LoadSampleChunk()

Mix_Chunk * S_LoadSampleChunk ( const char * sound)
static

Definition at line 58 of file s_sample.cpp.

References Com_Printf(), FS_FreeFile(), FS_LoadFile(), len, MAX_QPATH, SAMPLE_TYPES, and va().

Referenced by S_LoadSampleIdx().

◆ S_LoadSampleIdx()

int S_LoadSampleIdx ( const char * soundFile)

Loads and registers a sound file for later use.

Parameters
[in]soundFileThe name of the soundfile, relative to the sounds dir
Returns
The index of the loaded sample or 0
See also
S_LoadSound

Definition at line 105 of file s_sample.cpp.

References s_sample_t::chunk, cl_soundSysPool, Com_HashKey(), Com_StripExtension(), hash, s_sample_t::hashNext, s_sample_t::index, MAX_QPATH, Mem_PoolAllocType, Mem_PoolStrDup, name, s_sample_t::name, s_env, S_FindByName(), S_LoadSampleChunk(), SAMPLE_HASH_SIZE, sampleHash, sampleIndex, and sampleIndexLast.

Referenced by LE_AddAmbientSound(), and S_LoadSample().

◆ S_PrecacheSamples()

void S_PrecacheSamples ( void )
Note
Called at precache phase - only load these soundfiles once at startup or on sound restart
See also
S_Restart_f

Definition at line 163 of file s_sample.cpp.

References fireDef_t::bounceSound, csi, objDef_t::fd, fireDef_t::fireSound, fireDef_t::hitBodySound, i, fireDef_t::impactSound, INVSH_GetItemByIDX(), objDef_t::numFiredefs, objDef_t::numWeapons, s_env, S_LoadSample(), SOUND_WATER_IN, SOUND_WATER_MOVE, SOUND_WATER_OUT, and stdSoundPool.

Referenced by S_LoadSamples().

Variable Documentation

◆ sampleHash

s_sample_t* sampleHash[SAMPLE_HASH_SIZE]
static

Definition at line 32 of file s_sample.cpp.

Referenced by S_FindByName(), S_FreeSamples(), and S_LoadSampleIdx().

◆ sampleIndex

s_sample_t* sampleIndex[SAMPLE_MAX_COUNT]
static

Definition at line 36 of file s_sample.cpp.

Referenced by S_FreeSamples(), S_GetSample(), and S_LoadSampleIdx().

◆ sampleIndexLast

int sampleIndexLast = 0
static

Definition at line 37 of file s_sample.cpp.

Referenced by S_GetSample(), and S_LoadSampleIdx().

◆ stdSoundPool

s_sample_t* stdSoundPool[MAX_SOUNDIDS]

this pool is reloaded on every sound system restart

Definition at line 40 of file s_sample.cpp.

Referenced by S_PlayStdSample(), and S_PrecacheSamples().