Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
WWAudioClass.h
1/* Renegade Scripts.dll
2 Copyright 2013 Tiberian Technologies
3
4 This file is part of the Renegade scripts.dll
5 The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version. See the file COPYING for more details.
9 In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
10 Only the source code to the module(s) containing the licenced code has to be released.
11*/
12#ifndef __WWAUDIOCLASS_H__
13#define __WWAUDIOCLASS_H__
14#include "engine_common.h"
15#include "engine_string.h"
16#include "engine_vector.h"
17#include "scripts.h"
18#include "AudioCallbackListClass.h"
19#include "Matrix3D.h"
20#include <mmsystem.h>
21#include "SoundBufferClass.h"
22class AudibleSoundClass;
23class Sound3DClass;
24class Sound2DTriggerClass;
25class StreamSoundClass;
26class FileClass;
27class SoundSceneClass;
28class FileFactoryClass;
29class SoundSceneObjClass;
30class LogicalListenerClass;
31class LogicalSoundClass;
32class Matrix3D;
33class INIClass;
34typedef unsigned int HPROVIDER;
35typedef void *HDIGDRIVER;
36typedef void *HSAMPLE;
37typedef void *H3DSAMPLE;
38typedef void *H3DPOBJECT;
39typedef void *HSTREAM;
40typedef signed int HTIMER;
41typedef void (_stdcall *LPFNSOSCALLBACK) (SoundSceneObjClass *sound_obj, uint32 user_param);
42typedef void (_stdcall *LPFNEOSCALLBACK) (SoundSceneObjClass *sound_obj, uint32 user_param);
43typedef void (_stdcall *LPFNHEARDCALLBACK) (LogicalListenerClass *listener, LogicalSoundClass *sound_obj, uint32 user_param);
44typedef void (_stdcall *LPFNTEXTCALLBACK) (AudibleSoundClass *sound_obj, const StringClass &text, uint32 user_param);
45#define AILCALLBACK WINAPI
46typedef enum
47{
48 CLASSID_UNKNOWN = 0,
49 CLASSID_2D,
50 CLASSID_3D,
51 CLASSID_LISTENER,
52 CLASSID_PSEUDO3D,
53 CLASSID_2DTRIGGER,
54 CLASSID_LOGICAL,
55 CLASSID_FILTERED,
56 CLASSID_COUNT
57} SOUND_CLASSID;
58const int DEF_2D_SAMPLE_COUNT = 16;
59const int DEF_3D_SAMPLE_COUNT = 16;
60const float DEF_MUSIC_VOL = 1.0F;
61const float DEF_SFX_VOL = 1.0F;
62const float DEF_DIALOG_VOL = 1.0F;
63const float DEF_CINEMATIC_VOL = 1.0F;
64const float DEF_FADE_TIME = 0.5F;
65const int DEF_CACHE_SIZE = 1024;
66const int DEF_MAX_2D_BUFFER_SIZE = 20000;
67const int DEF_MAX_3D_BUFFER_SIZE = 100000;
68enum
69{
70 MAX_CACHE_HASH = 256,
71 CACHE_HASH_MASK = 0x000000FF
72};
73class WWAudioClass
74{
75public:
76 typedef enum
77 {
78 DRIVER2D_ERROR = 0,
79 DRIVER2D_DSOUND,
80 DRIVER2D_WAVEOUT,
81 DRIVER2D_COUNT
82 } DRIVER_TYPE_2D;
83 typedef enum
84 {
85 DRIVER3D_ERROR = 0,
86 DRIVER3D_D3DSOUND,
87 DRIVER3D_EAX,
88 DRIVER3D_A3D,
89 DRIVER3D_RSX,
90 DRIVER3D_PSEUDO,
91 DRIVER3D_DOLBY,
92 DRIVER3D_COUNT
93 } DRIVER_TYPE_3D;
94 typedef enum
95 {
96 PAGE_PRIMARY = 0,
97 PAGE_SECONDARY,
98 PAGE_TERTIARY,
99 PAGE_COUNT
100 } SOUND_PAGE;
101 typedef struct _DRIVER_INFO_STRUCT
102 {
103 HPROVIDER driver;
104 char * name;
105 } DRIVER_INFO_STRUCT;
106 friend class AudibleSoundClass;
107 friend class Sound3DClass;
108 friend class Listener3DClass;
109 WWAudioClass (bool lite = false);
110 virtual ~WWAudioClass (void);
111 static WWAudioClass * Get_Instance (void) { return _theInstance; }
112 void Initialize (bool stereo = true, int bits = 16, int hertz = 44100);
113 void Initialize (const char *registry_subkey_name);
114 void Shutdown (void);
115 HDIGDRIVER Get_2D_Driver (void) const { return m_Driver2D; }
116 HPROVIDER Get_3D_Driver (void) const { return m_Driver3D; }
117 const StringClass & Get_3D_Driver_Name (void) const { return m_Driver3DName; }
118 HPROVIDER Get_Reverb_Filter (void) const { return m_ReverbFilter; }
119 DRIVER_TYPE_2D Open_2D_Device (LPWAVEFORMAT format = NULL);
120 DRIVER_TYPE_2D Open_2D_Device (bool stereo, int bits, int hertz);
121 bool Close_2D_Device (void);
122 int Get_Playback_Rate (void) const { return m_PlaybackRate; }
123 int Get_Playback_Bits (void) const { return m_PlaybackBits; }
124 bool Get_Playback_Stereo (void) const { return m_PlaybackStereo; }
125 int Get_3D_Device_Count (void) const { return m_Driver3DList.Count (); }
126 bool Get_3D_Device (int index, DRIVER_INFO_STRUCT **info) { (*info) = m_Driver3DList[index]; return true; }
127 bool Is_3D_Device_Available (DRIVER_TYPE_3D type) { return Find_3D_Device (type) >= 0; }
128 int Find_3D_Device (DRIVER_TYPE_3D type);
129 bool Select_3D_Device (int index);
130 bool Select_3D_Device (const char *device_name, HPROVIDER provider);
131 bool Select_3D_Device (DRIVER_TYPE_3D type);
132 bool Select_3D_Device (const char *device_name);
133 bool Close_3D_Device (void);
134 void Set_Speaker_Type (int speaker_type);
135 int Get_Speaker_Type (void) const;
136 bool Load_From_Registry (const char *subkey_name);
137 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);
138 bool Save_To_Registry (const char *subkey_name);
139 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);
140 void Load_Default_Volume (int &defaultmusicvolume, int &defaultsoundvolume, int &defaultdialogvolume, int &defaultcinematicvolume);
141 void Set_File_Factory (FileFactoryClass *ffactory) { m_FileFactory = ffactory; }
142 bool Set_Max_2D_Sample_Count (int count = DEF_2D_SAMPLE_COUNT) { m_Max2DSamples = count; Allocate_2D_Handles(); return true; } // Reimplementation. No idea whether this matches the original function!
143 int Get_Max_2D_Sample_Count (void) const;
144 int Get_Avail_2D_Sample_Count (void) const;
145 bool Set_Max_3D_Sample_Count (int count = DEF_3D_SAMPLE_COUNT) { m_Max3DSamples = count; Allocate_3D_Handles(); return true; } // Reimplementation. No idea whether this matches the original function!
146 int Get_Max_3D_Sample_Count (void) const;
147 int Get_Avail_3D_Sample_Count (void) const;
148 float Get_Effects_Level (void) { return m_EffectsLevel; }
149 int Get_Reverb_Room_Type (void) { return m_ReverbRoomType; }
150 void Set_Reverb_Room_Type (int type);
151 void Set_Sound_Effects_Volume (float volume = DEF_SFX_VOL);
152 float Get_Sound_Effects_Volume (void) const { return m_SoundVolume; }
153 void Set_Music_Volume (float volume = DEF_MUSIC_VOL);
154 float Get_Music_Volume (void) const { return m_MusicVolume; }
155 void Set_Dialog_Volume (float volume = DEF_DIALOG_VOL);
156 float Get_Dialog_Volume (void) const { return m_DialogVolume; }
157 void Set_Cinematic_Volume (float volume = DEF_CINEMATIC_VOL);
158 float Get_Cinematic_Volume (void) const { return m_CinematicVolume; }
159 void Allow_Sound_Effects (bool onoff = true);
160 bool Are_Sound_Effects_On (void) const { return m_AreSoundEffectsEnabled; }
161 void Allow_Music (bool onoff = true);
162 bool Is_Music_On (void) const { return m_IsMusicEnabled; }
163 void Allow_Dialog (bool onoff = true);
164 bool Is_Dialog_On (void) const { return m_IsDialogEnabled; }
165 void Allow_Cinematic_Sound (bool onoff = true);
166 bool Is_Cinematic_Sound_On (void) const { return m_IsCinematicSoundEnabled; }
167 void Enable_New_Sounds (bool onoff) { m_AreNewSoundsEnabled = onoff; }
168 bool Are_New_Sounds_Enabled (void) const { return m_AreNewSoundsEnabled; }
169 void Temp_Disable_Audio (bool onoff);
170 void On_Frame_Update (unsigned int milliseconds = 0);
171 void Register_EOS_Callback (LPFNEOSCALLBACK callback, DWORD user_param);
172 void UnRegister_EOS_Callback (LPFNEOSCALLBACK callback);
173 void Register_Text_Callback (LPFNTEXTCALLBACK callback, DWORD user_param);
174 void UnRegister_Text_Callback (LPFNTEXTCALLBACK callback);
175 void Fire_Text_Callback (AudibleSoundClass *sound_obj, const StringClass &text);
176 bool Is_Sound_Cached (const char *string_id);
177 AudibleSoundClass * Create_Sound_Effect (FileClass &file, const char *string_id);
178 AudibleSoundClass * Create_Sound_Effect (const char *filename);
179 AudibleSoundClass * Create_Sound_Effect (const char *string_id, unsigned char *raw_wave_data, unsigned long bytes);
180 Sound3DClass * Create_3D_Sound (FileClass &file, const char *string_id, int classid_hint = CLASSID_3D);
181 Sound3DClass * Create_3D_Sound (const char *filename, int classid_hint = CLASSID_3D);
182 Sound3DClass * Create_3D_Sound (const char *string_id, unsigned char *raw_wave_data, unsigned long bytes, int classid_hint = CLASSID_3D);
183 void Set_Background_Music (const char *filename);
184 void Fade_Background_Music (const char *filename, int fade_out_time, int fade_in_time);
185 void Set_Background_Music_Offset (const char *filename, float startoffset);
186 const char * Get_Background_Music_Name (void) { return m_BackgroundMusicName; }
187 AudibleSoundClass * Peek_Background_Music (void) { return m_BackgroundMusic; }
188 LogicalSoundClass * Create_Logical_Sound (void);
189 LogicalListenerClass * Create_Logical_Listener (void);
190 void Add_Logical_Type (int id, LPCTSTR display_name);
191 void Reset_Logical_Types (void);
192 int Get_Logical_Type_Count (void) const { return m_LogicalTypes.Count (); }
193 int Get_Logical_Type (int index, StringClass &name);
194 int Create_Instant_Sound (int definition_id, const Matrix3D &tm, RefCountClass *user_obj = NULL, uint32 user_data = 0, int classid_hint = CLASSID_3D);
195 int Create_Instant_Sound (const char *def_name, const Matrix3D &tm, RefCountClass *user_obj = NULL, uint32 user_data = 0, int classid_hint = CLASSID_3D);
196 AudibleSoundClass * Create_Continuous_Sound (int definition_id, RefCountClass *user_obj = NULL, uint32 user_data = 0, int classid_hint = CLASSID_3D);
197 AudibleSoundClass * Create_Continuous_Sound (const char *def_name, RefCountClass *user_obj = NULL, uint32 user_data = 0, int classid_hint = CLASSID_3D);
198 AudibleSoundClass * Create_Sound (int definition_id, RefCountClass *user_obj = NULL, uint32 user_data = 0, int classid_hint = CLASSID_3D);
199 AudibleSoundClass * Create_Sound (const char *def_name, RefCountClass *user_obj = NULL, uint32 user_data = 0, int classid_hint = CLASSID_3D);
200 SoundSceneObjClass * Find_Sound_Object (uint32 sound_obj_id);
201#if !defined(W3DVIEWER) && !defined(TTLE_EXPORTS)
202 SoundSceneObjClass* Find_Server_Sound_Object(uint32 server_sound_obj_id); // Added by TT
203 uint32 Get_New_Server_Sound_ID(); // Added by TT
204#endif
205 SoundSceneClass * Get_Sound_Scene (void) const { return m_SoundScene; }
206 bool Set_Cache_Size (int kbytes = DEF_CACHE_SIZE) { m_MaxCacheSize = (kbytes * 1024); }
207 int Get_Cache_Size (void) const { return m_MaxCacheSize / 1024; }
208 int Get_Current_Cache_Size (void) const { return m_CurrentCacheSize; }
209 void Flush_Cache (void);
210 void Set_Max_2D_Sound_Buffer (int bytes = DEF_MAX_2D_BUFFER_SIZE) { m_Max2DBufferSize = bytes; }
211 void Set_Max_3D_Sound_Buffer (int bytes = DEF_MAX_3D_BUFFER_SIZE) { m_Max3DBufferSize = bytes; }
212 bool Simple_Play_2D_Sound_Effect (const char *filename, float priority = 1.0F, float volume = DEF_SFX_VOL);
213 bool Simple_Play_2D_Sound_Effect (FileClass &file, float priority = 1.0F, float volume = DEF_SFX_VOL);
214 bool Add_To_Playlist (AudibleSoundClass *sound);
215 bool Remove_From_Playlist (AudibleSoundClass *sound);
216 int Get_Playlist_Count (void) const { return m_Playlist[m_CurrPage].Count (); }
217 AudibleSoundClass * Get_Playlist_Entry (int index) const;
218 AudibleSoundClass * Peek_Playlist_Entry (int index) const { return m_Playlist[m_CurrPage][index]; }
219 void Flush_Playlist (void);
220 void Flush_Playlist (SOUND_PAGE page);
221 bool Is_Sound_In_Playlist (AudibleSoundClass *sound_obj);
222 bool Acquire_Virtual_Channel (AudibleSoundClass *sound_obj, int channel_index);
223 void Release_Virtual_Channel (AudibleSoundClass *sound_obj, int channel_index);
224 void Set_Active_Sound_Page (SOUND_PAGE page);
225 SOUND_PAGE Get_Active_Sound_Page (void) { m_CurrPage; }
226 void Push_Active_Sound_Page (SOUND_PAGE page);
227 void Pop_Active_Sound_Page (void);
228 void Fade_Non_Dialog_In (void);
229 void Fade_Non_Dialog_Out (void);
230 void Set_Non_Dialog_Fade_Time (float fade_time) { m_NonDialogFadeTime = fade_time; }
231 float Get_Digital_CPU_Percent (void) const;
232 bool Is_Disabled (void) const;
233 int Get_2D_Sample_Count (void) const { return m_2DSampleHandles.Count (); }
234 int Get_3D_Sample_Count (void) const { return m_3DSampleHandles.Count (); }
235 AudibleSoundClass * Peek_2D_Sample (int index);
236 AudibleSoundClass * Peek_3D_Sample (int index);
237 void Free_Completed_Sounds (void);
238public:
239 void Build_3D_Driver_List (void);
240 void Free_3D_Driver_List (void);
241 void Reprioritize_Playlist (void);
242 bool Validate_3D_Sound_Buffer (SoundBufferClass *buffer);
243 FileClass * Get_File (LPCTSTR filename);
244 void Return_File (FileClass *file);
245 void Allocate_2D_Handles (void);
246 void Release_2D_Handles (void);
247 void Allocate_3D_Handles (void);
248 void Release_3D_Handles (void);
249 HSAMPLE Get_2D_Sample (const AudibleSoundClass &sound_obj);
250 H3DSAMPLE Get_3D_Sample (const Sound3DClass &sound_obj);
251 H3DPOBJECT Get_Listener_Handle (void);
252 void ReAssign_2D_Handles (void);
253 void ReAssign_3D_Handles (void);
254 void Remove_2D_Sound_Handles (void);
255 void Remove_3D_Sound_Handles (void);
256 bool Is_OK_To_Give_Handle (const AudibleSoundClass &sound_obj);
257 void Update_Fade (void);
258 void Internal_Set_Sound_Effects_Volume (float volume);
259 void Internal_Set_Music_Volume (float volume);
260 SoundBufferClass * Get_Sound_Buffer (FileClass &file, const char *string_id, bool is_3d);
261 SoundBufferClass * Get_Sound_Buffer (const char *filename, bool is_3d);
262 SoundBufferClass * Find_Cached_Buffer (const char *string_id);
263 SoundBufferClass * Create_Sound_Buffer (FileClass &file, const char *string_id, bool is_3d);
264 SoundBufferClass * Create_Sound_Buffer (unsigned char *file_image, unsigned long bytes, const char *string_id, bool is_3d);
265 bool Cache_Buffer (SoundBufferClass *buffer, const char *string_id);
266 bool Free_Cache_Space (int bytes);
267 static unsigned int AILCALLBACK File_Open_Callback (char const *filename, unsigned int *file_handle);
268 static void AILCALLBACK File_Close_Callback (unsigned int file_handle);
269 static signed int AILCALLBACK File_Seek_Callback (unsigned int file_handle, signed int offset, unsigned int type);
270 static unsigned int AILCALLBACK File_Read_Callback (unsigned int file_handle, void *buffer, unsigned int bytes);
271private:
272#ifndef W3DVIEWER
273 static REF_DECL(WWAudioClass *, _theInstance);
274#else
275 static WWAudioClass *_theInstance;
276#endif
277 static HANDLE _TimerSyncEvent;
278 typedef struct _CACHE_ENTRY_STRUCT : public NoEqualsClass<_CACHE_ENTRY_STRUCT>
279 {
280 const char* string_id;
281 SoundBufferClass* buffer;
282 } CACHE_ENTRY_STRUCT;
283 typedef struct _LOGICAL_TYPE_STRUCT
284 {
285 StringClass display_name;
286 int id;
287 _LOGICAL_TYPE_STRUCT (void)
288 : id (0) {}
289 _LOGICAL_TYPE_STRUCT (int _id, LPCTSTR name)
290 : display_name (name), id (_id) {}
291 bool operator== (const _LOGICAL_TYPE_STRUCT &src) { return false; }
292 bool operator!= (const _LOGICAL_TYPE_STRUCT &src) { return true; }
293 } LOGICAL_TYPE_STRUCT;
294 typedef enum
295 {
296 FADE_NONE = 0,
297 FADE_IN,
298 FADE_OUT,
299 FADED_OUT,
300 } FADE_TYPE;
301
302 int m_PlaybackRate; // 0004
303 int m_PlaybackBits; // 0008
304 bool m_PlaybackStereo; // 000C
305 float m_MusicVolume; // 0010
306 float m_SoundVolume; // 0014
307 float m_RealMusicVolume; // 0018
308 float m_RealSoundVolume; // 001C
309 float m_DialogVolume; // 0020
310 float m_CinematicVolume; // 0024
311 int m_Max2DSamples; // 0028
312 int m_Max3DSamples; // 002C
313 int m_Max2DBufferSize; // 0030
314 int m_Max3DBufferSize; // 0034
315 HTIMER m_UpdateTimer; // 0038
316 bool m_IsMusicEnabled; // 003C
317 bool m_IsDialogEnabled; // 003D
318 bool m_IsCinematicSoundEnabled; // 003E
319 bool m_AreSoundEffectsEnabled; // 003F
320 bool m_AreNewSoundsEnabled; // 0040
321 FileFactoryClass * m_FileFactory; // 0044
322 AudibleSoundClass * m_BackgroundMusic; // 0048
323 StringClass m_BackgroundMusicName; // 004C
324 bool m_CachedIsMusicEnabled; // 0050
325 bool m_CachedIsDialogEnabled; // 0051
326 bool m_CachedIsCinematicSoundEnabled; // 0052
327 bool m_CachedAreSoundEffectsEnabled; // 0053
328 AudioCallbackListClass<LPFNEOSCALLBACK> m_EOSCallbackList; // 0054
329 AudioCallbackListClass<LPFNTEXTCALLBACK> m_TextCallbackList; // 0064
330 SoundSceneClass * m_SoundScene; // 0074
331 SOUND_PAGE m_CurrPage; // 0078
332 DynamicVectorClass<SOUND_PAGE> m_PageStack; // 007C
333 HDIGDRIVER m_Driver2D; // 0094
334 HPROVIDER m_Driver3D; // 0098
335 HPROVIDER m_Driver3DPseudo; // 009C
336 HPROVIDER m_ReverbFilter; // 00A0
337 DynamicVectorClass<DRIVER_INFO_STRUCT *> m_Driver3DList; // 00A4
338 StringClass m_Driver3DName; // 00BC
339 int m_SpeakerType; // 00C0
340 DynamicVectorClass<HSAMPLE> m_2DSampleHandles; // 00C4
341 DynamicVectorClass<H3DSAMPLE> m_3DSampleHandles; // 00DC
342 DynamicVectorClass<AudibleSoundClass *> m_Playlist[PAGE_COUNT]; // 00F4
343 DynamicVectorClass<AudibleSoundClass *> m_CompletedSounds; // 013C
344 DynamicVectorClass<AudibleSoundClass *> m_VirtualChannels; // 0154
345 DynamicVectorClass<CACHE_ENTRY_STRUCT> m_CachedBuffers[MAX_CACHE_HASH]; // 016C
346 int m_MaxCacheSize; // 196C
347 int m_CurrentCacheSize; // 1970
348 DynamicVectorClass<LOGICAL_TYPE_STRUCT> m_LogicalTypes; // 1974
349 float m_EffectsLevel; // 198C
350 int m_ReverbRoomType; // 1990
351 float m_NonDialogFadeTime; // 1994
352 FADE_TYPE m_FadeType; // 1998
353 float m_FadeTimer; // 199C
354 INIClass* AudioIni; // 19A0
355 bool m_ForceDisable; // 19A4
356}; // 19A5
357#endif