WWAudio.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWAudio.h *
  23. * *
  24. * $Archive:: /Commando/Code/WWAudio/WWAudio.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/30/02 2:47p $*
  29. * *
  30. * $Revision:: 31 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __WWAUDIO_H
  39. #define __WWAUDIO_H
  40. #include "always.h"
  41. #pragma warning (push, 3)
  42. #include "Mss.H"
  43. #pragma warning (pop)
  44. #include "Vector.H"
  45. #include "SoundBuffer.H"
  46. #include "AudioEvents.H"
  47. #include "wwstring.h"
  48. /////////////////////////////////////////////////////////////////////////////////
  49. // Forward declaration
  50. /////////////////////////////////////////////////////////////////////////////////
  51. class AudibleSoundClass;
  52. class Sound3DClass;
  53. class Sound2DTriggerClass;
  54. class StreamSoundClass;
  55. class FileClass;
  56. class SoundSceneClass;
  57. class FileFactoryClass;
  58. class SoundSceneObjClass;
  59. class LogicalListenerClass;
  60. class LogicalSoundClass;
  61. class Matrix3D;
  62. class INIClass;
  63. /////////////////////////////////////////////////////////////////////////////////
  64. // Class IDs
  65. /////////////////////////////////////////////////////////////////////////////////
  66. typedef enum
  67. {
  68. CLASSID_UNKNOWN = 0,
  69. CLASSID_2D,
  70. CLASSID_3D,
  71. CLASSID_LISTENER,
  72. CLASSID_PSEUDO3D,
  73. CLASSID_2DTRIGGER,
  74. CLASSID_LOGICAL,
  75. CLASSID_FILTERED,
  76. CLASSID_COUNT
  77. } SOUND_CLASSID;
  78. /////////////////////////////////////////////////////////////////////////////////
  79. // Default values
  80. /////////////////////////////////////////////////////////////////////////////////
  81. const int DEF_2D_SAMPLE_COUNT = 16;
  82. const int DEF_3D_SAMPLE_COUNT = 16;
  83. const float DEF_MUSIC_VOL = 1.0F;
  84. const float DEF_SFX_VOL = 1.0F;
  85. const float DEF_DIALOG_VOL = 1.0F;
  86. const float DEF_CINEMATIC_VOL = 1.0F;
  87. const float DEF_FADE_TIME = 0.5F;
  88. const int DEF_CACHE_SIZE = 1024;
  89. const int DEF_MAX_2D_BUFFER_SIZE = 20000;
  90. const int DEF_MAX_3D_BUFFER_SIZE = 100000;
  91. /////////////////////////////////////////////////////////////////////////////////
  92. // Constants
  93. /////////////////////////////////////////////////////////////////////////////////
  94. enum
  95. {
  96. MAX_CACHE_HASH = 256,
  97. CACHE_HASH_MASK = 0x000000FF
  98. };
  99. /////////////////////////////////////////////////////////////////////////////////
  100. //
  101. // WWAudioClass
  102. //
  103. // Main controlling entity for all music and sound effects in a game. Used
  104. // to:
  105. //
  106. // -- Select hardware devices
  107. // -- Modify quality preferences
  108. // -- Modify global volume settings
  109. // -- Allocate new sounds
  110. // -- Cache reuseable sounds
  111. // -- Play music and sound effects
  112. //
  113. //
  114. /////////////////////////////////////////////////////////////////////////////////
  115. class WWAudioClass
  116. {
  117. public:
  118. //////////////////////////////////////////////////////////////////////
  119. // Public data types
  120. //////////////////////////////////////////////////////////////////////
  121. typedef enum
  122. {
  123. DRIVER2D_ERROR = 0,
  124. DRIVER2D_DSOUND,
  125. DRIVER2D_WAVEOUT,
  126. DRIVER2D_COUNT
  127. } DRIVER_TYPE_2D;
  128. typedef enum
  129. {
  130. DRIVER3D_ERROR = 0,
  131. DRIVER3D_D3DSOUND,
  132. DRIVER3D_EAX,
  133. DRIVER3D_A3D,
  134. DRIVER3D_RSX,
  135. DRIVER3D_PSEUDO,
  136. DRIVER3D_DOLBY,
  137. DRIVER3D_COUNT
  138. } DRIVER_TYPE_3D;
  139. typedef enum
  140. {
  141. PAGE_PRIMARY = 0,
  142. PAGE_SECONDARY,
  143. PAGE_TERTIARY,
  144. PAGE_COUNT
  145. } SOUND_PAGE;
  146. typedef struct _DRIVER_INFO_STRUCT
  147. {
  148. HPROVIDER driver;
  149. char * name;
  150. } DRIVER_INFO_STRUCT;
  151. //////////////////////////////////////////////////////////////////////
  152. // Friend classes
  153. //////////////////////////////////////////////////////////////////////
  154. friend class AudibleSoundClass;
  155. friend class Sound3DClass;
  156. friend class Listener3DClass;
  157. //////////////////////////////////////////////////////////////////////
  158. // Public constructors/destructors
  159. //////////////////////////////////////////////////////////////////////
  160. WWAudioClass (bool lite = false);
  161. virtual ~WWAudioClass (void);
  162. //////////////////////////////////////////////////////////////////////
  163. // Static methods
  164. //////////////////////////////////////////////////////////////////////
  165. static WWAudioClass * Get_Instance (void) { return _theInstance; }
  166. //////////////////////////////////////////////////////////////////////
  167. // Initialization methods
  168. //////////////////////////////////////////////////////////////////////
  169. //
  170. // Note: After call Initialize () you can begin using the library, you don't
  171. // need to explicity call Open_2D_Device () or Select_3D_Device (). Those
  172. // methods were provided as a means of opening devices other than the default.
  173. //
  174. // The Initialize () method defaults to a stereo, 16bit, 44100hz 2D DirectSound
  175. // driver and a RSX 3D provider. If RSX isn't available, it trys A3D, then
  176. // EAX, then D3DSound, then whatever driver is first available.
  177. //
  178. void Initialize (bool stereo = true, int bits = 16, int hertz = 44100);
  179. void Initialize (const char *registry_subkey_name);
  180. void Shutdown (void);
  181. //////////////////////////////////////////////////////////////////////
  182. // Driver methods
  183. //////////////////////////////////////////////////////////////////////
  184. HDIGDRIVER Get_2D_Driver (void) const { return m_Driver2D; }
  185. HPROVIDER Get_3D_Driver (void) const { return m_Driver3D; }
  186. const StringClass & Get_3D_Driver_Name (void) const { return m_Driver3DName; }
  187. HPROVIDER Get_Reverb_Filter (void) const { return m_ReverbFilter; }
  188. //////////////////////////////////////////////////////////////////////
  189. // 2D Hardware/driver selection methods
  190. //////////////////////////////////////////////////////////////////////
  191. DRIVER_TYPE_2D Open_2D_Device (LPWAVEFORMAT format = NULL);
  192. DRIVER_TYPE_2D Open_2D_Device (bool stereo, int bits, int hertz);
  193. bool Close_2D_Device (void);
  194. int Get_Playback_Rate (void) const { return m_PlaybackRate; }
  195. int Get_Playback_Bits (void) const { return m_PlaybackBits; }
  196. bool Get_Playback_Stereo (void) const { return m_PlaybackStereo; }
  197. //////////////////////////////////////////////////////////////////////
  198. // 3D Hardware/driver selection methods
  199. //////////////////////////////////////////////////////////////////////
  200. // Device information
  201. int Get_3D_Device_Count (void) const { return m_Driver3DList.Count (); }
  202. bool Get_3D_Device (int index, DRIVER_INFO_STRUCT **info) { (*info) = m_Driver3DList[index]; return true; }
  203. bool Is_3D_Device_Available (DRIVER_TYPE_3D type) { return Find_3D_Device (type) >= 0; }
  204. int Find_3D_Device (DRIVER_TYPE_3D type);
  205. // Device selection
  206. bool Select_3D_Device (int index);
  207. bool Select_3D_Device (const char *device_name, HPROVIDER provider);
  208. bool Select_3D_Device (DRIVER_TYPE_3D type);
  209. bool Select_3D_Device (const char *device_name);
  210. bool Close_3D_Device (void);
  211. //////////////////////////////////////////////////////////////////////
  212. // Speaker configuration
  213. //////////////////////////////////////////////////////////////////////
  214. //
  215. // See MSS.H for a list of speaker types
  216. //
  217. // At the time of this documentation the speaker types were:
  218. // #define AIL_3D_2_SPEAKER 0
  219. // #define AIL_3D_HEADPHONE 1
  220. // #define AIL_3D_SURROUND 2
  221. // #define AIL_3D_4_SPEAKER 3
  222. //
  223. void Set_Speaker_Type (int speaker_type);
  224. int Get_Speaker_Type (void) const;
  225. //////////////////////////////////////////////////////////////////////
  226. // Registry settings
  227. //////////////////////////////////////////////////////////////////////
  228. bool Load_From_Registry (const char *subkey_name);
  229. bool Load_From_Registry (const char *subkey_name, StringClass &device_name, bool &is_stereo, int &bits, int &hertz, bool &sound_enabled, bool &music_enabled, bool &dialog_enabled, bool &cinematic_sound_enabled, float &sound_volume, float &music_volume, float &dialog_volume, float &cinematic_volume, int &speaker_types);
  230. bool Save_To_Registry (const char *subkey_name);
  231. bool Save_To_Registry (const char *subkey_name, const StringClass &device_name, bool is_stereo, int bits, int hertz, bool sound_enabled, bool music_enabled, bool dialog_enabled, bool cinematic_sound_enabled, float sound_volume, float music_volume, float dialog_volume, float cinematic_volume, int speaker_type);
  232. //////////////////////////////////////////////////////////////////////
  233. // Default settings
  234. //////////////////////////////////////////////////////////////////////
  235. void Load_Default_Volume (int &defaultmusicvolume, int &defaultsoundvolume, int &defaultdialogvolume, int &defaultcinematicvolume);
  236. //////////////////////////////////////////////////////////////////////
  237. // File interface methods
  238. //////////////////////////////////////////////////////////////////////
  239. //
  240. // Note: The user is responsible for freeing this file factory, the
  241. // sound library does not.
  242. //
  243. void Set_File_Factory (FileFactoryClass *ffactory) { m_FileFactory = ffactory; }
  244. //////////////////////////////////////////////////////////////////////
  245. // Preference settings methods
  246. //////////////////////////////////////////////////////////////////////
  247. bool Set_Max_2D_Sample_Count (int count = DEF_2D_SAMPLE_COUNT);
  248. int Get_Max_2D_Sample_Count (void) const;
  249. int Get_Avail_2D_Sample_Count (void) const;
  250. bool Set_Max_3D_Sample_Count (int count = DEF_3D_SAMPLE_COUNT);
  251. int Get_Max_3D_Sample_Count (void) const;
  252. int Get_Avail_3D_Sample_Count (void) const;
  253. //
  254. // Reverb Support: Only works with Create Labs EAX chipset.
  255. //
  256. float Get_Effects_Level (void) { return m_EffectsLevel; }
  257. // See ENVIRONMENT_ defines in MSS.H for a list of possible values.
  258. int Get_Reverb_Room_Type (void) { return m_ReverbRoomType; }
  259. void Set_Reverb_Room_Type (int type);
  260. //////////////////////////////////////////////////////////////////////
  261. // Volume methods
  262. //////////////////////////////////////////////////////////////////////
  263. void Set_Sound_Effects_Volume (float volume = DEF_SFX_VOL);
  264. float Get_Sound_Effects_Volume (void) const { return m_SoundVolume; }
  265. void Set_Music_Volume (float volume = DEF_MUSIC_VOL);
  266. float Get_Music_Volume (void) const { return m_MusicVolume; }
  267. void Set_Dialog_Volume (float volume = DEF_DIALOG_VOL);
  268. float Get_Dialog_Volume (void) const { return m_DialogVolume; }
  269. void Set_Cinematic_Volume (float volume = DEF_CINEMATIC_VOL);
  270. float Get_Cinematic_Volume (void) const { return m_CinematicVolume; }
  271. void Allow_Sound_Effects (bool onoff = true);
  272. bool Are_Sound_Effects_On (void) const { return m_AreSoundEffectsEnabled; }
  273. void Allow_Music (bool onoff = true);
  274. bool Is_Music_On (void) const { return m_IsMusicEnabled; }
  275. void Allow_Dialog (bool onoff = true);
  276. bool Is_Dialog_On (void) const { return m_IsDialogEnabled; }
  277. void Allow_Cinematic_Sound (bool onoff = true);
  278. bool Is_Cinematic_Sound_On (void) const { return m_IsCinematicSoundEnabled; }
  279. void Enable_New_Sounds (bool onoff) { m_AreNewSoundsEnabled = onoff; }
  280. bool Are_New_Sounds_Enabled (void) const { return m_AreNewSoundsEnabled; }
  281. void Temp_Disable_Audio (bool onoff);
  282. //////////////////////////////////////////////////////////////////////
  283. // Update methods
  284. //////////////////////////////////////////////////////////////////////
  285. void On_Frame_Update (unsigned int milliseconds = 0);
  286. //////////////////////////////////////////////////////////////////////
  287. // Callback methods
  288. //////////////////////////////////////////////////////////////////////
  289. void Register_EOS_Callback (LPFNEOSCALLBACK callback, DWORD user_param);
  290. void UnRegister_EOS_Callback (LPFNEOSCALLBACK callback);
  291. void Register_Text_Callback (LPFNTEXTCALLBACK callback, DWORD user_param);
  292. void UnRegister_Text_Callback (LPFNTEXTCALLBACK callback);
  293. void Fire_Text_Callback (AudibleSoundClass *sound_obj, const StringClass &text);
  294. //////////////////////////////////////////////////////////////////////
  295. // Sound allocation methods
  296. //////////////////////////////////////////////////////////////////////
  297. //
  298. // Note: The string_id is either the filename (for file-based sounds)
  299. // or the string_id passed into the create-from-memory methods.
  300. // It is important to note that the AudibleSoundClass object is not cached, but
  301. // the raw sound data the AudibleSoundClass object plays.
  302. //
  303. bool Is_Sound_Cached (const char *string_id);
  304. //
  305. // Note: We differentiate between a 'music' object and
  306. // a 'sound effect' for volume control. A music object
  307. // is simply a sound effect with a 'SOUND_TYPE' of TYPE_MUSIC.
  308. // When the user adjusts the 'music' volume, we loop through
  309. // the sound effects marked 'music' and update their volume.
  310. // Same for 'sound effect' volume.
  311. //
  312. //
  313. // Note: The sound data these objects support can be PCM WAV,
  314. // ADPCM WAV, VOC, or MP3.
  315. //
  316. AudibleSoundClass * Create_Sound_Effect (FileClass &file, const char *string_id);
  317. AudibleSoundClass * Create_Sound_Effect (const char *filename);
  318. AudibleSoundClass * Create_Sound_Effect (const char *string_id, unsigned char *raw_wave_data, unsigned long bytes);
  319. //
  320. // Note: 3D sound effects should be inserted into the SoundScene.
  321. // They should not be manually played/stopped/etc.
  322. //
  323. // True 3D sound effects require mono, uncompressed, WAV data.
  324. // If the supplied data is not in this format the sound will
  325. // become a pseudo-3D sound.
  326. //
  327. // Pseudo-3D sounds are not true 3D sounds. They have the
  328. // same properties as 3D 'sound effects' but do not use 3D
  329. // hardware, are not restricted to mono, uncompressed, WAV data,
  330. // and do not calculate doppler and reverb effects.
  331. //
  332. Sound3DClass * Create_3D_Sound (FileClass &file, const char *string_id, int classid_hint = CLASSID_3D);
  333. Sound3DClass * Create_3D_Sound (const char *filename, int classid_hint = CLASSID_3D);
  334. Sound3DClass * Create_3D_Sound (const char *string_id, unsigned char *raw_wave_data, unsigned long bytes, int classid_hint = CLASSID_3D);
  335. //////////////////////////////////////////////////////////////////////
  336. // Background music support
  337. //////////////////////////////////////////////////////////////////////
  338. void Set_Background_Music (const char *filename);
  339. void Fade_Background_Music (const char *filename, int fade_out_time, int fade_in_time);
  340. const char * Get_Background_Music_Name (void) { return m_BackgroundMusicName; }
  341. AudibleSoundClass * Peek_Background_Music (void) { return m_BackgroundMusic; }
  342. //////////////////////////////////////////////////////////////////////
  343. // Logical-sound related methods
  344. //////////////////////////////////////////////////////////////////////
  345. LogicalSoundClass * Create_Logical_Sound (void);
  346. LogicalListenerClass * Create_Logical_Listener (void);
  347. //
  348. // Logical type identification for use with the definition system
  349. //
  350. void Add_Logical_Type (int id, LPCTSTR display_name);
  351. void Reset_Logical_Types (void);
  352. int Get_Logical_Type_Count (void) const { return m_LogicalTypes.Count (); }
  353. int Get_Logical_Type (int index, StringClass &name);
  354. //////////////////////////////////////////////////////////////////////
  355. // Definition related methods
  356. //////////////////////////////////////////////////////////////////////
  357. //
  358. // Sound creation methods
  359. //
  360. int Create_Instant_Sound (int definition_id, const Matrix3D &tm, RefCountClass *user_obj = NULL, uint32 user_data = 0, int classid_hint = CLASSID_3D);
  361. int Create_Instant_Sound (const char *def_name, const Matrix3D &tm, RefCountClass *user_obj = NULL, uint32 user_data = 0, int classid_hint = CLASSID_3D);
  362. AudibleSoundClass * Create_Continuous_Sound (int definition_id, RefCountClass *user_obj = NULL, uint32 user_data = 0, int classid_hint = CLASSID_3D);
  363. AudibleSoundClass * Create_Continuous_Sound (const char *def_name, RefCountClass *user_obj = NULL, uint32 user_data = 0, int classid_hint = CLASSID_3D);
  364. AudibleSoundClass * Create_Sound (int definition_id, RefCountClass *user_obj = NULL, uint32 user_data = 0, int classid_hint = CLASSID_3D);
  365. AudibleSoundClass * Create_Sound (const char *def_name, RefCountClass *user_obj = NULL, uint32 user_data = 0, int classid_hint = CLASSID_3D);
  366. //////////////////////////////////////////////////////////////////////
  367. // Sound object lookup
  368. //////////////////////////////////////////////////////////////////////
  369. SoundSceneObjClass * Find_Sound_Object (uint32 sound_obj_id);
  370. //////////////////////////////////////////////////////////////////////
  371. // Sound scene methods (for 3D sounds)
  372. //////////////////////////////////////////////////////////////////////
  373. SoundSceneClass * Get_Sound_Scene (void) const { return m_SoundScene; }
  374. //////////////////////////////////////////////////////////////////////
  375. // Cache methods
  376. //////////////////////////////////////////////////////////////////////
  377. //
  378. // Note: The cache sizes are in kilo-bytes. The default
  379. // is currently set to 1MB.
  380. //
  381. bool Set_Cache_Size (int kbytes = DEF_CACHE_SIZE) { m_MaxCacheSize = (kbytes * 1024); }
  382. int Get_Cache_Size (void) const { return m_MaxCacheSize / 1024; }
  383. int Get_Current_Cache_Size (void) const { return m_CurrentCacheSize; }
  384. void Flush_Cache (void);
  385. //
  386. // This settings determines whether a sound buffer is loaded
  387. // into memory or streamed from file.
  388. //
  389. // Note: True 3D sounds can't be streamed, so if the buffer size
  390. // is larger then the following setting, the sound is created as
  391. // a pseudo-3d sound effect and streamed.
  392. //
  393. void Set_Max_2D_Sound_Buffer (int bytes = DEF_MAX_2D_BUFFER_SIZE) { m_Max2DBufferSize = bytes; }
  394. void Set_Max_3D_Sound_Buffer (int bytes = DEF_MAX_3D_BUFFER_SIZE) { m_Max3DBufferSize = bytes; }
  395. //////////////////////////////////////////////////////////////////////
  396. // Play control methods
  397. //////////////////////////////////////////////////////////////////////
  398. bool Simple_Play_2D_Sound_Effect (const char *filename, float priority = 1.0F, float volume = DEF_SFX_VOL);
  399. bool Simple_Play_2D_Sound_Effect (FileClass &file, float priority = 1.0F, float volume = DEF_SFX_VOL);
  400. //////////////////////////////////////////////////////////////////////
  401. // Playlist methods
  402. //////////////////////////////////////////////////////////////////////
  403. bool Add_To_Playlist (AudibleSoundClass *sound);
  404. bool Remove_From_Playlist (AudibleSoundClass *sound);
  405. int Get_Playlist_Count (void) const { return m_Playlist[m_CurrPage].Count (); }
  406. AudibleSoundClass * Get_Playlist_Entry (int index) const;
  407. AudibleSoundClass * Peek_Playlist_Entry (int index) const { return m_Playlist[m_CurrPage][index]; }
  408. void Flush_Playlist (void);
  409. void Flush_Playlist (SOUND_PAGE page);
  410. bool Is_Sound_In_Playlist (AudibleSoundClass *sound_obj);
  411. //////////////////////////////////////////////////////////////////////
  412. // Virtual channel access
  413. //////////////////////////////////////////////////////////////////////
  414. bool Acquire_Virtual_Channel (AudibleSoundClass *sound_obj, int channel_index);
  415. void Release_Virtual_Channel (AudibleSoundClass *sound_obj, int channel_index);
  416. //////////////////////////////////////////////////////////////////////
  417. // Sound "page" access
  418. //////////////////////////////////////////////////////////////////////
  419. //
  420. // Note: Sound "pages" are simply sets of sounds. The primary page
  421. // is the full set of 3D sounds (in the scene) and 2D sounds that
  422. // are started when the primary page is active.
  423. // The secondary page is only the set of 2D sounds that are started
  424. // when the secondary page is active.
  425. //
  426. void Set_Active_Sound_Page (SOUND_PAGE page);
  427. SOUND_PAGE Get_Active_Sound_Page (void) { m_CurrPage; }
  428. void Push_Active_Sound_Page (SOUND_PAGE page);
  429. void Pop_Active_Sound_Page (void);
  430. //////////////////////////////////////////////////////////////////////
  431. // Dialog methods
  432. //////////////////////////////////////////////////////////////////////
  433. void Fade_Non_Dialog_In (void);
  434. void Fade_Non_Dialog_Out (void);
  435. void Set_Non_Dialog_Fade_Time (float fade_time) { m_NonDialogFadeTime = fade_time; }
  436. //////////////////////////////////////////////////////////////////////
  437. // Statistics methods
  438. //////////////////////////////////////////////////////////////////////
  439. //
  440. // This CPU percent includes total CPU being used for:
  441. // Mixing
  442. // Format conversions
  443. // ADPCM or MP3 decompression
  444. // System buffer fills
  445. //
  446. float Get_Digital_CPU_Percent (void) const;
  447. //////////////////////////////////////////////////////////////////////
  448. // Debug methods
  449. //////////////////////////////////////////////////////////////////////
  450. bool Is_Disabled (void) const;
  451. //
  452. // Debug support for determine what sounds are playing on which "channels"
  453. //
  454. int Get_2D_Sample_Count (void) const { return m_2DSampleHandles.Count (); }
  455. int Get_3D_Sample_Count (void) const { return m_3DSampleHandles.Count (); }
  456. AudibleSoundClass * Peek_2D_Sample (int index);
  457. AudibleSoundClass * Peek_3D_Sample (int index);
  458. // Um somtimes you need to get rid of all the completed sounds without
  459. // being in the update render function and without totally shutting down
  460. // the sound system. This is primarily because completed (non static) sounds
  461. // still may have a reference to the object they're attached to.
  462. void Free_Completed_Sounds (void);
  463. protected:
  464. //////////////////////////////////////////////////////////////////////
  465. // Protected methods
  466. //////////////////////////////////////////////////////////////////////
  467. void Build_3D_Driver_List (void);
  468. void Free_3D_Driver_List (void);
  469. void Reprioritize_Playlist (void);
  470. bool Validate_3D_Sound_Buffer (SoundBufferClass *buffer);
  471. FileClass * Get_File (LPCTSTR filename);
  472. void Return_File (FileClass *file);
  473. //////////////////////////////////////////////////////////////////////
  474. // Handle management
  475. //////////////////////////////////////////////////////////////////////
  476. void Allocate_2D_Handles (void);
  477. void Release_2D_Handles (void);
  478. void Allocate_3D_Handles (void);
  479. void Release_3D_Handles (void);
  480. HSAMPLE Get_2D_Sample (const AudibleSoundClass &sound_obj);
  481. H3DSAMPLE Get_3D_Sample (const Sound3DClass &sound_obj);
  482. H3DPOBJECT Get_Listener_Handle (void);
  483. void ReAssign_2D_Handles (void);
  484. void ReAssign_3D_Handles (void);
  485. void Remove_2D_Sound_Handles (void);
  486. void Remove_3D_Sound_Handles (void);
  487. bool Is_OK_To_Give_Handle (const AudibleSoundClass &sound_obj);
  488. //////////////////////////////////////////////////////////////////////
  489. // Dialog/Fade methods
  490. //////////////////////////////////////////////////////////////////////
  491. void Update_Fade (void);
  492. void Internal_Set_Sound_Effects_Volume (float volume);
  493. void Internal_Set_Music_Volume (float volume);
  494. //////////////////////////////////////////////////////////////////////
  495. // Cache methods
  496. //////////////////////////////////////////////////////////////////////
  497. SoundBufferClass * Get_Sound_Buffer (FileClass &file, const char *string_id, bool is_3d);
  498. SoundBufferClass * Get_Sound_Buffer (const char *filename, bool is_3d);
  499. SoundBufferClass * Find_Cached_Buffer (const char *string_id);
  500. SoundBufferClass * Create_Sound_Buffer (FileClass &file, const char *string_id, bool is_3d);
  501. SoundBufferClass * Create_Sound_Buffer (unsigned char *file_image, unsigned long bytes, const char *string_id, bool is_3d);
  502. bool Cache_Buffer (SoundBufferClass *buffer, const char *string_id);
  503. bool Free_Cache_Space (int bytes);
  504. //////////////////////////////////////////////////////////////////////
  505. // Miles File Callbacks
  506. //////////////////////////////////////////////////////////////////////
  507. static U32 AILCALLBACK File_Open_Callback (char const *filename, U32 *file_handle);
  508. static void AILCALLBACK File_Close_Callback (U32 file_handle);
  509. static S32 AILCALLBACK File_Seek_Callback (U32 file_handle, S32 offset, U32 type);
  510. static U32 AILCALLBACK File_Read_Callback (U32 file_handle, void *buffer, U32 bytes);
  511. private:
  512. //////////////////////////////////////////////////////////////////////
  513. // Static member data
  514. //////////////////////////////////////////////////////////////////////
  515. static WWAudioClass * _theInstance;
  516. static HANDLE _TimerSyncEvent;
  517. //////////////////////////////////////////////////////////////////////
  518. // Private data types
  519. //////////////////////////////////////////////////////////////////////
  520. typedef struct _CACHE_ENTRY_STRUCT
  521. {
  522. char * string_id;
  523. SoundBufferClass * buffer;
  524. _CACHE_ENTRY_STRUCT (void)
  525. : string_id (0), buffer (NULL) {}
  526. _CACHE_ENTRY_STRUCT &operator= (const _CACHE_ENTRY_STRUCT &src) { string_id = ::strdup (src.string_id); REF_PTR_SET (buffer, src.buffer); return *this; }
  527. operator== (const _CACHE_ENTRY_STRUCT &src) { return false; }
  528. operator!= (const _CACHE_ENTRY_STRUCT &src) { return true; }
  529. } CACHE_ENTRY_STRUCT;
  530. typedef struct _LOGICAL_TYPE_STRUCT
  531. {
  532. StringClass display_name;
  533. int id;
  534. _LOGICAL_TYPE_STRUCT (void)
  535. : id (0) {}
  536. _LOGICAL_TYPE_STRUCT (int _id, LPCTSTR name)
  537. : display_name (name), id (_id) {}
  538. operator== (const _LOGICAL_TYPE_STRUCT &src) { return false; }
  539. operator!= (const _LOGICAL_TYPE_STRUCT &src) { return true; }
  540. } LOGICAL_TYPE_STRUCT;
  541. //////////////////////////////////////////////////////////////////////
  542. // Private constants
  543. //////////////////////////////////////////////////////////////////////
  544. typedef enum
  545. {
  546. FADE_NONE = 0,
  547. FADE_IN,
  548. FADE_OUT,
  549. FADED_OUT,
  550. } FADE_TYPE;
  551. //////////////////////////////////////////////////////////////////////
  552. // Private member data
  553. //////////////////////////////////////////////////////////////////////
  554. int m_PlaybackRate;
  555. int m_PlaybackBits;
  556. bool m_PlaybackStereo;
  557. float m_MusicVolume;
  558. float m_SoundVolume;
  559. float m_RealMusicVolume;
  560. float m_RealSoundVolume;
  561. float m_DialogVolume;
  562. float m_CinematicVolume;
  563. int m_Max2DSamples;
  564. int m_Max3DSamples;
  565. int m_Max2DBufferSize;
  566. int m_Max3DBufferSize;
  567. HTIMER m_UpdateTimer;
  568. bool m_IsMusicEnabled;
  569. bool m_IsDialogEnabled;
  570. bool m_IsCinematicSoundEnabled;
  571. bool m_AreSoundEffectsEnabled;
  572. bool m_AreNewSoundsEnabled;
  573. FileFactoryClass * m_FileFactory;
  574. AudibleSoundClass * m_BackgroundMusic;
  575. StringClass m_BackgroundMusicName;
  576. bool m_CachedIsMusicEnabled;
  577. bool m_CachedIsDialogEnabled;
  578. bool m_CachedIsCinematicSoundEnabled;
  579. bool m_CachedAreSoundEffectsEnabled;
  580. // Callback lists
  581. AudioCallbackListClass<LPFNEOSCALLBACK> m_EOSCallbackList;
  582. AudioCallbackListClass<LPFNTEXTCALLBACK> m_TextCallbackList;
  583. // Sound scene management
  584. SoundSceneClass * m_SoundScene;
  585. SOUND_PAGE m_CurrPage;
  586. DynamicVectorClass<SOUND_PAGE> m_PageStack;
  587. // Driver information
  588. HDIGDRIVER m_Driver2D;
  589. HPROVIDER m_Driver3D;
  590. HPROVIDER m_Driver3DPseudo;
  591. HPROVIDER m_ReverbFilter;
  592. DynamicVectorClass<DRIVER_INFO_STRUCT *> m_Driver3DList;
  593. StringClass m_Driver3DName;
  594. int m_SpeakerType;
  595. // Available sample handles
  596. DynamicVectorClass<HSAMPLE> m_2DSampleHandles;
  597. DynamicVectorClass<H3DSAMPLE> m_3DSampleHandles;
  598. // Playlist managment
  599. DynamicVectorClass<AudibleSoundClass *> m_Playlist[PAGE_COUNT];
  600. DynamicVectorClass<AudibleSoundClass *> m_CompletedSounds;
  601. // Virtual channel support
  602. DynamicVectorClass<AudibleSoundClass *> m_VirtualChannels;
  603. // Buffer caching
  604. DynamicVectorClass<CACHE_ENTRY_STRUCT> m_CachedBuffers[MAX_CACHE_HASH];
  605. int m_MaxCacheSize;
  606. int m_CurrentCacheSize;
  607. // Logical type management
  608. DynamicVectorClass<LOGICAL_TYPE_STRUCT> m_LogicalTypes;
  609. // Reverb support
  610. float m_EffectsLevel;
  611. int m_ReverbRoomType;
  612. // Fade support
  613. float m_NonDialogFadeTime;
  614. FADE_TYPE m_FadeType;
  615. float m_FadeTimer;
  616. // INI
  617. INIClass *AudioIni;
  618. bool m_ForceDisable;
  619. };
  620. #endif //__WWAUDIO_H