2 * $Logfile: /Freespace2/code/Sound/Sound.h $
7 * <insert description of file here>
10 * Revision 1.2 2002/05/07 03:16:43 theoddone33
11 * The Great Newline Fix
13 * Revision 1.1.1.1 2002/05/03 03:28:12 root
17 * 6 9/08/99 3:22p Dave
18 * Updated builtin mission list.
20 * 5 8/27/99 6:38p Alanl
21 * crush the blasted repeating messages bug
23 * 4 6/18/99 5:16p Dave
24 * Added real beam weapon lighting. Fixed beam weapon sounds. Added MOTD
25 * dialog to PXO screen.
27 * 3 5/23/99 8:11p Alanl
28 * Added support for EAX
30 * 2 10/07/98 10:54a Dave
33 * 1 10/07/98 10:51a Dave
35 * 30 5/12/98 5:39p Lawrance
36 * Increase MAX_SOUNDS to 175.. to account for missions with lots of voice
38 * 29 5/12/98 2:43p Lawrance
39 * Make snd_time_remaining() work for arbitrary format
41 * 28 4/13/98 5:04p Lawrance
42 * Write functions to determine how many milliseconds are left in a sound
44 * 27 3/29/98 12:56a Lawrance
45 * preload the warp in and explosions sounds before a mission.
47 * 26 3/25/98 6:10p Lawrance
48 * Work on DirectSound3D
50 * 25 3/23/98 10:34a Lawrance
51 * fix parameter in snd_size()
53 * 24 3/23/98 10:32a Lawrance
54 * Add functions for extracting raw sound data
56 * 23 3/21/98 3:34p Lawrance
57 * Allow 3d sounds to have their ranges modified dynamically
59 * 22 3/19/98 5:36p Lawrance
60 * Add some sound debug functions to see how many sounds are playing, and
61 * to start/stop random looping sounds.
63 * 21 3/17/98 5:55p Lawrance
64 * Support object-linked sounds for asteroids.
66 * 20 2/20/98 8:32p Lawrance
67 * Add radius parm to sound_play_3d()
69 * 19 1/07/98 11:08a Lawrance
70 * pass priority to snd_play_raw()
72 * 18 12/05/97 5:19p Lawrance
73 * re-do sound priorities to make more general and extensible
75 * 17 11/20/97 5:36p Dave
76 * Hooked in a bunch of main hall changes (including sound). Made it
77 * possible to reposition (rewind/ffwd)
78 * sound buffer pointers. Fixed animation direction change framerate
81 * 16 11/20/97 1:06a Lawrance
82 * Add Master_voice_volume, make voices play back at correctly scaled
85 * 15 10/14/97 11:33p Lawrance
88 * 14 10/13/97 7:41p Lawrance
89 * store duration of sound
91 * 13 10/01/97 5:55p Lawrance
92 * change call to snd_play_3d() to allow for arbitrary listening position
94 * 12 7/15/97 11:15a Lawrance
95 * limit the max instances of simultaneous sound effects, implement
96 * priorities to force critical sounds
98 * 11 6/12/97 5:16p Lawrance
99 * allow snd_play_looping to take just one parm
101 * 10 6/09/97 11:50p Lawrance
102 * integrating DirectSound3D
104 * 9 6/05/97 11:25a Lawrance
105 * use sound signatures to ensure correct sound is loaded
107 * 8 6/05/97 1:36a Lawrance
108 * using a new interface to play sounds
110 * 7 6/05/97 1:08a Lawrance
111 * new sound play interface
113 * 6 6/02/97 1:45p Lawrance
114 * implementing hardware mixing
116 * 5 5/29/97 3:32p Lawrance
117 * added call to snd_do_frame()
119 * 4 5/29/97 12:04p Lawrance
120 * split off acm, direct sound, and direct sound 3d portions to separate
123 * 3 5/26/97 10:25a Lawrance
124 * extern ds_convert_volume()
126 * 2 5/06/97 9:36a Lawrance
127 * added support for min and max distances for 3d sounds
129 * 1 4/28/97 4:45p John
130 * Initial version of ripping sound & movie out of OsAPI.
132 * 18 4/24/97 4:14p Lawrance
133 * make ds_initialized extern
135 * 17 4/21/97 8:58a Lawrance
136 * keep track of how much mem is used for sounds
138 * 16 4/20/97 11:19a Lawrance
139 * sndman_ interface obsolete. Using snd_ functions to load, play, and
140 * manage static sound fx
142 * 15 4/18/97 2:54p Lawrance
143 * sounds now have a default volume, when playing, pass a scaling factor
144 * not the actual volume
146 * 14 4/09/97 4:34p Lawrance
147 * allow looped sounds to be cut off after they complete the full sample
150 * 13 4/03/97 4:27p Lawrance
151 * expanding functionality to support event driven music
153 * 12 3/25/97 10:49a Lawrance
154 * ADPCM -> PCM conversion working
156 * 11 3/24/97 5:50p Lawrance
157 * added code to convert from ADPCM -> PCM using Audio Compression Manager
159 * 10 3/19/97 11:48a Lawrance
160 * make each sound effect have a DirectSound secondary buffer
162 * 9 3/10/97 4:16p Allender
163 * new messaging system. builtin5 fixed to support it. made new sound
164 * function to determine if sound is still playing.
166 * 8 2/25/97 11:13a Lawrance
167 * added Master_sound_volume to scale volume passed to snd_play()
169 * 7 1/10/97 10:44a John
170 * added functions to dynamically set volume/pan
172 * 6 12/03/96 3:50p John
173 * Added some initial support for looping sounds.
175 * 5 11/05/96 11:02a Mike
176 * Add sound toggle to Delete-D menu.
177 * Make some global variables look global - ie, capitalize them.
178 * Fix bug in collision code to make ship:ship collision detection work.
179 * Fix setting of parent_obj in obj_create().
181 * 4 11/04/96 3:16p John
182 * First rev of working sound.
184 * 3 11/04/96 10:37a John
185 * Closed the DirectSound object on program termination.
187 * 2 10/30/96 5:27p John
188 * some hacked in sound stuff so i can experiment with directsound.
190 * 1 10/28/96 11:36a John
198 #define MAX_SOUNDS 256
200 // Used for keeping track which low-level sound library is being used
201 #define SOUND_LIB_DIRECTSOUND 0
202 #define SOUND_LIB_RSX 1
204 #define GAME_SND_USE_DS3D (1<<1)
205 #define GAME_SND_VOICE (1<<2)
207 // Priorities that can be passed to snd_play() functions to limit how many concurrent sounds of a
208 // given type are played.
209 #define SND_PRIORITY_MUST_PLAY 0
210 #define SND_PRIORITY_SINGLE_INSTANCE 1
211 #define SND_PRIORITY_DOUBLE_INSTANCE 2
212 #define SND_PRIORITY_TRIPLE_INSTANCE 3
214 typedef struct game_snd
216 int sig; // number of sound in sounds.tbl (not used)
217 char filename[MAX_FILENAME_LEN];
218 float default_volume; // range: 0.0 -> 1.0
219 int min, max; // min: distance at which sound will stop getting louder max: distance at which sound is inaudible
220 int preload; // preload sound (ie read from disk before mission starts)
221 int id; // index into Sounds[], where sound data is stored
222 int id_sig; // signature of Sounds[] element
226 typedef struct sound_env
234 extern int Sound_enabled;
235 extern float Master_sound_volume; // 0 -> 1.0
236 extern float Master_voice_volume; // 0 -> 1.0
237 extern int Snd_sram; // System memory consumed by sound data
238 extern int Snd_hram; // Soundcard memory consumed by sound data
240 //int snd_load( char *filename, int hardware=0, int three_d=0, int *sig=NULL );
241 int snd_load( game_snd *gs, int allow_hardware_load = 0);
243 int snd_unload( int sndnum );
244 void snd_unload_all();
246 // Plays a sound with volume between 0 and 1.0, where 0 is the
247 // inaudible and 1.0 is the loudest sound in the game.
248 // Pan goes from -1.0 all the way left to 0.0 in center to 1.0 all the way right.
249 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 );
251 // Play a sound directly from index returned from snd_load(). Bypasses
252 // the sound management process of using game_snd.
253 int snd_play_raw( int soundnum, float pan, float vol_scale=1.0f, int priority = SND_PRIORITY_MUST_PLAY );
255 // Plays a sound with volume between 0 and 1.0, where 0 is the
256 // inaudible and 1.0 is the loudest sound in the game. It scales
257 // the pan and volume relative to the current viewer's location.
258 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 );
260 // update the given 3d sound with a new position
261 void snd_update_3d_pos(int soudnnum, game_snd *gs, vector *new_pos);
263 // Use these for looping sounds.
264 // Returns the handle of the sound. -1 if failed.
265 // If startloop or stoploop are not -1, then then are used.
266 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 );
268 void snd_stop( int snd_handle );
270 // Sets the volume of a sound that is already playing.
271 // The volume is between 0 and 1.0, where 0 is the
272 // inaudible and 1.0 is the loudest sound in the game.
273 void snd_set_volume( int snd_handle, float volume );
275 // Sets the panning location of a sound that is already playing.
276 // Pan goes from -1.0 all the way left to 0.0 in center to 1.0 all the way right.
277 void snd_set_pan( int snd_handle, float pan );
279 // Sets the pitch (frequency) of a sound that is already playing
280 // Valid values for pitch are between 100 and 100000
281 void snd_set_pitch( int snd_handle, int pitch );
282 int snd_get_pitch( int snd_handle );
284 // Stops all sounds from playing, even looping ones.
287 // determines if the sound handle is still palying
288 int snd_is_playing( int snd_handle );
290 // change the looping status of a sound that is playing
291 void snd_chg_loop_status(int snd_handle, int loop);
293 // return the time in ms for the duration of the sound
294 int snd_get_duration(int snd_id);
296 // get a 3D vol and pan for a particular sound
297 int snd_get_3d_vol_and_pan(game_snd *gs, vector *pos, float* vol, float *pan, float radius=0.0f);
299 int snd_init(int use_a3d, int use_eax);
302 // Return 1 or 0 to show that sound system is inited ok
305 // Returns a pointer to the direct sound object
308 void snd_update_listener(vector *pos, vector *vel, matrix *orient);
310 void snd_use_lib(int lib_id);
312 int snd_num_playing();
314 int snd_get_data(int handle, char *data);
315 int snd_size(int handle, int *size);
318 // repositioning of the sound buffer pointer
319 void snd_rewind(int snd_handle, game_snd *sg, float seconds); // rewind N seconds from the current position
320 void snd_ffwd(int snd_handle, game_snd *sg, float seconds); // fast forward N seconds from the current position
321 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
323 void snd_get_format(int handle, int *bits_per_sample, int *frequency);
324 int snd_time_remaining(int handle, int bits_per_sample=8, int frequency=11025);
341 SND_ENV_CARPETEDHALLWAY,
343 SND_ENV_STONECORRIDOR,
358 int sound_env_set(sound_env *se);
359 int sound_env_get(sound_env *se);
360 int sound_env_disable();
361 int sound_env_supported();