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