3 * =============================================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
33 #if defined _sdktools_sound_included
36 #define _sdktools_sound_included
39 * Sound should be from the target client.
41 #define SOUND_FROM_PLAYER -2
44 * Sound should be from the listen server player.
46 #define SOUND_FROM_LOCAL_PLAYER -1
49 * Sound is from the world.
51 #define SOUND_FROM_WORLD 0
58 SNDCHAN_REPLACE = -1, /**< Unknown */
59 SNDCHAN_AUTO = 0, /**< Auto */
60 SNDCHAN_WEAPON = 1, /**< Weapons */
61 SNDCHAN_VOICE = 2, /**< Voices */
62 SNDCHAN_ITEM = 3, /**< Items */
63 SNDCHAN_BODY = 4, /**< Player? */
64 SNDCHAN_STREAM = 5, /**< "Stream channel from the static or dynamic area" */
65 SNDCHAN_STATIC = 6, /**< "Stream channel from the static area" */
66 SNDCHAN_VOICE_BASE = 7, /**< "Channel for network voice data" */
67 SNDCHAN_USER_BASE = 135 /**< Anything >= this is allocated to game code */
71 * Sound flags for the sound emitter system.
75 SND_NOFLAGS= 0, /**< Nothing */
76 SND_CHANGEVOL = 1, /**< Change sound volume */
77 SND_CHANGEPITCH = 2, /**< Change sound pitch */
78 SND_STOP = 3, /**< Stop the sound */
79 SND_SPAWNING = 4, /**< Used in some cases for ambients */
80 SND_DELAY = 5, /**< Sound has an initial delay */
81 SND_STOPLOOPING = 6, /**< Stop looping all sounds on the entity */
82 SND_SPEAKER = 7, /**< Being played by a mic through a speaker */
83 SND_SHOULDPAUSE = 8, /**< Pause if game is paused */
87 * Various predefined sound levels in dB.
91 SNDLEVEL_NONE = 0, /**< None */
92 SNDLEVEL_RUSTLE = 20, /**< Rustling leaves */
93 SNDLEVEL_WHISPER = 25, /**< Whispering */
94 SNDLEVEL_LIBRARY = 30, /**< In a library */
95 SNDLEVEL_FRIDGE = 45, /**< Refridgerator */
96 SNDLEVEL_HOME = 50, /**< Average home (3.9 attn) */
97 SNDLEVEL_CONVO = 60, /**< Normal conversation (2.0 attn) */
98 SNDLEVEL_DRYER = 60, /**< Clothes dryer */
99 SNDLEVEL_DISHWASHER = 65, /**< Dishwasher/washing machine (1.5 attn) */
100 SNDLEVEL_CAR = 70, /**< Car or vacuum cleaner (1.0 attn) */
101 SNDLEVEL_NORMAL = 75, /**< Normal sound level */
102 SNDLEVEL_TRAFFIC = 75, /**< Busy traffic (0.8 attn) */
103 SNDLEVEL_MINIBIKE = 80, /**< Mini-bike, alarm clock (0.7 attn) */
104 SNDLEVEL_SCREAMING = 90, /**< Screaming child (0.5 attn) */
105 SNDLEVEL_TRAIN = 100, /**< Subway train, pneumatic drill (0.4 attn) */
106 SNDLEVEL_HELICOPTER = 105, /**< Helicopter */
107 SNDLEVEL_SNOWMOBILE = 110, /**< Snow mobile */
108 SNDLEVEL_AIRCRAFT = 120, /**< Auto horn, aircraft */
109 SNDLEVEL_RAIDSIREN = 130, /**< Air raid siren */
110 SNDLEVEL_GUNFIRE = 140, /**< Gunshot, jet engine (0.27 attn) */
111 SNDLEVEL_ROCKET = 180, /**< Rocket launching (0.2 attn) */
114 #define SNDVOL_NORMAL 1.0 /**< Normal volume */
115 #define SNDPITCH_NORMAL 100 /**< Normal pitch */
116 #define SNDPITCH_LOW 95 /**< A low pitch */
117 #define SNDPITCH_HIGH 120 /**< A high pitch */
118 #define SNDATTN_NONE 0.0 /**< No attenuation */
119 #define SNDATTN_NORMAL 0.8 /**< Normal attenuation */
120 #define SNDATTN_STATIC 1.25 /**< Static attenuation? */
121 #define SNDATTN_RICOCHET 1.5 /**< Ricochet effect */
122 #define SNDATTN_IDLE 2.0 /**< Idle attenuation? */
125 * Prefetches a sound.
127 * @param name Sound file name.
130 native PrefetchSound(const String:nane[]);
133 * Gets a sound's duration (does not work for mp3s).
135 * @param name Sound file name.
136 * @return Duration in seconds.
138 native Float:GetSoundDuration(const String:name[]);
141 * Emits an ambient sound.
143 * @param entity Entity index to associate sound with.
144 * @param pos Origin of sound.
145 * @param name Sound file name.
146 * @param level Sound level (from 0 to 255).
147 * @param flags Sound flags.
148 * @param vol Volume (from 0.0 to 1.0).
149 * @param pitch Pitch (from 0 to 255).
150 * @param delay Play delay.
153 native EmitAmbientSound(const String:name[],
155 entity = SOUND_FROM_WORLD,
156 level = SNDLEVEL_NORMAL,
158 Float:vol = SNDVOL_NORMAL,
159 pitch = SNDPITCH_NORMAL,
163 * Fades a client's volume level toward silence or a given percentage.
165 * @param client Client index.
166 * @param percent Fade percentage.
167 * @param outtime Fade out time, in seconds.
168 * @param holdtime Hold time, in seconds.
169 * @param intime Fade in time, in seconds.
171 * @error Invalid client index or client not in game.
173 native FadeClientVolume(client, Float:percent, Float:outtime, Float:holdtime, Float:intime);
178 * @param entity Entity index.
179 * @param channel Channel number.
180 * @param name Sound name.
183 native StopSound(entity, channel, const String:name[]);
186 * Emits a sound to a list of clients.
188 * @param clients Array of client indexes.
189 * @param numClients Number of clients in the array.
190 * @param entity Entity to emit from.
191 * @param channel Channel to emit with.
192 * @param sample Sound name.
193 * @param level Sound level.
194 * @param flags Sound flags.
195 * @param volume Sound volume.
196 * @param pitch Sound pitch.
197 * @param speakerentity Unknown.
198 * @param origin Sound origin.
199 * @param dir Sound direction.
200 * @param updatePos Unknown (updates positions?)
201 * @param soundtime Alternate time to play sound for.
202 * @param ... Optional list of Float[3] arrays to specify additional origins.
204 * @error Invalid client index.
206 native EmitSound(const clients[],
208 const String:sample[],
209 entity = SOUND_FROM_PLAYER,
210 channel = SNDCHAN_AUTO,
211 level = SNDLEVEL_NORMAL,
213 Float:volume = SNDVOL_NORMAL,
214 pitch = SNDPITCH_NORMAL,
216 const Float:origin[3] = NULL_VECTOR,
217 const Float:dir[3] = NULL_VECTOR,
218 bool:updatePos = true,
219 Float:soundtime = 0.0,
223 * Emits a sentence to a list of clients.
225 * @param clients Array of client indexes.
226 * @param numClients Number of clients in the array.
227 * @param entity Entity to emit from.
228 * @param channel Channel to emit with.
229 * @param sentence Sentence index (from PrecacheSenteFile).
230 * @param level Sound level.
231 * @param flags Sound flags.
232 * @param volume Sound volume.
233 * @param pitch Sound pitch.
234 * @param speakerentity Unknown.
235 * @param origin Sound origin.
236 * @param dir Sound direction.
237 * @param updatePos Unknown (updates positions?)
238 * @param soundtime Alternate time to play sound for.
239 * @param ... Optional list of Float[3] arrays to specify additional origins.
241 * @error Invalid client index.
243 native EmitSentence(const clients[],
247 channel = SNDCHAN_AUTO,
248 level = SNDLEVEL_NORMAL,
250 Float:volume = SNDVOL_NORMAL,
251 pitch = SNDPITCH_NORMAL,
253 const Float:origin[3] = NULL_VECTOR,
254 const Float:dir[3] = NULL_VECTOR,
255 bool:updatePos = true,
256 Float:soundtime = 0.0,
261 * Wrapper to emit sound to one client.
263 * @param client Client index.
264 * @param entity Entity to emit from.
265 * @param channel Channel to emit with.
266 * @param sample Sound name.
267 * @param level Sound level.
268 * @param flags Sound flags.
269 * @param volume Sound volume.
270 * @param pitch Sound pitch.
271 * @param speakerentity Unknown.
272 * @param origin Sound origin.
273 * @param dir Sound direction.
274 * @param updatePos Unknown (updates positions?)
275 * @param soundtime Alternate time to play sound for.
277 * @error Invalid client index.
279 stock EmitSoundToClient(client,
280 const String:sample[],
281 entity = SOUND_FROM_PLAYER,
282 channel = SNDCHAN_AUTO,
283 level = SNDLEVEL_NORMAL,
285 Float:volume = SNDVOL_NORMAL,
286 pitch = SNDPITCH_NORMAL,
288 const Float:origin[3] = NULL_VECTOR,
289 const Float:dir[3] = NULL_VECTOR,
290 bool:updatePos = true,
291 Float:soundtime = 0.0)
295 /* Save some work for SDKTools and remove SOUND_FROM_PLAYER references */
296 entity = (entity == SOUND_FROM_PLAYER) ? client : entity;
297 EmitSound(clients, 1, sample, entity, channel,
298 level, flags, volume, pitch, speakerentity,
299 origin, dir, updatePos, soundtime);
303 * Wrapper to emit sound to all clients.
305 * @param entity Entity to emit from.
306 * @param channel Channel to emit with.
307 * @param sample Sound name.
308 * @param level Sound level.
309 * @param flags Sound flags.
310 * @param volume Sound volume.
311 * @param pitch Sound pitch.
312 * @param speakerentity Unknown.
313 * @param origin Sound origin.
314 * @param dir Sound direction.
315 * @param updatePos Unknown (updates positions?)
316 * @param soundtime Alternate time to play sound for.
318 * @error Invalid client index.
320 stock EmitSoundToAll(const String:sample[],
321 entity = SOUND_FROM_PLAYER,
322 channel = SNDCHAN_AUTO,
323 level = SNDLEVEL_NORMAL,
325 Float:volume = SNDVOL_NORMAL,
326 pitch = SNDPITCH_NORMAL,
328 const Float:origin[3] = NULL_VECTOR,
329 const Float:dir[3] = NULL_VECTOR,
330 bool:updatePos = true,
331 Float:soundtime = 0.0)
333 new maxClients = GetMaxClients();
334 new clients[maxClients];
337 for (new i=1; i<=maxClients; i++)
339 if (IsClientInGame(i))
341 clients[total++] = i;
350 EmitSound(clients, total, sample, entity, channel,
351 level, flags, volume, pitch, speakerentity,
352 origin, dir, updatePos, soundtime);
356 * Converts an attenuation value to a sound level.
357 * This function is from the HL2SDK.
359 * @param attn Attenuation value.
360 * @return Integer sound level.
362 stock ATTN_TO_SNDLEVEL(Float:attn)
366 return RoundFloat(50.0 + (20.0 / attn));