]> icculus.org git repositories - divverent/darkplaces.git/blob - sound.h
don't show editlights cursor position when not in editlights mode
[divverent/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 // sound.h -- client sound i/o functions
21
22 #ifndef SOUND_H
23 #define SOUND_H
24
25 //AK: TODO: find a better solution instead of using a define
26 #if defined( _WIN32 ) && !defined( USE_SDL )
27 #       define USE_DSOUND
28 #endif
29
30 #define DEFAULT_SOUND_PACKET_VOLUME 255
31 #define DEFAULT_SOUND_PACKET_ATTENUATION 1.0
32
33 typedef struct
34 {
35         size_t  length;
36         size_t  offset;
37         qbyte   data[4];        // variable sized
38 } sfxbuffer_t;
39
40 typedef struct
41 {
42         unsigned int    speed;
43         unsigned int    width;
44         unsigned int    channels;
45 } snd_format_t;
46
47 // sfx_t flags
48 #define SFXFLAG_NONE                    0
49 #define SFXFLAG_SILENTLYMISSING (1 << 0) // if the sfx is missing and loaded with complain = false
50 #define SFXFLAG_USED                    (1 << 1)
51 #define SFXFLAG_STREAMED                (1 << 2) // informative only. You shouldn't need to know that
52
53 typedef struct snd_fetcher_s snd_fetcher_t;
54 typedef struct sfx_s
55 {
56         char                            name[MAX_QPATH];
57         mempool_t                       *mempool;
58         unsigned int            flags;                  // cf SFXFLAG_* defines
59         snd_format_t            format;
60         int                                     loopstart;
61         size_t                          total_length;
62         const snd_fetcher_t     *fetcher;
63         void                            *fetcher_data;  // Per-sfx data for the sound fetching functions
64 } sfx_t;
65
66 typedef struct
67 {
68         snd_format_t    format;
69         int                             samples;                // mono samples in buffer
70         int                             samplepos;              // in mono samples
71         unsigned char   *buffer;
72         int                             bufferlength;   // used only by certain drivers
73 } dma_t;
74
75 // channel_t flags
76 #define CHANNELFLAG_NONE                0
77 #define CHANNELFLAG_FORCELOOP   (1 << 0) // force looping even if the sound is not looped
78 #define CHANNELFLAG_LOCALSOUND  (1 << 1) // non-game sound (ex: menu sound)
79 #define CHANNELFLAG_PAUSED              (1 << 2)
80
81 typedef struct
82 {
83         sfx_t                   *sfx;                   // sfx number
84         unsigned int    flags;                  // cf CHANNELFLAG_* defines
85         int                             leftvol;                // 0-255 volume
86         int                             rightvol;               // 0-255 volume
87         int                             end;                    // end time in global paintsamples
88         int                             lastptime;              // last time this channel was painted
89         int                             pos;                    // sample position in sfx
90         int                             looping;                // where to loop, -1 = no looping
91         int                             entnum;                 // to allow overriding a specific sound
92         int                             entchannel;
93         vec3_t                  origin;                 // origin of sound effect
94         vec_t                   dist_mult;              // distance multiplier (attenuation/clipK)
95         int                             master_vol;             // 0-255 master volume
96         void                    *fetcher_data;  // Per-channel data for the sound fetching function
97 } channel_t;
98
99 typedef const sfxbuffer_t* (*snd_fetcher_getsb_t) (channel_t* ch, unsigned int start, unsigned int nbsamples);
100 typedef void (*snd_fetcher_end_t) (channel_t* ch);
101 struct snd_fetcher_s
102 {
103         snd_fetcher_getsb_t     getsb;
104         snd_fetcher_end_t       end;
105 };
106
107 void S_Init (void);
108 void S_Startup (void);
109 void S_Shutdown (void);
110 // S_StartSound returns the channel index, or -1 if an error occurred
111 int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol,  float attenuation);
112 void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation);
113 void S_StopChannel (unsigned int channel_ind);
114 void S_PauseChannel (unsigned int channel_ind, qboolean toggle);
115 void S_LoopChannel (unsigned int channel_ind, qboolean toggle);
116 void S_StopSound (int entnum, int entchannel);
117 void S_StopAllSounds(qboolean clear);
118 void S_PauseGameSounds (void);
119 void S_ResumeGameSounds (void);
120 void S_SetChannelVolume (unsigned int ch_ind, float fvol);
121 void S_Update(vec3_t origin, vec3_t forward, vec3_t left, vec3_t up);
122 void S_ExtraUpdate (void);
123
124 sfx_t *S_GetCached(const char *name, qboolean stdpath);
125 sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean stdpath);
126 void S_TouchSound (const char *sample, qboolean stdpath);
127 void S_ClearUsed (void);
128 void S_PurgeUnused (void);
129 void S_PaintChannels(int endtime);
130 void S_InitPaintChannels (void);
131
132 // initializes cycling through a DMA buffer and returns information on it
133 qboolean SNDDMA_Init(void);
134
135 // gets the current DMA position
136 int SNDDMA_GetDMAPos(void);
137
138 // shutdown the DMA xfer.
139 void SNDDMA_Shutdown(void);
140
141 extern size_t ResampleSfx (const qbyte *in_data, size_t in_length, const snd_format_t* in_format, qbyte *out_data, const char* sfxname);
142
143 // ====================================================================
144 // User-setable variables
145 // ====================================================================
146
147 // LordHavoc: increased from 128 to 516 (4 for NUM_AMBIENTS)
148 #define MAX_CHANNELS                    516
149 // LordHavoc: increased maximum sound channels from 8 to 128
150 #define MAX_DYNAMIC_CHANNELS    128
151
152
153 extern channel_t channels[MAX_CHANNELS];
154 // 0 to MAX_DYNAMIC_CHANNELS-1  = normal entity sounds
155 // MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc
156 // MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds
157
158 extern unsigned int total_channels;
159
160 //
161 // Fake dma is a synchronous faking of the DMA progress used for
162 // isolating performance in the renderer.  The fakedma_updates is
163 // number of times S_Update() is called per second.
164 //
165
166 extern qboolean fakedma;
167 extern int fakedma_updates;
168 extern int paintedtime;
169 extern int soundtime;
170 extern vec3_t listener_vieworigin;
171 extern vec3_t listener_viewforward;
172 extern vec3_t listener_viewleft;
173 extern vec3_t listener_viewup;
174 extern volatile dma_t *shm;
175 extern vec_t sound_nominal_clip_dist;
176
177 extern cvar_t bgmvolume;
178 extern cvar_t volume;
179 extern cvar_t snd_swapstereo;
180
181 extern cvar_t cdaudioinitialized;
182 extern cvar_t snd_initialized;
183 extern cvar_t snd_streaming;
184
185 extern int snd_blocked;
186
187 void S_LocalSound (const char *s, qboolean stdpath);
188 qboolean S_LoadSound (sfx_t *s, qboolean complain);
189 void S_UnloadSound(sfx_t *s);
190
191 void SND_InitScaletable (void);
192 void SNDDMA_Submit(void);
193
194 void *S_LockBuffer(void);
195 void S_UnlockBuffer(void);
196
197 #endif