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