Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sr2echa/TF2-Source-Code/llms.txt

Use this file to discover all available pages before exploring further.

TF2’s audio is managed by two layers: the SoundEmitter system (soundemittersystem/) that maps logical sound names to wave files and parameters, and the engine sound interfaces (IEngineSound) that submit actual sound commands to the audio hardware. Game code almost always calls EmitSound() with a logical name rather than a raw wave path.

Sound script files

Sound scripts (e.g., scripts/game_sounds_tf.txt) define named sound entries as KeyValues. The CSoundEmitterSystemBase class parses these files at startup and stores them in a hash table keyed by sound name.
scripts/game_sounds_tf.txt (example entry)
"Weapon_Minigun.Fire"
{
    "channel"       "CHAN_WEAPON"
    "volume"        "1.0"
    "soundlevel"    "SNDLVL_GUNFIRE"
    "rndwave"
    {
        "wave"  "weapons/minigun_shoot1.wav"
        "wave"  "weapons/minigun_shoot2.wav"
        "wave"  "weapons/minigun_shoot3.wav"
    }
}
Key sound script parameters:
KeyDescription
channelAudio channel (CHAN_WEAPON, CHAN_VOICE, CHAN_BODY, etc.)
volume0.0–1.0 or VOL_NORM
soundlevelAttenuation level (SNDLVL_NORM, SNDLVL_GUNFIRE, SNDLVL_NONE)
pitchPitch shift (100 = normal, PITCH_NORM)
wave / rndwaveSingle wave file or random selection block
delay_msecPre-play delay in milliseconds

ISoundEmitterSystemBase

CSoundEmitterSystemBase (soundemittersystem/soundemittersystembase.h) is the server-and-client registry. It resolves a sound name to a CSoundParametersInternal struct, then game code submits those parameters to the engine.
// soundemittersystem/soundemittersystembase.h
class CSoundEmitterSystemBase : public ISoundEmitterSystemBase
{
public:
    virtual HSOUNDSCRIPTHANDLE GetSoundIndex( const char *pSoundName ) const;
    virtual bool GetParametersForSound( const char *soundname,
        CSoundParameters &params, gender_t gender ) = 0;
    virtual const char *GetWavFileForSound( const char *soundname,
        gender_t gender ) = 0;
};

EmitSound on server and client

Game code uses CBaseEntity::EmitSound() on the server (which sends a SVC_Sounds network message to clients) and C_BaseEntity::EmitSound() on the client for purely local sounds (UI clicks, local player footsteps).
// Server-side: plays for all clients who can hear
EmitSound( filter, entindex(), "Weapon_Minigun.Fire" );

// Client-side: local only
C_BaseEntity::EmitSound( "UI.ButtonClick" );

Audio channels

Channels prevent sounds from stacking incoherently on the same entity. Each channel can only play one sound at a time per entity:
ChannelUsage
CHAN_WEAPONWeapon fire, reload
CHAN_VOICECharacter speech, pain sounds
CHAN_BODYFootsteps, physical impacts
CHAN_ITEMItem pickup, flag sounds
CHAN_STATICAmbient/looping background
CHAN_AUTOEngine-selected, allows stacking

Soundscapes

Soundscapes (soundscape_*.txt and soundscapeSystem.cpp) layer multiple ambient loops and random sound triggers to create the environmental audio feel of each map area. env_soundscape entities in maps reference soundscape entries by name and activate when players enter trigger volumes.
TF2 voices use gender-aware sound selection. The gender_t parameter in GetParametersForSound() allows male/female voice variant selection, used for taunts and domination lines.

Build docs developers (and LLMs) love