]> git.xonotic.org Git - xonotic/darkplaces.git/blob - sound.h
zone: Do a straight malloc on non-Windows
[xonotic/darkplaces.git] / sound.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #ifndef SOUND_H
22 #define SOUND_H
23
24 #include "matrixlib.h"
25 struct cmd_state_s;
26
27
28 // ====================================================================
29 // Constants
30 // ====================================================================
31
32 #define DEFAULT_SOUND_PACKET_VOLUME 255
33 #define DEFAULT_SOUND_PACKET_ATTENUATION 1.0
34
35 // Channel flags
36 // These channel flags can be used for sound() builtins, with SOUNDFLAG_* names
37 #define CHANNELFLAG_NONE        0
38 #define CHANNELFLAG_RELIABLE    (1 << 0) // send as reliable message (only used on server)
39 #define CHANNELFLAG_FORCELOOP   (1 << 1) // force looping even if the sound is not looped
40 #define CHANNELFLAG_LOCALSOUND  (1 << 2) // INTERNAL USE. Not settable by S_SetChannelFlag
41 #define CHANNELFLAG_PAUSED      (1 << 3) // pause status
42 #define CHANNELFLAG_FULLVOLUME  (1 << 4) // isn't affected by the general volume
43
44 // ====================================================================
45 // Types and variables
46 // ====================================================================
47
48 typedef struct sfx_s sfx_t;
49
50 extern struct cvar_s mastervolume;
51 extern struct cvar_s bgmvolume;
52 extern struct cvar_s volume;
53 extern struct cvar_s snd_initialized;
54 extern struct cvar_s snd_staticvolume;
55 extern struct cvar_s snd_mutewhenidle;
56
57
58 // ====================================================================
59 // Functions
60 // ====================================================================
61
62 void S_Init (void);
63 void S_Terminate (void);
64
65 void S_Startup (void);
66 void S_Shutdown (void);
67 void S_UnloadAllSounds_f(struct cmd_state_s *cmd);
68
69 void S_Update(const matrix4x4_t *listenermatrix);
70 void S_ExtraUpdate (void);
71
72 sfx_t *S_PrecacheSound (const char *sample, qbool complain, qbool levelsound);
73 float S_SoundLength(const char *name);
74 void S_ClearUsed (void);
75 void S_PurgeUnused (void);
76 qbool S_IsSoundPrecached (const sfx_t *sfx);
77 sfx_t *S_FindName(const char *name);
78
79 // these define the "engine" channel namespace
80 #define CHAN_MIN_AUTO       -128
81 #define CHAN_MAX_AUTO          0
82 #define CHAN_MIN_SINGLE        1
83 #define CHAN_MAX_SINGLE      127
84 #define IS_CHAN_AUTO(n)        ((n) >= CHAN_MIN_AUTO && (n) <= CHAN_MAX_AUTO)
85 #define IS_CHAN_SINGLE(n)      ((n) >= CHAN_MIN_SINGLE && (n) <= CHAN_MAX_SINGLE)
86 #define IS_CHAN(n)             (IS_CHAN_AUTO(n) || IS_CHAN_SINGLE(n))
87
88 // engine channel == network channel
89 #define CHAN_ENGINE2NET(c)     (c)
90 #define CHAN_NET2ENGINE(c)     (c)
91
92 // engine view of channel encodes the auto flag into the channel number (see CHAN_ constants below)
93 // user view uses the flags bitmask for it
94 #define CHAN_USER2ENGINE(c)    (c)
95 #define CHAN_ENGINE2USER(c)    (c)
96 #define CHAN_ENGINE2CVAR(c)    (abs(c))
97
98 // S_StartSound returns the channel index, or -1 if an error occurred
99 int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation);
100 int S_StartSound_StartPosition_Flags (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float startposition, int flags, float fspeed);
101 qbool S_LocalSound (const char *s);
102
103 void S_StaticSound (sfx_t *sfx, vec3_t origin, float fvol, float attenuation);
104 void S_StopSound (int entnum, int entchannel);
105 void S_StopAllSounds (void);
106 void S_StopAllSounds_f(struct cmd_state_s *cmd);
107 void S_PauseGameSounds (qbool toggle);
108
109 void S_StopChannel (unsigned int channel_ind, qbool lockmutex, qbool freesfx);
110 qbool S_SetChannelFlag (unsigned int ch_ind, unsigned int flag, qbool value);
111 void S_SetChannelVolume (unsigned int ch_ind, float fvol);
112 void S_SetChannelSpeed (unsigned int ch_ind, float fspeed);
113 float S_GetChannelPosition (unsigned int ch_ind);
114 float S_GetEntChannelPosition(int entnum, int entchannel);
115
116 void S_BlockSound (void);
117 void S_UnblockSound (void);
118
119 int S_GetSoundRate (void);
120 int S_GetSoundChannels (void);
121 int S_GetSoundWidth (void);
122
123 #endif