]> icculus.org git repositories - taylor/freespace2.git/blob - include/sound.h
finished cfilesystem.
[taylor/freespace2.git] / include / sound.h
1 /*
2  * $Logfile: /Freespace2/code/Sound/Sound.h $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * <insert description of file here>
8  *
9  * $Log$
10  * Revision 1.3  2002/05/31 07:24:28  relnev
11  * warning
12  *
13  * Revision 1.2  2002/05/07 03:16:43  theoddone33
14  * The Great Newline Fix
15  *
16  * Revision 1.1.1.1  2002/05/03 03:28:12  root
17  * Initial import.
18  *
19  * 
20  * 6     9/08/99 3:22p Dave
21  * Updated builtin mission list.
22  * 
23  * 5     8/27/99 6:38p Alanl
24  * crush the blasted repeating messages bug
25  * 
26  * 4     6/18/99 5:16p Dave
27  * Added real beam weapon lighting. Fixed beam weapon sounds. Added MOTD
28  * dialog to PXO screen.
29  * 
30  * 3     5/23/99 8:11p Alanl
31  * Added support for EAX
32  * 
33  * 2     10/07/98 10:54a Dave
34  * Initial checkin.
35  * 
36  * 1     10/07/98 10:51a Dave
37  * 
38  * 30    5/12/98 5:39p Lawrance
39  * Increase MAX_SOUNDS to 175.. to account for missions with lots of voice
40  * 
41  * 29    5/12/98 2:43p Lawrance
42  * Make snd_time_remaining() work for arbitrary format
43  * 
44  * 28    4/13/98 5:04p Lawrance
45  * Write functions to determine how many milliseconds are left in a sound
46  * 
47  * 27    3/29/98 12:56a Lawrance
48  * preload the warp in and explosions sounds before a mission.
49  * 
50  * 26    3/25/98 6:10p Lawrance
51  * Work on DirectSound3D
52  * 
53  * 25    3/23/98 10:34a Lawrance
54  * fix parameter in snd_size()
55  * 
56  * 24    3/23/98 10:32a Lawrance
57  * Add functions for extracting raw sound data
58  * 
59  * 23    3/21/98 3:34p Lawrance
60  * Allow 3d sounds to have their ranges modified dynamically
61  * 
62  * 22    3/19/98 5:36p Lawrance
63  * Add some sound debug functions to see how many sounds are playing, and
64  * to start/stop random looping sounds.
65  * 
66  * 21    3/17/98 5:55p Lawrance
67  * Support object-linked sounds for asteroids.
68  * 
69  * 20    2/20/98 8:32p Lawrance
70  * Add radius parm to sound_play_3d()
71  * 
72  * 19    1/07/98 11:08a Lawrance
73  * pass priority to snd_play_raw()
74  * 
75  * 18    12/05/97 5:19p Lawrance
76  * re-do sound priorities to make more general and extensible
77  * 
78  * 17    11/20/97 5:36p Dave
79  * Hooked in a bunch of main hall changes (including sound). Made it
80  * possible to reposition (rewind/ffwd) 
81  * sound buffer pointers. Fixed animation direction change framerate
82  * problem.
83  * 
84  * 16    11/20/97 1:06a Lawrance
85  * Add Master_voice_volume, make voices play back at correctly scaled
86  * volumes
87  * 
88  * 15    10/14/97 11:33p Lawrance
89  * get RSX implemented
90  * 
91  * 14    10/13/97 7:41p Lawrance
92  * store duration of sound
93  * 
94  * 13    10/01/97 5:55p Lawrance
95  * change call to snd_play_3d() to allow for arbitrary listening position
96  * 
97  * 12    7/15/97 11:15a Lawrance
98  * limit the max instances of simultaneous sound effects, implement
99  * priorities to force critical sounds
100  * 
101  * 11    6/12/97 5:16p Lawrance
102  * allow snd_play_looping to take just one parm
103  * 
104  * 10    6/09/97 11:50p Lawrance
105  * integrating DirectSound3D
106  * 
107  * 9     6/05/97 11:25a Lawrance
108  * use sound signatures to ensure correct sound is loaded
109  * 
110  * 8     6/05/97 1:36a Lawrance
111  * using a new interface to play sounds
112  * 
113  * 7     6/05/97 1:08a Lawrance
114  * new sound play interface
115  * 
116  * 6     6/02/97 1:45p Lawrance
117  * implementing hardware mixing
118  * 
119  * 5     5/29/97 3:32p Lawrance
120  * added call to snd_do_frame()
121  * 
122  * 4     5/29/97 12:04p Lawrance
123  * split off acm, direct sound, and direct sound 3d portions to separate
124  * files
125  * 
126  * 3     5/26/97 10:25a Lawrance
127  * extern ds_convert_volume() 
128  * 
129  * 2     5/06/97 9:36a Lawrance
130  * added support for min and max distances for 3d sounds
131  * 
132  * 1     4/28/97 4:45p John
133  * Initial version of ripping sound & movie out of OsAPI.
134  * 
135  * 18    4/24/97 4:14p Lawrance
136  * make ds_initialized extern
137  * 
138  * 17    4/21/97 8:58a Lawrance
139  * keep track of how much mem is used for sounds
140  * 
141  * 16    4/20/97 11:19a Lawrance
142  * sndman_ interface obsolete.  Using snd_ functions to load, play, and
143  * manage static sound fx
144  * 
145  * 15    4/18/97 2:54p Lawrance
146  * sounds now have a default volume, when playing, pass a scaling factor
147  * not the actual volume
148  * 
149  * 14    4/09/97 4:34p Lawrance
150  * allow looped sounds to be cut off after they complete the full sample
151  * duration
152  * 
153  * 13    4/03/97 4:27p Lawrance
154  * expanding functionality to support event driven music
155  * 
156  * 12    3/25/97 10:49a Lawrance
157  * ADPCM -> PCM conversion working
158  * 
159  * 11    3/24/97 5:50p Lawrance
160  * added code to convert from ADPCM -> PCM using Audio Compression Manager
161  * 
162  * 10    3/19/97 11:48a Lawrance
163  * make each sound effect have a DirectSound secondary buffer
164  * 
165  * 9     3/10/97 4:16p Allender
166  * new messaging system.  builtin5 fixed to support it.  made new sound
167  * function to determine if sound is still playing.
168  * 
169  * 8     2/25/97 11:13a Lawrance
170  * added Master_sound_volume to scale volume passed to snd_play()
171  * 
172  * 7     1/10/97 10:44a John
173  * added functions to dynamically set volume/pan
174  * 
175  * 6     12/03/96 3:50p John
176  * Added some initial support for looping sounds.
177  * 
178  * 5     11/05/96 11:02a Mike
179  * Add sound toggle to Delete-D menu.
180  * Make some global variables look global - ie, capitalize them.
181  * Fix bug in collision code to make ship:ship collision detection work.
182  * Fix setting of parent_obj in obj_create().
183  * 
184  * 4     11/04/96 3:16p John
185  * First rev of working sound.
186  * 
187  * 3     11/04/96 10:37a John
188  * Closed the DirectSound object on program termination.
189  * 
190  * 2     10/30/96 5:27p John
191  * some hacked in sound stuff so i can experiment with directsound.
192  * 
193  * 1     10/28/96 11:36a John
194  *
195  * $NoKeywords: $
196  */
197
198 #ifndef __SOUND_H__
199 #define __SOUND_H__
200
201 #define MAX_SOUNDS      256
202
203 // Used for keeping track which low-level sound library is being used
204 #define SOUND_LIB_DIRECTSOUND           0
205 #define SOUND_LIB_RSX                           1
206
207 #define GAME_SND_USE_DS3D                       (1<<1)
208 #define GAME_SND_VOICE                          (1<<2)
209
210 // Priorities that can be passed to snd_play() functions to limit how many concurrent sounds of a 
211 // given type are played.
212 #define SND_PRIORITY_MUST_PLAY                          0
213 #define SND_PRIORITY_SINGLE_INSTANCE            1
214 #define SND_PRIORITY_DOUBLE_INSTANCE            2
215 #define SND_PRIORITY_TRIPLE_INSTANCE            3
216
217 typedef struct game_snd
218 {
219         int     sig;                                            // number of sound in sounds.tbl (not used)
220         char    filename[MAX_FILENAME_LEN];
221         float   default_volume;         // range: 0.0 -> 1.0
222         int     min, max;                               // min: distance at which sound will stop getting louder  max: distance at which sound is inaudible
223         int     preload;                                        // preload sound (ie read from disk before mission starts)
224         int     id;                                             // index into Sounds[], where sound data is stored
225         int     id_sig;                                 // signature of Sounds[] element
226         int     flags;
227 } game_snd;
228
229 typedef struct sound_env
230 {
231         unsigned long id;
232         float volume;
233         float damping;
234         float decay;
235 } sound_env;
236
237 extern int              Sound_enabled;
238 extern float    Master_sound_volume;            // 0 -> 1.0
239 extern float    Master_voice_volume;            // 0 -> 1.0
240 extern int              Snd_sram;                                       // System memory consumed by sound data 
241 extern int              Snd_hram;                                       // Soundcard memory consumed by sound data
242
243 //int   snd_load( char *filename, int hardware=0, int three_d=0, int *sig=NULL );
244 int     snd_load( game_snd *gs, int allow_hardware_load = 0);
245
246 int     snd_unload( int sndnum );
247 void    snd_unload_all();
248
249 // Plays a sound with volume between 0 and 1.0, where 0 is the
250 // inaudible and 1.0 is the loudest sound in the game.
251 // Pan goes from -1.0 all the way left to 0.0 in center to 1.0 all the way right.
252 int snd_play( game_snd *gs, float pan=0.0f, float vol_scale=1.0f, int priority = SND_PRIORITY_SINGLE_INSTANCE, bool voice_message = false );
253
254 // Play a sound directly from index returned from snd_load().  Bypasses
255 // the sound management process of using game_snd.
256 int snd_play_raw( int soundnum, float pan, float vol_scale=1.0f, int priority = SND_PRIORITY_MUST_PLAY );
257
258 // Plays a sound with volume between 0 and 1.0, where 0 is the
259 // inaudible and 1.0 is the loudest sound in the game.  It scales
260 // the pan and volume relative to the current viewer's location.
261 int snd_play_3d(game_snd *gs, vector *source_pos, vector *listen_pos, float radius=0.0f, vector *vel = NULL, int looping = 0, float vol_scale=1.0f, int priority = SND_PRIORITY_SINGLE_INSTANCE, vector *sound_fvec = NULL, float range_factor = 1.0f, int force = 0 );
262
263 // update the given 3d sound with a new position
264 void snd_update_3d_pos(int soudnnum, game_snd *gs, vector *new_pos);
265
266 // Use these for looping sounds.
267 // Returns the handle of the sound. -1 if failed.
268 // If startloop or stoploop are not -1, then then are used.
269 int     snd_play_looping( game_snd *gs, float pan=0.0f, int start_loop=-1, int stop_loop=-1, float vol_scale=1.0f, int priority = SND_PRIORITY_MUST_PLAY, int force = 0 );
270
271 void    snd_stop( int snd_handle );
272
273 // Sets the volume of a sound that is already playing.
274 // The volume is between 0 and 1.0, where 0 is the
275 // inaudible and 1.0 is the loudest sound in the game.
276 void snd_set_volume( int snd_handle, float volume );
277
278 // Sets the panning location of a sound that is already playing.
279 // Pan goes from -1.0 all the way left to 0.0 in center to 1.0 all the way right.
280 void snd_set_pan( int snd_handle, float pan );
281
282 // Sets the pitch (frequency) of a sound that is already playing
283 // Valid values for pitch are between 100 and 100000
284 void    snd_set_pitch( int snd_handle, int pitch );
285 int     snd_get_pitch( int snd_handle );
286
287 // Stops all sounds from playing, even looping ones.
288 void    snd_stop_all();
289
290 // determines if the sound handle is still palying
291 int     snd_is_playing( int snd_handle );
292
293 // change the looping status of a sound that is playing
294 void    snd_chg_loop_status(int snd_handle, int loop);
295
296 // return the time in ms for the duration of the sound
297 int snd_get_duration(int snd_id);
298
299 // get a 3D vol and pan for a particular sound
300 int     snd_get_3d_vol_and_pan(game_snd *gs, vector *pos, float* vol, float *pan, float radius=0.0f);
301
302 int     snd_init(int use_a3d, int use_eax);
303 void    snd_close();
304
305 // Return 1 or 0 to show that sound system is inited ok
306 int     snd_is_inited();
307
308 // Returns a pointer to the direct sound object
309 uint    sound_get_ds();
310
311 void    snd_update_listener(vector *pos, vector *vel, matrix *orient);
312
313 void    snd_use_lib(int lib_id);
314
315 int snd_num_playing();
316
317 int snd_get_data(int handle, char *data);
318 int snd_size(int handle, int *size);
319 void snd_do_frame();
320
321 // repositioning of the sound buffer pointer
322 void snd_rewind(int snd_handle, game_snd *sg, float seconds);                                   // rewind N seconds from the current position
323 void snd_ffwd(int snd_handle, game_snd *sg, float seconds);                                             // fast forward N seconds from the current position
324 void snd_set_pos(int snd_handle, game_snd *sg, float val,int as_pct);           // set the position val as either a percentage (if as_pct) or as a # of seconds into the sound
325
326 void snd_get_format(int handle, int *bits_per_sample, int *frequency);
327 int snd_time_remaining(int handle, int bits_per_sample=8, int frequency=11025);
328
329 // sound environment
330
331 enum
332 {
333     SND_ENV_GENERIC,
334     SND_ENV_PADDEDCELL,
335     SND_ENV_ROOM,
336     SND_ENV_BATHROOM,
337     SND_ENV_LIVINGROOM,
338     SND_ENV_STONEROOM,
339     SND_ENV_AUDITORIUM,
340     SND_ENV_CONCERTHALL,
341     SND_ENV_CAVE,
342     SND_ENV_ARENA,
343     SND_ENV_HANGAR,
344     SND_ENV_CARPETEDHALLWAY,
345     SND_ENV_HALLWAY,
346     SND_ENV_STONECORRIDOR,
347     SND_ENV_ALLEY,
348     SND_ENV_FOREST,
349     SND_ENV_CITY,
350     SND_ENV_MOUNTAINS,
351     SND_ENV_QUARRY,
352     SND_ENV_PLAIN,
353     SND_ENV_PARKINGLOT,
354     SND_ENV_SEWERPIPE,
355     SND_ENV_UNDERWATER,
356     SND_ENV_DRUGGED,
357     SND_ENV_DIZZY,
358     SND_ENV_PSYCHOTIC
359 };
360
361 int sound_env_set(sound_env *se);
362 int sound_env_get(sound_env *se);
363 int sound_env_disable();
364 int sound_env_supported();
365
366 #endif
367