| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/lib/hlsoundlib.h $ |
| 21 | * $Revision: 47 $ |
| 22 | * $Date: 3/20/00 12:26p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * Descent III Device-independant sound library |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/lib/hlsoundlib.h $ |
| 28 | * |
| 29 | * 47 3/20/00 12:26p Matt |
| 30 | * Merge of Duane's post-1.3 changes. |
| 31 | * Lower MAX_SOUND_OBJECTS for Mac (Mac only) |
| 32 | * |
| 33 | * 46 10/21/99 9:27p Jeff |
| 34 | * B.A. Macintosh code merge |
| 35 | * |
| 36 | * 45 5/10/99 10:53p Ardussi |
| 37 | * changes to compile on Mac |
| 38 | * |
| 39 | * 44 4/27/99 2:10p Samir |
| 40 | * added code to set the desired sound card given the descriptive name of |
| 41 | * a sound card. |
| 42 | * |
| 43 | * 43 4/12/99 7:14p Samir |
| 44 | * prioritization code added. |
| 45 | * |
| 46 | * 42 4/11/99 2:17p Chris |
| 47 | * Made max sounds 3000 DAMN! |
| 48 | * |
| 49 | * 41 4/10/99 5:09p Samir |
| 50 | * beginning to add prioritization of sounds code. currently non |
| 51 | * functional, but allows me to change all calls to Play3dSound so that I |
| 52 | * can test later. |
| 53 | * |
| 54 | * 40 4/01/99 6:37p Chris |
| 55 | * |
| 56 | * 39 4/01/99 6:37p Chris |
| 57 | * Increased max sound objects |
| 58 | * |
| 59 | * 38 4/01/99 4:28p Samir |
| 60 | * hardware geometry integration if it's available. |
| 61 | * |
| 62 | * 37 2/21/99 5:48p Matt |
| 63 | * Added SetVolumeObject() |
| 64 | * |
| 65 | * 36 1/30/99 3:44p Chris |
| 66 | * Added support for time-offset'ed 3d sounds (like start at 1.2 seconds |
| 67 | * into the sound) |
| 68 | * |
| 69 | * 35 1/29/99 12:48p Matt |
| 70 | * Rewrote the doorway system |
| 71 | * |
| 72 | * 34 1/26/99 5:16p Matt |
| 73 | * Added StopObjectSound() |
| 74 | * |
| 75 | * 33 1/12/99 4:04p Samir |
| 76 | * added environmental audio on a per room basis. |
| 77 | * |
| 78 | * 32 1/08/99 6:31p Samir |
| 79 | * added reverb |
| 80 | * |
| 81 | * 31 1/08/99 5:37p Samir |
| 82 | * reverb values per room. |
| 83 | * |
| 84 | * 30 11/16/98 4:29p Chris |
| 85 | * Added pause new flag to the high level system |
| 86 | * |
| 87 | * 29 11/13/98 2:27p Samir |
| 88 | * moved music stuff to d3music.h |
| 89 | * |
| 90 | * 28 10/16/98 5:42p Chris |
| 91 | * |
| 92 | * 27 8/18/98 12:17p Chris |
| 93 | * f_in_game for begin sound frame (to do 3d processing) |
| 94 | * |
| 95 | * 26 8/10/98 5:52p Samir |
| 96 | * added tension levels for music. |
| 97 | * |
| 98 | * 25 7/28/98 5:41p Samir |
| 99 | * change some music system protos. |
| 100 | * |
| 101 | * 24 7/24/98 5:26p Samir |
| 102 | * added some D3 music functions. |
| 103 | * |
| 104 | * 23 7/09/98 8:34p Samir |
| 105 | * added argument to callback for streams. |
| 106 | * |
| 107 | * 22 6/29/98 9:29a Chris |
| 108 | * Added some support for Direct Sound 3d |
| 109 | * |
| 110 | * 21 6/24/98 12:09p Chris |
| 111 | * Update |
| 112 | * |
| 113 | * 20 6/22/98 12:00p Chris |
| 114 | * Working on sound system to make it in a nice shape. |
| 115 | * |
| 116 | * 19 6/19/98 3:03p Chris |
| 117 | * Made CheckAndForceSoundDataAlloc a SoundSystem function - useful for |
| 118 | * multiple mixers. Added IsSoundPlaying to the high level sound lib. |
| 119 | * |
| 120 | * 18 6/17/98 7:04p Chris |
| 121 | * Added support for 8bit stream data to be played by our 16bit sound |
| 122 | * mixer |
| 123 | * |
| 124 | * 17 6/16/98 3:48p Chris |
| 125 | * Updated the sound system and added the start of sound streaming |
| 126 | * |
| 127 | * 16 3/20/98 2:59p Chris |
| 128 | * Added a wall hit sound for the player and added support for a base |
| 129 | * volume for 3d sounds |
| 130 | * |
| 131 | * 15 2/27/98 5:31p Chris |
| 132 | * Changed how master_volume is set. |
| 133 | * |
| 134 | * 14 2/23/98 6:32p Chris |
| 135 | * Added support for a hlsoundlib unique id. This is what all the public |
| 136 | * functions use. Also, looping sounds are now correctly turned off and |
| 137 | * on. |
| 138 | * |
| 139 | * 13 2/15/98 6:41p Chris |
| 140 | * Added Update2dSound |
| 141 | * |
| 142 | * 12 2/13/98 5:15p Chris |
| 143 | * Fixed multiple problems with looping sounds not being able to be |
| 144 | * stopped |
| 145 | * |
| 146 | * 11 1/19/98 10:04a Matt |
| 147 | * Added new object handle system |
| 148 | * |
| 149 | * 10 1/13/98 5:08p Chris |
| 150 | * Increased sound object limit |
| 151 | * |
| 152 | * 9 1/06/98 2:12p Chris |
| 153 | * Added muffled sounds v.1 and made 3d sounds keep their roomnum. |
| 154 | * |
| 155 | * 8 1/02/98 5:32p Chris |
| 156 | * More radical changes to the sound system |
| 157 | * |
| 158 | * 7 12/31/97 2:58a Chris |
| 159 | * Another major revision to the SoundLib. This cleaned up the code after |
| 160 | * removing the direct sound secondary buffers. |
| 161 | * |
| 162 | * 6 12/30/97 2:15p Chris |
| 163 | * Adding further support for software 3d stuff |
| 164 | * |
| 165 | * 5 12/12/97 11:43a Chris |
| 166 | * Added support to toggle sndlib on/off |
| 167 | * |
| 168 | * 4 12/11/97 12:58p Chris |
| 169 | * Added support for fixed 3d position updating sounds. |
| 170 | * |
| 171 | * 3 12/10/97 4:47p Chris |
| 172 | * Revision 1.0 of new sound library (no hardware -- uses primary buffer |
| 173 | * streaming) |
| 174 | * |
| 175 | * 2 11/21/97 1:10p Chris |
| 176 | * Incremental Improvements |
| 177 | * |
| 178 | * 20 6/11/97 1:07p Samir |
| 179 | * The removal of gameos and replaced with oeApplication, oeDatabase |
| 180 | * |
| 181 | * 19 5/22/97 6:18p Chris |
| 182 | * |
| 183 | * 18 5/22/97 5:15p Chris |
| 184 | * |
| 185 | * 17 5/15/97 1:59a Chris |
| 186 | * |
| 187 | * 16 4/29/97 8:03a Chris |
| 188 | * Improved the sound code. High-level sound now |
| 189 | * fully uses the flags in the sound page and it |
| 190 | * resulted in a simpilier coding interface :) |
| 191 | * |
| 192 | * 15 4/28/97 11:21a Chris |
| 193 | * Incremental improvements is the sound system |
| 194 | * |
| 195 | * 14 4/24/97 3:25a Chris |
| 196 | * // Added some more support for 3d sounds |
| 197 | * |
| 198 | * 13 4/03/97 8:37p Chris |
| 199 | * Added the Main_OS object pass in the sound library |
| 200 | * initialization code. |
| 201 | * |
| 202 | * 12 3/15/97 1:34p Chris |
| 203 | * |
| 204 | * $NoKeywords: $ |
| 205 | */ |
| 206 | |
| 207 | #ifndef __HLSOUNDLIB_H__ |
| 208 | #define __HLSOUNDLIB_H__ |
| 209 | |
| 210 | #include "ssl_lib.h" |
| 211 | #include "object.h" |
| 212 | |
| 213 | ////////////////////////////////////////////////////////////////////////// |
| 214 | |
| 215 | #define MAX_SOUNDS_MIXED 40 |
| 216 | #define MIN_SOUNDS_MIXED 20 |
| 217 | #define MAX_SOUND_OBJECTS 3000 |
| 218 | |
| 219 | extern char Sound_quality; |
| 220 | extern char Sound_mixer; |
| 221 | extern char Sound_card_name[]; |
| 222 | |
| 223 | class sound_object { |
| 224 | public: |
| 225 | sound_object() { m_obj_type_flags = SIF_UNUSED; } |
| 226 | |
| 227 | public: |
| 228 | uint32_t m_obj_type_flags; |
| 229 | int m_sound_uid; |
| 230 | int m_sound_index; |
| 231 | int m_hlsound_uid; |
| 232 | |
| 233 | play_information play_info; |
| 234 | |
| 235 | float volume_3d; // Used so that 3d sounds can have a base volume (for 2d this is in play_information) |
| 236 | |
| 237 | union { |
| 238 | struct { |
| 239 | int segnum; // Use physics' bit-bit stuff (inside/outside) |
| 240 | vector pos; |
| 241 | matrix orient; // only need pitch and heading -- not roll (sound cones are symetrical) |
| 242 | } pos_info; |
| 243 | |
| 244 | int object_handle; |
| 245 | } m_link_info; |
| 246 | }; |
| 247 | |
| 248 | class hlsSystem { |
| 249 | int m_f_hls_system_init; |
| 250 | |
| 251 | class sound_object m_sound_objects[MAX_SOUND_OBJECTS]; |
| 252 | |
| 253 | float m_master_volume; |
| 254 | int m_sounds_played; |
| 255 | |
| 256 | bool m_pause_new; |
| 257 | uint8_t m_cur_environment; // current environment being played. |
| 258 | int n_lls_sounds; // number of sounds that we want the low level mixer to mix. |
| 259 | |
| 260 | bool Emulate3dSound(int sound_obj_index); |
| 261 | bool ComputePlayInfo(int sound_obj_index, vector *virtual_pos, vector *virtual_vel, float *adjusted_volume); |
| 262 | |
| 263 | inline int MakeUniqueId(int sound_obj_index); |
| 264 | inline int ValidateUniqueId(int hl_sound_uid); |
| 265 | |
| 266 | // Forcefully ends a sound |
| 267 | void StopSound(int sound_obj_index, uint8_t f_immediately = SKT_STOP_IMMEDIATELY); |
| 268 | |
| 269 | private: |
| 270 | int Play3dSound(int sound_index, pos_state *cur_pos, object *cur_obj, int priority, float volume, int flags, |
| 271 | float offset = 0.0); |
| 272 | |
| 273 | public: |
| 274 | // Include a lowel-level sound system |
| 275 | class llsSystem *m_ll_sound_ptr; |
| 276 | |
| 277 | hlsSystem(); // {m_f_hls_system_init = 0; m_sounds_played=0; m_master_volume = 1.0; m_pause_new = false;} |
| 278 | ~hlsSystem() { KillSoundLib(true); } |
| 279 | |
| 280 | bool IsActive(void); |
| 281 | |
| 282 | // Start and clean-up after the sound library |
| 283 | int InitSoundLib(oeApplication *sos, char mixer_type, char quality, bool f_kill_sound_lib = false); |
| 284 | void KillSoundLib(bool f_kill_sound_list); |
| 285 | void SetLLSoundQuantity(int n_sounds); |
| 286 | int GetLLSoundQuantity(); |
| 287 | |
| 288 | bool SetLLevelType(); // These are |
| 289 | |
| 290 | // Pause and Resume the library |
| 291 | void PauseSounds(bool f_all_sounds = false); |
| 292 | void ResumeSounds(); |
| 293 | void StopAllSounds(); |
| 294 | |
| 295 | // Code for the beginning and ending of a frame of action |
| 296 | |
| 297 | // Begin_sound_frame(listener pos/orient/velocity) |
| 298 | // SyncSounds |
| 299 | // Do sound pos updates -- IF VOLUME IS LOW AND NOT FOREVER, THEN STOP SOUND |
| 300 | // compute echo / reverb |
| 301 | // indirect/direct path sounds |
| 302 | void BeginSoundFrame(bool f_in_game = true); |
| 303 | |
| 304 | // Plays the deffered 3d stuff |
| 305 | void EndSoundFrame(); |
| 306 | |
| 307 | // Functions that play a sound |
| 308 | |
| 309 | // 3d functions (we use the sound flags in the page to determine all the cool stuff) |
| 310 | // Functions that play a 3d sound -- includes the 2d emulation of 3d sound |
| 311 | int Play3dSound(int sound_index, pos_state *cur_pos, float volume = MAX_GAME_VOLUME, int flags = 0, |
| 312 | float offset = 0.0); |
| 313 | int Play3dSound(int sound_index, object *cur_obj, float volume = MAX_GAME_VOLUME, int flags = 0, float offset = 0.0); |
| 314 | |
| 315 | int Play3dSound(int sound_index, int priority, pos_state *cur_pos, float volume = MAX_GAME_VOLUME, int flags = 0, |
| 316 | float offset = 0.0); |
| 317 | int Play3dSound(int sound_index, int priority, object *cur_obj, float volume = MAX_GAME_VOLUME, int flags = 0, |
| 318 | float offset = 0.0); |
| 319 | |
| 320 | int PlayStream(int unique_handle, void *data, int size, int stream_format, float volume, |
| 321 | void *stream_callback(void *user_data, int handle, int *size) = NULL); |
| 322 | |
| 323 | // 2d functions |
| 324 | int Play2dSound(int sound_index, float volume = MAX_GAME_VOLUME / 2, float pan = 0.0, |
| 325 | uint16_t frequency = 22050); |
| 326 | |
| 327 | int Play2dSound(int sound_index, int priority, float volume = MAX_GAME_VOLUME / 2, float pan = 0.0, |
| 328 | uint16_t frequency = 22050); |
| 329 | |
| 330 | int Update2dSound(int hlsound_uid, float volume, float pan); |
| 331 | |
| 332 | // Do nice looping stop stuff |
| 333 | void StopSoundLooping(int hlsound_uid); |
| 334 | void StopSoundImmediate(int hlsound_uid); |
| 335 | |
| 336 | // Stop all sounds attached to an object |
| 337 | void StopObjectSound(int objhandle); |
| 338 | |
| 339 | // Set the volume for all the sounds attached to an object |
| 340 | void SetVolumeObject(int objhandle, float volume); |
| 341 | |
| 342 | // Master volume controls for sound effects |
| 343 | void SetMasterVolume(float volume); |
| 344 | float GetMasterVolume(); |
| 345 | |
| 346 | // Queued sound functions |
| 347 | void Add2dSoundQueued(int q_num, int sound_index, float volume, float pan, uint16_t frequency); |
| 348 | void KillQueue(int q_num = 0); |
| 349 | void KillAllQueues(); |
| 350 | |
| 351 | bool CheckAndForceSoundDataAlloc(int sound_file_index); |
| 352 | bool SetSoundQuality(char quality); |
| 353 | char GetSoundQuality(void); |
| 354 | bool SetSoundMixer(char mixer_type); |
| 355 | char GetSoundMixer(void); |
| 356 | |
| 357 | bool IsSoundPlaying(int hlsound_uid); |
| 358 | |
| 359 | // Midi play stuff |
| 360 | void SetMidiVolume(); |
| 361 | void GetMidiVolume(); |
| 362 | void PlayMidi(); |
| 363 | void StopMidi(); |
| 364 | void PauseMidi(); |
| 365 | void ResumeMidi(); |
| 366 | }; |
| 367 | |
| 368 | extern hlsSystem Sound_system; |
| 369 | |
| 370 | ////////////////////////////////////////////////////////////////////////// |
| 371 | // ENVIRONMENTAL REVERB PRESETS |
| 372 | |
| 373 | #define N_ENVAUDIO_PRESETS 26 |
| 374 | |
| 375 | #define ENVAUD_PRESET_NONE 0 |
| 376 | #define ENVAUD_PRESET_PADDEDCELL 1 |
| 377 | #define ENVAUD_PRESET_ROOM 2 |
| 378 | #define ENVAUD_PRESET_BATHROOM 3 |
| 379 | #define ENVAUD_PRESET_LIVINGROOM 4 |
| 380 | #define ENVAUD_PRESET_STONEROOM 5 |
| 381 | #define ENVAUD_PRESET_AUDITORIUM 6 |
| 382 | #define ENVAUD_PRESET_CONCERTHALL 7 |
| 383 | #define ENVAUD_PRESET_CAVE 8 |
| 384 | #define ENVAUD_PRESET_ARENA 9 |
| 385 | #define ENVAUD_PRESET_HANGAR 10 |
| 386 | #define ENVAUD_PRESET_CARPETEDHALLWAY 11 |
| 387 | #define ENVAUD_PRESET_HALLWAY 12 |
| 388 | #define ENVAUD_PRESET_STONECORRIDOR 13 |
| 389 | #define ENVAUD_PRESET_ALLEY 14 |
| 390 | #define ENVAUD_PRESET_FOREST 15 |
| 391 | #define ENVAUD_PRESET_CITY 16 |
| 392 | #define ENVAUD_PRESET_MOUNTAINS 17 |
| 393 | #define ENVAUD_PRESET_QUARRY 18 |
| 394 | #define ENVAUD_PRESET_PLAIN 19 |
| 395 | #define ENVAUD_PRESET_PARKINGLOT 20 |
| 396 | #define ENVAUD_PRESET_SEWERPIPE 21 |
| 397 | #define ENVAUD_PRESET_UNDERWATER 22 |
| 398 | #define ENVAUD_PRESET_DRUGGED 23 |
| 399 | #define ENVAUD_PRESET_DIZZY 24 |
| 400 | #define ENVAUD_PRESET_PSYCHOTIC 25 |
| 401 | |
| 402 | #endif |