2 * $Logfile: /Freespace2/code/Sound/Sound.h $
7 * <insert description of file here>
10 * Revision 1.1 2002/05/03 03:28:12 root
14 * 6 9/08/99 3:22p Dave
15 * Updated builtin mission list.
17 * 5 8/27/99 6:38p Alanl
18 * crush the blasted repeating messages bug
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.
24 * 3 5/23/99 8:11p Alanl
25 * Added support for EAX
27 * 2 10/07/98 10:54a Dave
30 * 1 10/07/98 10:51a Dave
32 * 30 5/12/98 5:39p Lawrance
33 * Increase MAX_SOUNDS to 175.. to account for missions with lots of voice
35 * 29 5/12/98 2:43p Lawrance
36 * Make snd_time_remaining() work for arbitrary format
38 * 28 4/13/98 5:04p Lawrance
39 * Write functions to determine how many milliseconds are left in a sound
41 * 27 3/29/98 12:56a Lawrance
42 * preload the warp in and explosions sounds before a mission.
44 * 26 3/25/98 6:10p Lawrance
45 * Work on DirectSound3D
47 * 25 3/23/98 10:34a Lawrance
48 * fix parameter in snd_size()
50 * 24 3/23/98 10:32a Lawrance
51 * Add functions for extracting raw sound data
53 * 23 3/21/98 3:34p Lawrance
54 * Allow 3d sounds to have their ranges modified dynamically
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.
60 * 21 3/17/98 5:55p Lawrance
61 * Support object-linked sounds for asteroids.
63 * 20 2/20/98 8:32p Lawrance
64 * Add radius parm to sound_play_3d()
66 * 19 1/07/98 11:08a Lawrance
67 * pass priority to snd_play_raw()
69 * 18 12/05/97 5:19p Lawrance
70 * re-do sound priorities to make more general and extensible
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
78 * 16 11/20/97 1:06a Lawrance
79 * Add Master_voice_volume, make voices play back at correctly scaled
82 * 15 10/14/97 11:33p Lawrance
85 * 14 10/13/97 7:41p Lawrance
86 * store duration of sound
88 * 13 10/01/97 5:55p Lawrance
89 * change call to snd_play_3d() to allow for arbitrary listening position
91 * 12 7/15/97 11:15a Lawrance
92 * limit the max instances of simultaneous sound effects, implement
93 * priorities to force critical sounds
95 * 11 6/12/97 5:16p Lawrance
96 * allow snd_play_looping to take just one parm
98 * 10 6/09/97 11:50p Lawrance
99 * integrating DirectSound3D
101 * 9 6/05/97 11:25a Lawrance
102 * use sound signatures to ensure correct sound is loaded
104 * 8 6/05/97 1:36a Lawrance
105 * using a new interface to play sounds
107 * 7 6/05/97 1:08a Lawrance
108 * new sound play interface
110 * 6 6/02/97 1:45p Lawrance
111 * implementing hardware mixing
113 * 5 5/29/97 3:32p Lawrance
114 * added call to snd_do_frame()
116 * 4 5/29/97 12:04p Lawrance
117 * split off acm, direct sound, and direct sound 3d portions to separate
120 * 3 5/26/97 10:25a Lawrance
121 * extern ds_convert_volume()
123 * 2 5/06/97 9:36a Lawrance
124 * added support for min and max distances for 3d sounds
126 * 1 4/28/97 4:45p John
127 * Initial version of ripping sound & movie out of OsAPI.
129 * 18 4/24/97 4:14p Lawrance
130 * make ds_initialized extern
132 * 17 4/21/97 8:58a Lawrance
133 * keep track of how much mem is used for sounds
135 * 16 4/20/97 11:19a Lawrance
136 * sndman_ interface obsolete. Using snd_ functions to load, play, and
137 * manage static sound fx
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
143 * 14 4/09/97 4:34p Lawrance
144 * allow looped sounds to be cut off after they complete the full sample
147 * 13 4/03/97 4:27p Lawrance
148 * expanding functionality to support event driven music
150 * 12 3/25/97 10:49a Lawrance
151 * ADPCM -> PCM conversion working
153 * 11 3/24/97 5:50p Lawrance
154 * added code to convert from ADPCM -> PCM using Audio Compression Manager
156 * 10 3/19/97 11:48a Lawrance
157 * make each sound effect have a DirectSound secondary buffer
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.
163 * 8 2/25/97 11:13a Lawrance
164 * added Master_sound_volume to scale volume passed to snd_play()
166 * 7 1/10/97 10:44a John
167 * added functions to dynamically set volume/pan
169 * 6 12/03/96 3:50p John
170 * Added some initial support for looping sounds.
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().
178 * 4 11/04/96 3:16p John
179 * First rev of working sound.
181 * 3 11/04/96 10:37a John
182 * Closed the DirectSound object on program termination.
184 * 2 10/30/96 5:27p John
185 * some hacked in sound stuff so i can experiment with directsound.
187 * 1 10/28/96 11:36a John
195 #define MAX_SOUNDS 256
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
201 #define GAME_SND_USE_DS3D (1<<1)
202 #define GAME_SND_VOICE (1<<2)
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
211 typedef struct game_snd
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
223 typedef struct sound_env
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
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);
240 int snd_unload( int sndnum );
241 void snd_unload_all();
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 );
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 );
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 );
257 // update the given 3d sound with a new position
258 void snd_update_3d_pos(int soudnnum, game_snd *gs, vector *new_pos);
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 );
265 void snd_stop( int snd_handle );
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 );
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 );
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 );
281 // Stops all sounds from playing, even looping ones.
284 // determines if the sound handle is still palying
285 int snd_is_playing( int snd_handle );
287 // change the looping status of a sound that is playing
288 void snd_chg_loop_status(int snd_handle, int loop);
290 // return the time in ms for the duration of the sound
291 int snd_get_duration(int snd_id);
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);
296 int snd_init(int use_a3d, int use_eax);
299 // Return 1 or 0 to show that sound system is inited ok
302 // Returns a pointer to the direct sound object
305 void snd_update_listener(vector *pos, vector *vel, matrix *orient);
307 void snd_use_lib(int lib_id);
309 int snd_num_playing();
311 int snd_get_data(int handle, char *data);
312 int snd_size(int handle, int *size);
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
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);
338 SND_ENV_CARPETEDHALLWAY,
340 SND_ENV_STONECORRIDOR,
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();