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