Sound Reference - Basics
Sound Reference
Other pages on the topic of audio and sound are:
- Basics
- Creating Looping Sounds
File Formats and Frequencies
Garry's Mod can load audio files in the following formats:
.mp3
.wav
Regardless of audio file format, all audio must use one of the following sample rates in order to be played:
11025 hz
22050 hz
44100 hz
If an audio file does not use a valid sample rate, it will not play and will produce console errors such as:
Unsupported 32-bit wave file <File Name>.wav
Invalid sample rate (<Audio File Same Rate>) for sound '<File Name>'
Folder Structure
When the game attempts to load sound files, it looks for them in the following locations and order:
garrysmod/sound/
garrysmod/addons/<Addon Name>/sound/
garrysmod/gamemodes/<Gamemode Name>/content/sound/
When searching for an audio file, Garry's Mod will use the first matching file it finds.
materials/
, models/
, etc.) the sound
folder's name is singular (sound
) rather than plural (sounds
) and does not end with an "s
".Example: File/Folder Paths
Suppose you have an audio file you want to play called weapon_reload.mp3
that is intended for use as part of a Scripted Weapon (SWEP) called rocket_launcher
.
There are 3 locations where you might place weapon_reload.mp3
:
1. During the early proof-of-concept development of your weapon, you might add files to the game's basic folder structure.
In this case, you might use the path: garrysmod/sound/weapons/rocket_launcher/weapon_reload.mp3
2. Suppose that this rocket_launcher
weapon is part of an Addon called weapon_pack
.
Here you would use a folder structure like: garrysmod/addons/weapon_pack/sound/weapons/rocket_launcher/weapon_reload.mp3
3. If this rocket_launcher
is part of a larger Gamemode called rocket_deathmatch
, you would instead put this audio file within the gamemode's folder structure.
The folder structure here might look like: garrysmod/gamemodes/rocket_deathmatch/content/sound/weapons/rocket_launcher/weapon_reload.mp3
In all 3 cases, the file path used to load and play the file from your Lua script(s) is: weapons/rocket_launcher/weapon_reload.mp3