Debian Codegraph @

sndlib/soundload.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
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
19
20 /*
21 * $Logfile: /DescentIII/Main/sndlib/soundload.cpp $
22 * $Revision: 59 $
23 * $Date: 10/21/99 3:23p $
24 * $Author: Kevin $
25 *
26 * Code to load sounds
27 *
28 * $Log: /DescentIII/Main/sndlib/soundload.cpp $
29 *
30 * 59 10/21/99 3:23p Kevin
31 * Mac merge w/memory savings
32 *
33 * 58 5/11/99 12:10a Ardussi
34 * changes to compile on Mac
35 *
36 * 57 5/08/99 3:30p Matt
37 * Added weapon-hit-water sound.
38 *
39 * 56 4/30/99 3:28p Matt
40 * Weapons now make a special sound when colliding with lava & volatile
41 * surfaces, instead of the standard hit-wall sound.
42 *
43 * 55 4/29/99 3:50p Matt
44 * Added hiss sound for volatile surface damage
45 *
46 * 54 4/29/99 1:10p Jeff
47 * added sounds for inventory and countermeasure switch
48 *
49 * 53 4/14/99 1:46a Jeff
50 * fixed case mismatched #includes
51 *
52 * 52 4/12/99 4:18p Jason
53 * remap textures during sound remapping
54 *
55 * 51 4/11/99 5:03p Matt
56 * Changed static sound remapping code to use simpler & more
57 * space-efficient scheme. Also deleted an unused entry in the static
58 * sound list.
59 *
60 * 50 3/04/99 10:57a Matt
61 * Added goal message notification sound
62 *
63 * 49 2/22/99 10:24p Matt
64 * Added a static sound for debris explosion
65 *
66 * 48 2/18/99 4:48p Matt
67 * Changed the default import volume for new sounds to 100%
68 *
69 * 47 2/18/99 2:49p Matt
70 * Added goal complete sound
71 *
72 * 46 2/10/99 4:38p Matt
73 * Misc. changes for table file parsing
74 *
75 * 45 1/29/99 12:48p Matt
76 * Rewrote the doorway system
77 *
78 * 44 1/13/99 6:55a Jeff
79 * fixed #includes to work for linux
80 *
81 * 43 11/23/98 1:50p Jason
82 * added thruster sounds
83 *
84 * 42 10/22/98 8:31p Chris
85 * Sounds use GlobalAlloc and GlobalFree
86 *
87 * 41 10/21/98 4:53p Jeff
88 * added some sounds to sounds array
89 *
90 * 40 10/20/98 2:09p Jeff
91 * added 2 more sounds to static sounds
92 *
93 * 39 10/20/98 12:49p Matt
94 * Removed obsolete sounds from static sound list.
95 *
96 * 38 10/19/98 7:19p Matt
97 * Added system to support different types of damage to the player and
98 * have these different types make different sounds.
99 *
100 * 37 10/19/98 11:57a Chris
101 * Update the sound system to use the import volume
102 *
103 * 36 10/14/98 1:02p Jason
104 * fixed FindSoundName issues
105 *
106 * 35 10/12/98 1:27p Jeff
107 * all mem_free's do set the value to NULL after they are complete
108 *
109 * 34 9/21/98 8:19p Chris
110 * Improved volatile and forcefield hits
111 *
112 * 33 9/18/98 1:27p Matt
113 * Added afterburner release sound
114 *
115 * 32 9/08/98 12:05p Jason
116 * moved doorway.h out of room.h
117 *
118 * 31 7/24/98 5:22p Samir
119 * took out WAV file stuff because low level sound libray needs this code.
120 *
121 * 30 6/19/98 3:03p Chris
122 * Made CheckAndForceSoundDataAlloc a SoundSystem function - useful for
123 * multiple mixers. Added IsSoundPlaying to the high level sound lib.
124 *
125 * 29 6/17/98 4:39p Chris
126 * Added the playing of 8bit samples with the 16 bit sound mixer
127 *
128 * 28 5/26/98 10:54p Chris
129 * Ooops again
130 *
131 * 27 5/26/98 10:42p Chris
132 * Fixed door sound paging
133 *
134 * 26 5/26/98 10:21p Chris
135 * Added door sound paging
136 *
137 * 25 5/22/98 11:59a Chris
138 * Fixed improper uses of FindSoundName and made the proper static sounds
139 *
140 * 24 5/17/98 4:08p Chris
141 * Fixed bugs with initial sound loading. :)
142 *
143 * 23 5/14/98 1:28p Chris
144 * Improved sound loading stuff
145 *
146 * 22 5/14/98 11:49a Chris
147 * Bettered the sound paging system
148 *
149 * 21 5/03/98 10:22p Matt
150 * Added breaking glass sound
151 *
152 * 20 5/03/98 5:38p Chris
153 * Added sounds to anim page
154 *
155 * 19 4/24/98 3:02p Chris
156 * Removed GlobalAlloc and GlobalFree
157 *
158 * 18 4/22/98 5:38p Chris
159 * Fixed problems with adding new sounds
160 *
161 * 17 4/22/98 11:55a Jeff
162 * fixed stack overrun in ChangeSoundFileName
163 *
164 * 16 4/21/98 2:35p Chris
165 * Made soundload use the standard mem_malloc stuff
166 *
167 * 15 4/06/98 5:13p Chris
168 * Sounds page in at the beginning of a level
169 *
170 * 14 3/31/98 3:49p Jason
171 * added memory lib
172 *
173 * 13 3/02/98 4:16p Chris
174 * Added 14 new fields to the AI Settings Dialog/page.
175 *
176 * 12 2/23/98 5:03p Chris
177 * Added the global alloc calls (deifned them to malloc and free when not
178 * Win32)
179 *
180 * 11 2/16/98 4:55p Chris
181 * Added default sounds for explosions
182 *
183 * 10 2/12/98 4:23p Chris
184 * Fixed problem with sound dialog and allowing users to enter invalid
185 * values
186 *
187 * 9 1/02/98 5:32p Chris
188 * More radical changes to the sound system
189 *
190 * 8 12/31/97 2:58a Chris
191 * Another major revision to the SoundLib. This cleaned up the code after
192 * removing the direct sound secondary buffers.
193 *
194 * 7 12/30/97 2:15p Chris
195 * Adding further support for software 3d stuff
196 *
197 * 6 12/22/97 6:19p Chris
198 * Moved weapon battery firing sound off the projectile (weapon) and into
199 * the weapon battery.
200 *
201 * 5 12/19/97 4:09p Chris
202 * New dynamically loading sounds
203 *
204 * 4 12/10/97 4:47p Chris
205 * Revision 1.0 of new sound library (no hardware -- uses primary buffer
206 * streaming)
207 *
208 * 3 7/15/97 7:29p Chris
209 * Added a sound for helicopter blades.
210 *
211 * 13 5/29/97 3:26p Chris
212 *
213 * 12 5/29/97 3:11p Chris
214 * Fixed loadsound
215 *
216 * 11 5/22/97 3:29p Jason
217 * made sounds loading faster
218 *
219 * 10 5/14/97 11:31p Jason
220 * fixed annoying printf
221 *
222 * 9 5/14/97 12:31p Chris
223 *
224 * 8 5/13/97 10:31p Matt
225 * Added hook for refueling sound
226 *
227 * $NoKeywords: $
228 */
229
230 #include <cstring>
231
232 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
233 #include "ssl_lib.h"cxx . . $ `<file>/sndlib/ssl_lib.h`/
234 #include "object.h"cxx . . $ `<file>/Descent3/object.h`/
235 #include "ddio.h"cxx . . $ `<file>/ddio/ddio.h`/
236 #include "mem.h"cxx . . $ `<file>/mem/mem.h`/
237 #include "soundload.h"cxx . . $ `<file>/sndlib/soundload.h`/
238 #include "weapon.h"cxx . . $ `<file>/Descent3/weapon.h`/
239 #include "ship.h"cxx . . $ `<file>/Descent3/ship.h`/
240 #include "door.h"cxx . . $ `<file>/Descent3/door.h`/
241 #include "room.h"cxx . . $ `<file>/Descent3/room.h`/
242 #include "doorway.h"cxx . . $ `<file>/Descent3/doorway.h`/
243
244 #if defined(WIN32) || defined(POSIXcxx . . $ `<built-in>:478:9`!)
245 #include "../manage/soundpage.h"cxx . . $ `<file>/manage/soundpage.h`/
246 #include "../Descent3/sounds.h"cxx . . $ `<file>/Descent3/sounds.h`/
247 #endif
248
249 int Num_soundscxx . . $ Num_sounds. = 0;
250 int Num_sound_filescxx . . $ Num_sound_files. = 0;
251
252 const char *Static_sound_namescxx . . $ Static_sound_names.[NUM_STATIC_SOUNDScxx . . $ `Descent3/sounds.h:154:9`!] = {
253 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Default"), // 0 SOUND_NONE_INDEX
254 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Refuel"), // 1 SOUND_REFUELING
255 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("DefaultRobotExplode1"), // 2 SOUND_ROBOT_EXPLODE_1
256 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("DefaultRobotExplode2"), // 3 SOUND_ROBOT_EXPLODE_2
257 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("DefaultBuildingExplode"), // 4 SOUND_BUILDING_EXPLODE
258 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("BreakingGlass"), // 5 SOUND_BREAKING_GLASS
259 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Tear01"), // 6 SOUND_MELEE_HIT_0
260 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Tear02"), // 7 SOUND_MELEE_HIT_1
261 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Afterburner"), // 8 SOUND_AFTERBURNER
262 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Drop unknown "), // 9 SOUND_ENERGY_DRAIN
263 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Missle lock"), // 10 SOUND_MISSLE_LOCK
264 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Powerup pickup"), // 11 SOUND_POWERUP_PICKUP
265 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("You don't have it BEEP"), // 12 SOUND_DO_NOT_HAVE_IT
266 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Change primary weapon"), // 13 SOUND_CHANGE_PRIMARY
267 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Change secondary weapon"), // 14 SOUND_CHANGE_SECONDARY
268 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("HitWall"), // 15 SOUND_PLAYER_HIT_WALL
269 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("AftrBrnrTail"), // 16 SOUND_AFTERBURNER_TAIL
270 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Forcefield bounce"), // 17 SOUND_FORCEFIELD_BOUNCE
271 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Headlight1"), // 18 SOUND_HEADLIGHT
272 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Cheater!"), // 19 SOUND_CHEATER
273 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Energy Converter"), // 20 SOUND_ENERGY_CONVERTER
274 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("CockpitSequenceTest1"), // 21 SOUND_COCKPIT
275 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Metallic Door Hit"), // 22 SOUND_METALLIC_DOOR_HIT
276 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Wall Fade ???"), // 23 SOUND_WALL_FADE
277 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Raindrop"), // 24 SOUND_RAINDROP
278 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Lightning"), // 25 SOUND_LIGHTNING
279 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("HitEnergy"), // 26 SOUND_HIT_BY_ENERGY_WEAPON
280 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("HitMatter"), // 27 SOUND_HIT_BY_MATTER_WEAPON
281 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("HitConcussion"), // 28 SOUND_HIT_BY_CONCUSSIVE_FORCE
282 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("HitFire"), // 29 SOUND_PLAYER_BURNING
283 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Menu Slider Click"), // 30 SOUND_MENU_SOUND_CLICK
284 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Hostage pickup"), // 31 SOUND_HOSTAGE_PICKUP
285 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Briefstartup1"), // 32 SOUND_BRIEF_STARTUP
286 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("BriefStatic"), // 33 SOUND_BRIEF_STATIC
287 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Briefmonitoroff1"), // 34 SOUND_BRIEF_MONITOROFF
288 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Briefingrunning"), // 35 SOUND_BRIEF_RUNNING
289 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Briefbulb1"), // 36 SOUND_BRIEF_BULLB
290 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Briefingtype"), // 37 SOUND_BRIEF_TYPE
291 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("ShpIdle"), // 38 SHIP_IDLE
292 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("ShpForwardThrust"), // 39 SHIP_FORWARD_THRUST
293 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("ShpForwardThrRelease"), // 40 SHIP_FORWARD_THRUST_RELEASE
294 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("GoalComplete"), // 41 SOUND_GOAL_COMPLETE
295 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("DebrisExplosion"), // 42 SOUND_DEBRIS_EXPLODE
296 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("GameMessageNotify"), // 43 SOUND_GAME_MESSAGE
297 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Change countermeasure weapon"), // 44 SOUND_CHANGE_COUNTERMEASURE
298 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("Change inventory item"), // 45 SOUND_CHANGE_INVENTORY
299 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("VolatileHiss"), // 46 SOUND_VOLATILE_HISS
300 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("WeaponHitLava"), // 47 SOUND_WEAPON_HIT_LAVA
301 TBL_SOUNDcxx . . $ `lib/manage_external.h:58:9`!("WeaponHitWater"), // 48 SOUND_WEAPON_HIT_WATER
302 };
303
304 // Allocs a sound file for use, returns -1 if error, else index on success
305 int AllocSoundFilecxx . . $ AllocSoundFile(b126dc7c1de90089).() {
306 for (int i = 0; i < MAX_SOUND_FILEScxx . . $ `sndlib/ssl_lib.h:579:9`!; i++) {
307 if (SoundFilescxx . . $ SoundFiles.[i].usedcxx . . $ sound_file_info#used. == 0) {
308 memset(&SoundFilescxx . . $ SoundFiles.[i], 0, sizeof(sound_file_infocxx . . $ sound_file_info#));
309 SoundFilescxx . . $ SoundFiles.[i].usedcxx . . $ sound_file_info#used. = 1;
310
311 Num_sound_filescxx . . $ Num_sound_files.++;
312 return i;
313 }
314 }
315
316 Int3cxx . . $ `misc/pserror.h:247:9`!(); // No sound files free!
317 return -1;
318 }
319
320 // Frees sound index n
321 void FreeSoundFilecxx . . $ FreeSoundFile(d4f767463ce0a6b3).(int n) {
322 ASSERTcxx . . $ `misc/pserror.h:246:9`!(SoundFiles[n].used > 0);
323
324 SoundFilescxx . . $ SoundFiles.[n].usedcxx . . $ sound_file_info#used. = 0;
325 SoundFilescxx . . $ SoundFiles.[n].namecxx . . $ sound_file_info#name.[0] = 0;
326 if (SoundFilescxx . . $ SoundFiles.[n].sample_8bitcxx . . $ sound_file_info#sample_8bit.) {
327 mem_freecxx . . $ `mem/mem.h:80:9`!(SoundFiles[n].sample_8bit);
328 SoundFilescxx . . $ SoundFiles.[n].sample_8bitcxx . . $ sound_file_info#sample_8bit. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
329 }
330 if (SoundFilescxx . . $ SoundFiles.[n].sample_16bitcxx . . $ sound_file_info#sample_16bit.) {
331 mem_freecxx . . $ `mem/mem.h:80:9`!(SoundFiles[n].sample_16bit);
332 SoundFilescxx . . $ SoundFiles.[n].sample_16bitcxx . . $ sound_file_info#sample_16bit. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
333 }
334 Num_sound_filescxx . . $ Num_sound_files.--;
335 }
336
337 // Gets next sound file from n that has actually been alloced
338 int GetNextSoundFilecxx . . $ GetNextSoundFile(7864480464b09eea).(int n) {
339 int i;
340
341 ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0 && n < MAX_SOUND_FILEScxx . . $ `sndlib/ssl_lib.h:579:9`!);
342
343 if (Num_sound_filescxx . . $ Num_sound_files. == 0)
344 return -1;
345
346 for (i = n + 1; i < MAX_SOUND_FILEScxx . . $ `sndlib/ssl_lib.h:579:9`!; i++)
347 if (SoundFilescxx . . $ SoundFiles.[i].usedcxx . . $ sound_file_info#used.)
348 return i;
349 for (i = 0; i < n; i++)
350 if (SoundFilescxx . . $ SoundFiles.[i].usedcxx . . $ sound_file_info#used.)
351 return i;
352
353 // this is the only one
354
355 return n;
356 }
357
358 // Gets previous sound file from n that has actually been alloced
359 int GetPrevSoundFilecxx . . $ GetPrevSoundFile(7864480464b09eea).(int n) {
360 int i;
361
362 ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0 && n < MAX_SOUND_FILEScxx . . $ `sndlib/ssl_lib.h:579:9`!);
363
364 if (Num_sound_filescxx . . $ Num_sound_files. == 0)
365 return -1;
366
367 for (i = n - 1; i >= 0; i--) {
368 if (SoundFilescxx . . $ SoundFiles.[i].usedcxx . . $ sound_file_info#used.)
369 return i;
370 }
371 for (i = MAX_SOUND_FILEScxx . . $ `sndlib/ssl_lib.h:579:9`! - 1; i > n; i--) {
372 if (SoundFilescxx . . $ SoundFiles.[i].usedcxx . . $ sound_file_info#used.)
373 return i;
374 }
375
376 // this is the only one
377 return n;
378 }
379 // Searches thru all sounds for a specific name, returns -1 if not found
380 // or index of sound with name
381 int FindSoundFileNamecxx . . $ FindSoundFileName(1ef8e6ec083aabb9).(char *name) {
382 int i;
383
384 ASSERTcxx . . $ `misc/pserror.h:246:9`!(name != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
385
386 for (i = 0; i < MAX_SOUND_FILEScxx . . $ `sndlib/ssl_lib.h:579:9`!; i++)
387 if (SoundFilescxx . . $ SoundFiles.[i].usedcxx . . $ sound_file_info#used. && !stricmpcxx . . $ `linux/linux_fix.h:43:9`!(name, SoundFiles[i].name))
388 return i;
389
390 return -1;
391 }
392
393 // gets the filename from a path, plus appends our .wav extension
394 void ChangeSoundFileNamecxx . . $ ChangeSoundFileName(611124a97efc52dd).(const char *src, char *dest) {
395 int limit;
396 char path[256], ext[256], filename[256];
397
398 limit = PAGENAME_LENcxx . . $ `lib/manage_external.h:49:9`! - 5;
399
400 ddio_SplitPathcxx . . $ ddio_SplitPath(b05ba7ab99603c07).(src, path, filename, ext);
401
402 // Make sure we don't go over our name length limit
403 strncpy(dest, filename, limit);
404
405 strcat(dest, ".wav");
406 }
407
408 // Given a filename, loads the sound file.
409 int LoadSoundFilecxx . . $ LoadSoundFile(e629f44b83d433dc).(const char *filename, float import_volume, bool f_get_data) {
410 int sound_file_index;
411 char extension[10];
412 char name[90];
413 int len;
414
415 ChangeSoundFileNamecxx . . $ ChangeSoundFileName(611124a97efc52dd).(filename, name);
416
417 // See if the file was already loaded
418 sound_file_index = FindSoundFileNamecxx . . $ FindSoundFileName(1ef8e6ec083aabb9).(name);
419 if (sound_file_index != -1)
420 return sound_file_index;
421
422 // Make room for the new sound
423 sound_file_index = AllocSoundFilecxx . . $ AllocSoundFile(b126dc7c1de90089).();
424 if (sound_file_index == -1) {
425 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "SOUND LOADER: No free sound file slots are available.\n", filename);
426 Int3cxx . . $ `misc/pserror.h:247:9`!();
427 return -1;
428 }
429
430 // Validate the extension length
431
432 len = strlen(filename);
433 if (len < 4) {
•434 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "SOUND LOADER: %s does not have a 3 character extension.\n", filename);
435 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Get chris
436 goto error_state;
437 }
438
439 strcpy(SoundFilescxx . . $ SoundFiles.[sound_file_index].namecxx . . $ sound_file_info#name., name);
440
441 // Load the file by its type (as defined by the extension)
442 strncpy(extension, &filename[len - 3], 5);
443 if (strnicmpcxx . . $ `linux/linux_fix.h:44:9`!("wav", extension, 3) == 0) {
444 if (!SoundLoadWaveFilecxx . . $ SoundLoadWaveFile(a6965b2b334606ff).(filename, import_volume, sound_file_index, false, f_get_data)) {
445 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "SOUND LOADER: Error loading %s.\n", filename);
446 goto error_state;
447 }
448 } else {
449 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "SOUND LOADER: %s in not a supported file type.\n", extension);
450 goto error_state;
451 }
452
453 return sound_file_index;
454
455 error_state:
456 if (SoundFilescxx . . $ SoundFiles.[sound_file_index].usedcxx . . $ sound_file_info#used.)
457 FreeSoundFilecxx . . $ FreeSoundFile(d4f767463ce0a6b3).(sound_file_index);
458 return -1;
459 }
460
461 // Sets all sounds to unused
462 void InitSoundscxx . . $ InitSounds(49f6e7a06ebc5aa8).() {
463 int i;
464
465 for (i = 0; i < MAX_SOUNDScxx . . $ `sndlib/ssl_lib.h:578:9`!; i++) {
466 Soundscxx . . $ Sounds.[i].usedcxx . . $ sound_info#used. = 0;
467 Soundscxx . . $ Sounds.[i].namecxx . . $ sound_info#name.[0] = 0;
468 Soundscxx . . $ Sounds.[i].flagscxx . . $ sound_info#flags. = 0;
469 }
470 Num_soundscxx . . $ Num_sounds. = 0;
471
472 for (i = 0; i < MAX_SOUND_FILEScxx . . $ `sndlib/ssl_lib.h:579:9`!; i++) {
473 SoundFilescxx . . $ SoundFiles.[i].namecxx . . $ sound_file_info#name.[0] = 0;
474 SoundFilescxx . . $ SoundFiles.[i].usedcxx . . $ sound_file_info#used. = 0;
475 }
476 Num_sound_filescxx . . $ Num_sound_files. = 0;
477 }
478
479 // Allocs a sound for use, returns -1 if error, else index on success
480 int AllocSoundcxx . . $ AllocSound(b126dc7c1de90089).() {
481 // Don't alloc sound 0, because 0 means something special (default/none)
482 for (int i = 1; i < MAX_SOUNDScxx . . $ `sndlib/ssl_lib.h:578:9`!; i++) {
483 if (Soundscxx . . $ Sounds.[i].usedcxx . . $ sound_info#used. == 0) {
484 memset(&Soundscxx . . $ Sounds.[i], 0, sizeof(sound_infocxx . . $ sound_info#));
485
486 Soundscxx . . $ Sounds.[i].min_distancecxx . . $ sound_info#min_distance. = 10.0;
487 Soundscxx . . $ Sounds.[i].max_distancecxx . . $ sound_info#max_distance. = 256.0;
488 Soundscxx . . $ Sounds.[i].outer_cone_volumecxx . . $ sound_info#outer_cone_volume. = 1.0;
489 Soundscxx . . $ Sounds.[i].inner_cone_anglecxx . . $ sound_info#inner_cone_angle. = 360;
490 Soundscxx . . $ Sounds.[i].outer_cone_anglecxx . . $ sound_info#outer_cone_angle. = 360;
491 Soundscxx . . $ Sounds.[i].import_volumecxx . . $ sound_info#import_volume. = 1.0;
492
493 Soundscxx . . $ Sounds.[i].flagscxx . . $ sound_info#flags. = SPF_LISTENER_UPDATEcxx . . $ `sndlib/ssl_lib.h:373:9`!;
494
495 Soundscxx . . $ Sounds.[i].usedcxx . . $ sound_info#used. = 1;
496 Num_soundscxx . . $ Num_sounds.++;
497 return i;
498 }
499 }
500
501 Int3cxx . . $ `misc/pserror.h:247:9`!(); // No sounds free!
502 return -1;
503 }
504
505 // Frees sound index n
506 void FreeSoundcxx . . $ FreeSound(d4f767463ce0a6b3).(int n) {
507 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Sounds[n].used > 0);
508
509 Soundscxx . . $ Sounds.[n].usedcxx . . $ sound_info#used. = 0;
510 Soundscxx . . $ Sounds.[n].namecxx . . $ sound_info#name.[0] = 0;
511 Soundscxx . . $ Sounds.[n].flagscxx . . $ sound_info#flags. = 0;
512 Num_soundscxx . . $ Num_sounds.--;
513 }
514
515 // Gets next sound from n that has actually been alloced
516 int GetNextSoundcxx . . $ GetNextSound(7864480464b09eea).(int n) {
517 int i;
518
519 ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0 && n < MAX_SOUNDScxx . . $ `sndlib/ssl_lib.h:578:9`!);
520
521 if (Num_soundscxx . . $ Num_sounds. == 0)
522 return -1;
523
524 for (i = n + 1; i < MAX_SOUNDScxx . . $ `sndlib/ssl_lib.h:578:9`!; i++)
525 if (Soundscxx . . $ Sounds.[i].usedcxx . . $ sound_info#used.)
526 return i;
527 for (i = 0; i < n; i++)
528 if (Soundscxx . . $ Sounds.[i].usedcxx . . $ sound_info#used.)
529 return i;
530
531 // this is the only one
532
533 return n;
534 }
535
536 // Gets previous sound from n that has actually been alloced
537 int GetPrevSoundcxx . . $ GetPrevSound(7864480464b09eea).(int n) {
538 int i;
539
540 ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0 && n < MAX_SOUNDScxx . . $ `sndlib/ssl_lib.h:578:9`!);
541
542 if (Num_soundscxx . . $ Num_sounds. == 0)
543 return -1;
544
545 for (i = n - 1; i >= 0; i--) {
546 if (Soundscxx . . $ Sounds.[i].usedcxx . . $ sound_info#used.)
547 return i;
548 }
549 for (i = MAX_SOUNDScxx . . $ `sndlib/ssl_lib.h:578:9`! - 1; i > n; i--) {
550 if (Soundscxx . . $ Sounds.[i].usedcxx . . $ sound_info#used.)
551 return i;
552 }
553
554 // this is the only one
555 return n;
556 }
557 // Searches thru all sounds for a specific name, returns -1 if not found
558 // or index of sound with name
559 int FindSoundNamecxx . . $ FindSoundName(5c4306d8553b3696).(const char *name) {
560 int i;
561
562 ASSERTcxx . . $ `misc/pserror.h:246:9`!(name != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
563
564 for (i = 0; i < MAX_SOUNDScxx . . $ `sndlib/ssl_lib.h:578:9`!; i++)
565 if (Soundscxx . . $ Sounds.[i].usedcxx . . $ sound_info#used. && !stricmpcxx . . $ `linux/linux_fix.h:43:9`!(name, Sounds[i].name))
566 return i;
567
568 return -1;
569 }
570
571 // Given a filename, loads the sound.
572 int LoadSoundcxx . . $ LoadSound(1ef8e6ec083aabb9).(char *filename) {
573 int sound_handle;
574
575 sound_handle = mng_GetGuaranteedSoundPagecxx . . $ mng_GetGuaranteedSoundPage(a1d8d01c9983cd45).(filename);
576
577 return sound_handle;
578 }
579
580 void RemapSoundscxx . . $ RemapSounds(49f6e7a06ebc5aa8).() {
581 // Loop through the static sounds and move them to the correct slots
582 for (int i = 0; i < NUM_STATIC_SOUNDScxx . . $ `Descent3/sounds.h:154:9`!; i++) {
583
584 int cur_index = FindSoundNamecxx . . $ FindSoundName(5c4306d8553b3696).(Static_sound_namescxx . . $ Static_sound_names.[i]);
585
586 if (cur_index == -1) {
587 Int3cxx . . $ `misc/pserror.h:247:9`!(); // couldn't find statically-mapped sound
588 continue;
589 }
590
591 if (cur_index != i) { // not in right slot
592
593 if (Soundscxx . . $ Sounds.[i].usedcxx . . $ sound_info#used.) { // someone else in this slot, so swap
594 sound_infocxx . . $ sound_info# tsound = Soundscxx . . $ Sounds.[i];
595 Soundscxx . . $ Sounds.[i] =cxx . . $ sound_info#`operator=`(624d9766580fd28c). Soundscxx . . $ Sounds.[cur_index];
596 Soundscxx . . $ Sounds.[cur_index] =cxx . . $ sound_info#`operator=`(624d9766580fd28c). tsound;
597 RemapAllSoundObjectscxx . . $ RemapAllSoundObjects(3e454b8ccf442868).(i, MAX_SOUNDScxx . . $ `sndlib/ssl_lib.h:578:9`!);
598 RemapAllSoundObjectscxx . . $ RemapAllSoundObjects(3e454b8ccf442868).(cur_index, i);
599 RemapAllSoundObjectscxx . . $ RemapAllSoundObjects(3e454b8ccf442868).(MAX_SOUNDScxx . . $ `sndlib/ssl_lib.h:578:9`!, cur_index);
600 } else { // slot is unused, so just take it
601 Soundscxx . . $ Sounds.[i] =cxx . . $ sound_info#`operator=`(624d9766580fd28c). Soundscxx . . $ Sounds.[cur_index];
602 Soundscxx . . $ Sounds.[cur_index].usedcxx . . $ sound_info#used. = 0;
603 RemapAllSoundObjectscxx . . $ RemapAllSoundObjects(3e454b8ccf442868).(cur_index, i);
604 }
605 }
606 }
607 }
608
609 // goes thru every entity that could possible have a sound index (ie objects, robots, etc)
610 // and changes the old index to the new index
611 void RemapAllSoundObjectscxx . . $ RemapAllSoundObjects(3e454b8ccf442868).(int old_index, int new_index) {
612 int i, j, k;
613
614 // Remaps weapon sounds
615 for (i = 0; i < MAX_WEAPONScxx . . $ `Descent3/weapon.h:208:9`!; i++) {
616
617 if (Weaponscxx . . $ Weapons.[i].usedcxx . . $ weapon#used.) {
618 for (j = 0; j < MAX_WEAPON_SOUNDScxx . . $ `Descent3/weapon.h:259:9`!; j++) {
619 if (Weaponscxx . . $ Weapons.[i].soundscxx . . $ weapon#sounds.[j] == old_index) {
620 Weaponscxx . . $ Weapons.[i].soundscxx . . $ weapon#sounds.[j] = new_index;
621 }
622 }
623 }
624 }
625
626 // Remaps all non-wb object sounds
627 for (i = 0; i < MAX_OBJECT_IDScxx . . $ `Descent3/objinfo.h:327:9`!; i++) {
628 for (j = 0; j < MAX_OBJ_SOUNDScxx . . $ `Descent3/objinfo.h:330:9`!; j++) {
629 if (Object_infocxx . . $ Object_info.[i].soundscxx . . $ object_info#sounds.[j] == old_index) {
630 Object_infocxx . . $ Object_info.[i].soundscxx . . $ object_info#sounds.[j] = new_index;
631 }
632 }
633 if (Object_infocxx . . $ Object_info.[i].ai_infocxx . . $ object_info#ai_info.) {
634 for (j = 0; j < MAX_AI_SOUNDScxx . . $ `Descent3/aistruct.h:712:9`!; j++) {
635 if (Object_infocxx . . $ Object_info.[i].ai_infocxx . . $ object_info#ai_info.->soundcxx . . $ t_ai_info#sound.[j] == old_index) {
636 Object_infocxx . . $ Object_info.[i].ai_infocxx . . $ object_info#ai_info.->soundcxx . . $ t_ai_info#sound.[j] = new_index;
637 }
638 }
639 }
640 }
641
642 // Remaps weapon battery sounds contained by generic objects
643 for (i = 0; i < MAX_OBJECT_IDScxx . . $ `Descent3/objinfo.h:327:9`!; i++) {
644 if (Object_infocxx . . $ Object_info.[i].static_wbcxx . . $ object_info#static_wb.) {
645 for (j = 0; j < MAX_WBS_PER_OBJcxx . . $ `lib/robotfirestruct.h:32:9`!; j++) {
646 for (k = 0; k < MAX_WB_FIRING_MASKScxx . . $ `lib/robotfirestruct_external.h:23:9`!; k++) {
647 if (Object_infocxx . . $ Object_info.[i].static_wbcxx . . $ object_info#static_wb.[j].fm_fire_sound_indexcxx . . $ otype_wb_info#fm_fire_sound_index.[k] == old_index) {
648 Object_infocxx . . $ Object_info.[i].static_wbcxx . . $ object_info#static_wb.[j].fm_fire_sound_indexcxx . . $ otype_wb_info#fm_fire_sound_index.[k] = new_index;
649 }
650 }
651 }
652 }
653 }
654
655 // Remaps anim sounds contained by generic objects
656 for (i = 0; i < MAX_OBJECT_IDScxx . . $ `Descent3/objinfo.h:327:9`!; i++) {
657 if (Object_infocxx . . $ Object_info.[i].animcxx . . $ object_info#anim.) {
658 for (j = 0; j < NUM_MOVEMENT_CLASSEScxx . . $ `Descent3/objinfo.h:368:9`!; j++) {
659 for (k = 0; k < NUM_ANIMS_PER_CLASScxx . . $ `Descent3/objinfo.h:369:9`!; k++) {
660 if (Object_infocxx . . $ Object_info.[i].animcxx . . $ object_info#anim.[j].elemcxx . . $ anim_elem#elem.[k].anim_sound_indexcxx . . $ anim_entry#anim_sound_index. == old_index) {
661 Object_infocxx . . $ Object_info.[i].animcxx . . $ object_info#anim.[j].elemcxx . . $ anim_elem#elem.[k].anim_sound_indexcxx . . $ anim_entry#anim_sound_index. = new_index;
662 }
663 }
664 }
665 }
666 }
667
668 // Remaps weapons contained by Ships
669 for (i = 0; i < MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`!; i++) {
670 for (j = 0; j < MAX_WBS_PER_OBJcxx . . $ `lib/robotfirestruct.h:32:9`!; j++) {
671
672 if (Shipscxx . . $ Ships.[i].firing_soundcxx . . $ ship#firing_sound.[j] == old_index) {
673 Shipscxx . . $ Ships.[i].firing_soundcxx . . $ ship#firing_sound.[j] = new_index;
674 }
675
676 if (Shipscxx . . $ Ships.[i].firing_release_soundcxx . . $ ship#firing_release_sound.[j] == old_index) {
677 Shipscxx . . $ Ships.[i].firing_release_soundcxx . . $ ship#firing_release_sound.[j] = new_index;
678 }
679
680 for (k = 0; k < MAX_WB_FIRING_MASKScxx . . $ `lib/robotfirestruct_external.h:23:9`!; k++) {
681 if (Shipscxx . . $ Ships.[i].static_wbcxx . . $ ship#static_wb.[j].fm_fire_sound_indexcxx . . $ otype_wb_info#fm_fire_sound_index.[k] == old_index) {
682 Shipscxx . . $ Ships.[i].static_wbcxx . . $ ship#static_wb.[j].fm_fire_sound_indexcxx . . $ otype_wb_info#fm_fire_sound_index.[k] = new_index;
683 }
684 }
685 }
686 }
687
688 for (i = 0; i <= Highest_room_indexcxx . . $ Highest_room_index.; i++) {
689 if (Roomscxx . . $ Rooms.[i].usedcxx . . $ room#used.) {
690 if (Roomscxx . . $ Rooms.[i].flagscxx . . $ room#flags. & RF_DOORcxx . . $ `Descent3/room_external.h:176:9`!) {
691 doorcxx . . $ door# *door = &Doorscxx . . $ Doors.[Roomscxx . . $ Rooms.[i].doorway_datacxx . . $ room#doorway_data.->doornumcxx . . $ doorway#doornum.];
692
693 if (door->open_soundcxx . . $ door#open_sound. == old_index)
694 door->open_soundcxx . . $ door#open_sound. = new_index;
695 if (door->close_soundcxx . . $ door#close_sound. == old_index)
696 door->close_soundcxx . . $ door#close_sound. = new_index;
697 }
698 }
699 }
700
701 // Remaps textures
702 for (i = 0; i < MAX_TEXTUREScxx . . $ `Descent3/gametexture.h:244:9`!; i++) {
703 if (GameTexturescxx . . $ GameTextures.[i].usedcxx . . $ texture#used.) {
704 if (GameTexturescxx . . $ GameTextures.[i].soundcxx . . $ texture#sound. == old_index) {
705 GameTexturescxx . . $ GameTextures.[i].soundcxx . . $ texture#sound. = new_index;
706 }
707 }
708 }
709 }