]> icculus.org git repositories - taylor/freespace2.git/blob - include/ds.h
finished cfilesystem.
[taylor/freespace2.git] / include / ds.h
1 /*
2  * $Logfile: /Freespace2/code/Sound/ds.h $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Header file for interface to DirectSound
8  *
9  * $Log$
10  * Revision 1.2  2002/05/27 01:06:01  theoddone33
11  * sound.cpp works
12  *
13  * Revision 1.1.1.1  2002/05/03 03:28:12  root
14  * Initial import.
15  *
16  * 
17  * 5     8/27/99 6:38p Alanl
18  * crush the blasted repeating messages bug
19  * 
20  * 4     8/01/99 2:06p Alanl
21  * increase the rolloff for A3D
22  * 
23  * 3     5/23/99 8:11p Alanl
24  * Added support for EAX
25  * 
26  * 2     10/07/98 10:54a Dave
27  * Initial checkin.
28  * 
29  * 1     10/07/98 10:51a Dave
30  * 
31  * 21    5/05/98 4:49p Lawrance
32  * Put in code to authenticate A3D, improve A3D support
33  * 
34  * 20    4/20/98 12:03a Lawrance
35  * Allow prioritizing of CTRL3D buffers
36  * 
37  * 19    4/18/98 9:12p Lawrance
38  * Added Aureal support.
39  * 
40  * 18    4/13/98 5:04p Lawrance
41  * Write functions to determine how many milliseconds are left in a sound
42  * 
43  * 17    3/23/98 10:32a Lawrance
44  * Add functions for extracting raw sound data
45  * 
46  * 16    2/15/98 11:10p Lawrance
47  * more work on real-time voice system
48  * 
49  * 15    2/15/98 4:43p Lawrance
50  * work on real-time voice
51  * 
52  * 14    2/06/98 7:30p John
53  * Added code to monitor the number of channels of sound actually playing.
54  * 
55  * 13    2/06/98 8:56a Allender
56  * fixed calling convention problem with DLL handles
57  * 
58  * 12    2/04/98 6:08p Lawrance
59  * Read function pointers from dsound.dll, further work on
60  * DirectSoundCapture.
61  * 
62  * 11    1/31/98 5:48p Lawrance
63  * Start on real-time voice recording
64  * 
65  * 10    12/05/97 5:19p Lawrance
66  * re-do sound priorities to make more general and extensible
67  * 
68  * 9     11/20/97 5:36p Dave
69  * Hooked in a bunch of main hall changes (including sound). Made it
70  * possible to reposition (rewind/ffwd) 
71  * sound buffer pointers. Fixed animation direction change framerate
72  * problem.
73  * 
74  * 8     10/13/97 7:41p Lawrance
75  * store duration of sound
76  * 
77  * 7     7/28/97 11:39a Lawrance
78  * allow individual volume scaling on 3D buffers
79  * 
80  * 6     7/17/97 9:32a John
81  * made all directX header files name start with a v
82  * 
83  * 5     7/15/97 11:15a Lawrance
84  * limit the max instances of simultaneous sound effects, implement
85  * priorities to force critical sounds
86  * 
87  * 4     6/09/97 11:50p Lawrance
88  * integrating DirectSound3D
89  * 
90  * 3     6/02/97 1:45p Lawrance
91  * implementing hardware mixing
92  * 
93  * 2     5/29/97 12:04p Lawrance
94  * creation of file to hold DirectSound specific portions
95  *
96  * $NoKeywords: $
97  */
98
99 #ifndef __DS_H__
100 #define __DS_H__
101
102 #ifndef PLAT_UNIX
103 #include <windows.h>
104 #include <mmreg.h>
105 #include "vdsound.h"
106 #endif
107 #include "pstypes.h"
108
109 #define DS_HARDWARE     (1<<0)
110 #define DS_3D                   (1<<1)
111 #define DS_USE_DS3D     (1<<2)
112
113 // Constants that DirectSound should assign, but doesn't
114 #define MAX_PAN         1500.0f
115 #define MIN_PITCH               100
116 #define MAX_PITCH               100000
117
118
119 // limits placed on how many concurrent sounds of the same type can play simultaneously
120 #define DS_MUST_PLAY                            0
121 #define DS_LIMIT_ONE                            1
122 #define DS_LIMIT_TWO                            2
123 #define DS_LIMIT_THREE                  3
124
125 #define DS_DUP_FAILED                   -99
126
127 typedef struct sound_info {
128         int     format;         // WAVE_FORMAT_* defines from mmreg.h
129         uint    size;
130         int     sample_rate;
131         int     avg_bytes_per_sec;
132         int     n_block_align;
133         int     bits;
134         int     n_channels;
135         int     duration;       // time in ms for duration of sound
136         ubyte   *data;
137 } sound_info;
138
139 extern int                                                      ds_initialized;
140 #ifndef PLAT_UNIX
141 extern LPDIRECTSOUNDBUFFER              pPrimaryBuffer;
142 extern LPDIRECTSOUND                            pDirectSound;
143
144 extern HRESULT (__stdcall *pfn_DirectSoundCaptureCreate)(LPGUID lpGUID, LPDIRECTSOUNDCAPTURE *lplpDSC, LPUNKNOWN pUnkOuter);
145 #endif
146
147 int     ds_init(int use_a3d, int use_eax);
148 void    ds_close();
149 void    ds_get_primary_format(WAVEFORMATEX *wfx);
150 int     ds_parse_wave(char *filename, ubyte **dest, uint *dest_size, WAVEFORMATEX **header);
151 int     ds_load_buffer(int *sid, int *hid, int *final_size, void *header, sound_info *si, int flags);
152 void    ds_unload_buffer(int sid, int hid);
153 int     ds_play(int sid, int hid, int snd_id, int priority, int volume, int pan, int looping, bool is_voice_msg = false);
154 int     ds_convert_volume(float volume);                // Convert a volume from 0.0f->1.0f to -10000 -> 0
155 float ds_get_percentage_vol(int ds_vol);        // Convert a volume from -10000 -> 0 to 0.0f->1.0f
156 int     ds_get_channel(int sig);
157 int     ds_is_channel_playing(int channel);
158 void    ds_stop_channel(int channel);
159 void    ds_stop_channel_all();
160 void    ds_set_volume( int channel, int vol );
161 void    ds_set_pan( int channel, int pan );
162 int     ds_get_pitch(int channel);
163 void    ds_set_pitch(int channel, int pitch);
164 void    ds_chg_loop_status(int channel, int loop);
165 void  ds_set_position(int channel, DWORD offset);
166 DWORD ds_get_play_position(int channel);
167 DWORD ds_get_write_position(int channel);
168 int     ds_get_data(int sid, char *data);
169 int     ds_get_size(int sid, int *size);
170
171 int     ds_create_buffer(int frequency, int bits_per_sample, int nchannels, int nseconds);
172 int     ds_lock_data(int sid, unsigned char *data, int size);
173 int     ds_play_easy(int sid, int volume);
174 void    ds_stop_easy(int sid);
175 int     ds_get_channel_size(int channel);
176 int     ds_is_3d_buffer(int sid);
177 int     ds_using_ds3d();
178 bool    ds_using_a3d();
179
180 unsigned int ds_get_primary_buffer_interface();
181 unsigned int ds_get_dsound_interface();
182 unsigned int ds_get_property_set_interface();
183
184 // Returns the number of channels that are actually playing
185 int ds_get_number_channels();
186
187 int ds3d_play( int sid, int hid, int snd_id, vector *pos, vector *vel, int min, int max, int looping, int max_volume, int estimated_vol, int priority=DS_MUST_PLAY );
188
189 // Get a character string for the error code
190 char    *get_DSERR_text(int DSResult);
191
192 void ds_do_frame();
193
194 // --------------------
195 //
196 // Creative eax.h
197 //
198 // --------------------
199
200 // EAX (listener) reverb property set {4a4e6fc1-c341-11d1-b73a-444553540000}
201 #ifndef PLAT_UNIX
202 DEFINE_GUID(DSPROPSETID_EAX_ReverbProperties, 
203     0x4a4e6fc1,
204     0xc341,
205     0x11d1,
206     0xb7, 0x3a, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00);
207 #endif
208
209 typedef enum 
210 {
211     DSPROPERTY_EAX_ALL,                // all reverb properties
212     DSPROPERTY_EAX_ENVIRONMENT,        // standard environment no.
213     DSPROPERTY_EAX_VOLUME,             // loudness of the reverb
214     DSPROPERTY_EAX_DECAYTIME,          // how long the reverb lasts
215     DSPROPERTY_EAX_DAMPING             // the high frequencies decay faster
216 } DSPROPERTY_EAX_REVERBPROPERTY;
217
218 #define EAX_NUM_STANDARD_PROPERTIES (DSPROPERTY_EAX_DAMPING + 1)
219
220 // use this structure for get/set all properties...
221 typedef struct 
222 {
223     unsigned long environment;          // 0 to EAX_ENVIRONMENT_COUNT-1
224     float fVolume;                      // 0 to 1
225     float fDecayTime_sec;               // seconds, 0.1 to 100
226     float fDamping;                     // 0 to 1
227 } EAX_REVERBPROPERTIES;
228
229
230 enum
231 {
232     EAX_ENVIRONMENT_GENERIC,
233     EAX_ENVIRONMENT_PADDEDCELL,
234     EAX_ENVIRONMENT_ROOM,
235     EAX_ENVIRONMENT_BATHROOM,
236     EAX_ENVIRONMENT_LIVINGROOM,
237     EAX_ENVIRONMENT_STONEROOM,
238     EAX_ENVIRONMENT_AUDITORIUM,
239     EAX_ENVIRONMENT_CONCERTHALL,
240     EAX_ENVIRONMENT_CAVE,
241     EAX_ENVIRONMENT_ARENA,
242     EAX_ENVIRONMENT_HANGAR,
243     EAX_ENVIRONMENT_CARPETEDHALLWAY,
244     EAX_ENVIRONMENT_HALLWAY,
245     EAX_ENVIRONMENT_STONECORRIDOR,
246     EAX_ENVIRONMENT_ALLEY,
247     EAX_ENVIRONMENT_FOREST,
248     EAX_ENVIRONMENT_CITY,
249     EAX_ENVIRONMENT_MOUNTAINS,
250     EAX_ENVIRONMENT_QUARRY,
251     EAX_ENVIRONMENT_PLAIN,
252     EAX_ENVIRONMENT_PARKINGLOT,
253     EAX_ENVIRONMENT_SEWERPIPE,
254     EAX_ENVIRONMENT_UNDERWATER,
255     EAX_ENVIRONMENT_DRUGGED,
256     EAX_ENVIRONMENT_DIZZY,
257     EAX_ENVIRONMENT_PSYCHOTIC,
258
259     EAX_ENVIRONMENT_COUNT           // total number of environments
260 };
261
262 #define EAX_MAX_ENVIRONMENT (EAX_ENVIRONMENT_COUNT - 1)
263
264 // EAX buffer reverb property set {4a4e6fc0-c341-11d1-b73a-444553540000}
265 #ifndef PLAT_UNIX
266 DEFINE_GUID(DSPROPSETID_EAXBUFFER_ReverbProperties, 
267     0x4a4e6fc0,
268     0xc341,
269     0x11d1,
270     0xb7, 0x3a, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00);
271 #endif
272
273 typedef enum 
274 {
275     DSPROPERTY_EAXBUFFER_ALL,           // all reverb buffer properties
276     DSPROPERTY_EAXBUFFER_REVERBMIX      // the wet source amount
277 } DSPROPERTY_EAXBUFFER_REVERBPROPERTY;
278
279 // use this structure for get/set all properties...
280 typedef struct 
281 {
282     float fMix;                          // linear factor, 0.0F to 1.0F
283 } EAXBUFFER_REVERBPROPERTIES;
284
285 #define EAX_REVERBMIX_USEDISTANCE -1.0F // out of normal range
286                                          // signifies the reverb engine should
287                                          // calculate it's own reverb mix value
288                                          // based on distance
289
290 // prototypes
291
292 int ds_eax_init();
293 void ds_eax_close();
294
295 int ds_eax_set_preset(unsigned long envid);
296
297 int ds_eax_set_volume(float volume);
298 int ds_eax_set_decay_time(float seconds);
299 int ds_eax_set_damping(float damp);
300 int ds_eax_set_environment(unsigned long envid);
301 int ds_eax_set_all(unsigned long id, float volume, float damping, float decay);
302 int ds_eax_get_all(EAX_REVERBPROPERTIES *er);
303 int ds_eax_is_inited();
304
305 #endif /* __DS_H__ */
306