Revision Difference
sound_basics#563144
<warning>
This page is a work in progress
</warning>
<title>Sound Reference - Basics</title>
# Sound Reference
Other pages on the topic of audio and sound are:
* **Basics**
* <page text="Creating Looping Sounds">Creating_Looping_Sounds</page>
⤶
# 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:
1. `garrysmod/sound/`
2. `garrysmod/addons/<Addon Name>/sound/`
3. `garrysmod/gamemodes/<Gamemode Name>/content/sound/`
⤶
When searching for an audio file, Garry's Mod will use the first matching file it finds.⤶
<note>
Unlike other asset folders (`materials/`, `models/`, etc.) the `sound` folder's name is singular (`sound`) rather than plural (`sounds`) and does **not** end with an "`s`".
</note>
<example name="Choosing a Folder Structure">⤶
<example name="File/Folder Paths">⤶
<description>
Suppose you have an audio file you want to play called `weapon_reload.mp3` that is intended for use as part of a <page text="Scripted Weapon (SWEP)">Structures/SWEP</page> 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 <page text="Addon">Addons</page> 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 <page text="Gamemode">Gamemode_Creation</page> 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`
</description>
</example>
⤶
<example name="Load Order">⤶
<description>⤶
⤶
TODO⤶
⤶
</description>⤶
</example>⤶
⤶
⤶
# File Formats⤶
⤶
⤶