12#ifndef __WWAUDIOCLASS_H__
13#define __WWAUDIOCLASS_H__
14#include "engine_common.h"
15#include "engine_string.h"
16#include "engine_vector.h"
18#include "AudioCallbackListClass.h"
21#include "SoundBufferClass.h"
22class AudibleSoundClass;
24class Sound2DTriggerClass;
25class StreamSoundClass;
28class FileFactoryClass;
29class SoundSceneObjClass;
30class LogicalListenerClass;
31class LogicalSoundClass;
34typedef unsigned int HPROVIDER;
35typedef void *HDIGDRIVER;
37typedef void *H3DSAMPLE;
38typedef void *H3DPOBJECT;
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
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;
71 CACHE_HASH_MASK = 0x000000FF
101 typedef struct _DRIVER_INFO_STRUCT
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; }
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; }
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);
203 uint32 Get_New_Server_Sound_ID();
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);
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);
273 static REF_DECL(WWAudioClass *, _theInstance);
275 static WWAudioClass *_theInstance;
277 static HANDLE _TimerSyncEvent;
278 typedef struct _CACHE_ENTRY_STRUCT :
public NoEqualsClass<_CACHE_ENTRY_STRUCT>
280 const char* string_id;
281 SoundBufferClass* buffer;
282 } CACHE_ENTRY_STRUCT;
283 typedef struct _LOGICAL_TYPE_STRUCT
285 StringClass display_name;
287 _LOGICAL_TYPE_STRUCT (
void)
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;
304 bool m_PlaybackStereo;
307 float m_RealMusicVolume;
308 float m_RealSoundVolume;
309 float m_DialogVolume;
310 float m_CinematicVolume;
313 int m_Max2DBufferSize;
314 int m_Max3DBufferSize;
315 HTIMER m_UpdateTimer;
316 bool m_IsMusicEnabled;
317 bool m_IsDialogEnabled;
318 bool m_IsCinematicSoundEnabled;
319 bool m_AreSoundEffectsEnabled;
320 bool m_AreNewSoundsEnabled;
321 FileFactoryClass * m_FileFactory;
322 AudibleSoundClass * m_BackgroundMusic;
323 StringClass m_BackgroundMusicName;
324 bool m_CachedIsMusicEnabled;
325 bool m_CachedIsDialogEnabled;
326 bool m_CachedIsCinematicSoundEnabled;
327 bool m_CachedAreSoundEffectsEnabled;
328 AudioCallbackListClass<LPFNEOSCALLBACK> m_EOSCallbackList;
329 AudioCallbackListClass<LPFNTEXTCALLBACK> m_TextCallbackList;
330 SoundSceneClass * m_SoundScene;
331 SOUND_PAGE m_CurrPage;
332 DynamicVectorClass<SOUND_PAGE> m_PageStack;
333 HDIGDRIVER m_Driver2D;
334 HPROVIDER m_Driver3D;
335 HPROVIDER m_Driver3DPseudo;
336 HPROVIDER m_ReverbFilter;
337 DynamicVectorClass<DRIVER_INFO_STRUCT *> m_Driver3DList;
338 StringClass m_Driver3DName;
340 DynamicVectorClass<HSAMPLE> m_2DSampleHandles;
341 DynamicVectorClass<H3DSAMPLE> m_3DSampleHandles;
342 DynamicVectorClass<AudibleSoundClass *> m_Playlist[PAGE_COUNT];
343 DynamicVectorClass<AudibleSoundClass *> m_CompletedSounds;
344 DynamicVectorClass<AudibleSoundClass *> m_VirtualChannels;
345 DynamicVectorClass<CACHE_ENTRY_STRUCT> m_CachedBuffers[MAX_CACHE_HASH];
347 int m_CurrentCacheSize;
348 DynamicVectorClass<LOGICAL_TYPE_STRUCT> m_LogicalTypes;
349 float m_EffectsLevel;
350 int m_ReverbRoomType;
351 float m_NonDialogFadeTime;
352 FADE_TYPE m_FadeType;