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