1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25  *
26  */
27 
28 #ifndef ICB_SOUND_H
29 #define ICB_SOUND_H
30 
31 #include "engines/icb/common/px_common.h"
32 #include "engines/icb/common/px_clu_api.h"
33 #include "engines/icb/common/px_sfx_description.h"
34 #include "engines/icb/sound_lowlevel.h"
35 
36 namespace ICB {
37 
38 #define SPECIAL_SOUND (0xffffff)
39 
40 #define SPEECH_CHANNEL 1
41 #define MUSIC_CHANNEL 0
42 
43 // default sounds
44 
45 #define GUNSHOT_SFX_VAR 0
46 #define RICOCHET_SFX_VAR 1
47 #define TINKLE_SFX_VAR 2
48 
49 #define OPEN_SFX_VAR 0
50 #define CLOSE_SFX_VAR 1
51 
52 extern const char *gunSfxVar;
53 extern const char *defaultGunSfx;
54 extern const char *gunDesc;
55 
56 extern const char *ricochetSfxVar;
57 extern const char *defaultRicochetSfx;
58 extern const char *ricochetDesc;
59 
60 extern const char *openSfxVar;
61 extern const char *defaultOpenSfx;
62 extern const char *openDesc;
63 
64 extern const char *closeSfxVar;
65 extern const char *defaultCloseSfx;
66 extern const char *closeDesc;
67 
68 extern const char *addingMediSfxVar;
69 extern const char *defaultAddingMediSfx;
70 extern const char *defaultUsingMediSfx;
71 extern const char *addingMediDesc;
72 
73 extern const char *addingClipSfxVar;
74 extern const char *defaultAddingClipSfx;
75 extern const char *addingClipDesc;
76 
77 extern const char *activateRemoraSfxVar;
78 extern const char *activateRemoraSfx;
79 extern const char *activateRemoraDesc;
80 
81 extern const char *deactivateRemoraSfxVar;
82 extern const char *deactivateRemoraSfx;
83 extern const char *deactivateRemoraDesc;
84 
85 extern const char *emailSfxVar;
86 extern const char *defaultEmailSfx;
87 extern const char *emailDesc;
88 
89 extern const char *menuUpDownSfx;
90 extern const char *menuSelectSfx;
91 extern const char *menuCancelSfx;
92 
93 extern const char *tinkleSfxVar;
94 extern const char *defaultTinkleSfx;
95 extern const char *tinkleDesc;
96 
97 #define NO_REGISTERED_SOUND 0xffffffff
98 #define MAX_REGISTERED_SOUNDS 128
99 
100 class CRegisteredSound {
101 
102 public:
103 	uint32 m_objID;   // id of object calling us
104 	uint32 m_sndHash; // hash of sound id
105 	int32 m_channel;  // -1 for no channel        needed for the turn everything off hack...
106 
107 	PXreal m_x;
108 	PXreal m_y;
109 	PXreal m_z;
110 
111 	int32 m_restart_time;
112 	int32 m_volume;
113 
114 private:
115 	int32 m_sfxNumber; // hash value of sfx
116 
117 	int32 m_velocity;
118 	int32 m_position; // position*128
119 
120 	int32 m_current_pitch;
121 	int32 m_sample_pitch;
122 	int32 m_rand_pitch_value;
123 	int32 m_next_random_pos;
124 	int32 m_pan;
125 
126 	PXreal m_xoffset;
127 	PXreal m_yoffset;
128 	PXreal m_zoffset;
129 
130 	int8 m_objMoving;
131 	int8 m_volume_offset; // offset of volume, 127 is normal full volume effect, anything less scales down
132 
133 public:
134 	void Wipe();
135 
CRegisteredSound()136 	CRegisteredSound() : m_objID(NO_REGISTERED_SOUND) { Wipe(); }
137 
~CRegisteredSound()138 	~CRegisteredSound() {}
139 
GetObjectID()140 	inline uint32 GetObjectID() { return m_objID; }
141 
IsThisSound(uint32 obj,uint32 sndHash)142 	bool8 IsThisSound(uint32 obj, uint32 sndHash) {
143 
144 		if ((obj == m_objID) && (sndHash == m_sndHash))
145 			return TRUE8;
146 		else
147 			return FALSE8;
148 	}
149 
IsFree()150 	inline bool8 IsFree() { return (bool8)(m_objID == NO_REGISTERED_SOUND); }
IsUsed()151 	inline bool8 IsUsed() { return (bool8)(m_objID != NO_REGISTERED_SOUND); }
152 
GetChannel()153 	int32 GetChannel() { return m_channel; }
154 
155 	bool8 SetHearable();
156 	void SetUnhearable();
157 
158 	void Update10Hz(); // update 10hz (updates position etc)
159 
160 	void GetPosition();
161 
162 	void TurnOff();
163 
164 	// update every game cycle (starts samples if required, updates vol, pitch, pan, stops if end reached, etc...)
165 	void UpdateGameCycle(int32 newVol, int32 newPan);
166 
167 	void GetRandom(CSfx *sfx); // update random value
168 	void Register(const char *sndName, const char *sfxName, uint32 sfxHash, int8 volume);
169 
170 	void RegisterFromObject(const uint32 objID, const char *sndName, const char *sfxName, uint32 sfxHash, PXreal xo, PXreal yo, PXreal zo, int8 volume);
171 	void RegisterFromAbsolute(const uint32 objID, const char *sndName, const char *sfxName, uint32 sfxHash, PXreal x, PXreal y, PXreal z, int8 volume);
172 
173 	void Remove();
174 
175 	CSfx *GetSfx(); // should be reasonably fast now...
176 
177 	// volume and pan together (faster than seperate)
178 	void GetVolumeAndPan(int32 &vol, int32 &pan);
179 
180 private:
181 	bool8 m_inSession; // if TRUE sfx is in session cluster, otherwise sfx is in mission cluster
182 	bool8 m_turnOff;   // turning off
183 	bool8 m_remove;    // if true then when finihsed turning off remove the sound
184 	uint8 padding1;
185 };
186 
187 extern CRegisteredSound *g_registeredSounds[MAX_REGISTERED_SOUNDS];
188 
189 bool8 SfxExists(uint32 sfxHash);
190 bool8 SfxExists(const char *sfx);
191 
192 // full volume, central pan
193 #define menuSfxUpDown() RegisterMenuSound(menuUpDownSfx, 127, 0)
194 #define menuSfxSelect() RegisterMenuSound(menuSelectSfx, 127, 0)
195 #define menuSfxCancel() RegisterMenuSound(menuCancelSfx, 127, 0)
196 
197 int32 GetSpeechVolume();
198 int32 GetSfxVolume();
199 int32 GetMusicVolume();
200 void SetSpeechVolume(int32 v);
201 void SetSfxVolume(int32 v);
202 void SetMusicVolume(int32 v);
203 
204 // get current sound level in location (from camera)
205 // is defined as the square of the effects totaled as a percentage of 128*128*2
206 int32 GetCurrentSoundLevel();
207 
208 // update
209 void UpdateRemoraScannerSound();
210 
211 // called every game cycle
212 void UpdateHearableSounds();
213 
214 // called every 10hz
215 void UpdateSounds10Hz();
216 
217 // pause / unpause sound update...
218 void PauseSounds();
219 void UnpauseSounds();
220 
221 // turn system on or off
222 
223 void TurnOffSound();
224 void TurnOnSound();
225 
226 // start / stop
227 
228 int32 GetAssignedSounds();
229 
230 // these functions have both sfxHash and volume_offset which most calls will not use.... they will use the inlines below...
231 
232 void RegisterSoundOffset(uint32 obj, const char *offsetName, const char *sfxName, uint32 sfxHash, const char *sndID, PXreal xo, PXreal yo, PXreal zo, int32 isNico, int32 time,
233 						 int8 volume_offset);
234 void RegisterSound(uint32 obj, const char *sfxName, uint32 sfxHash, const char *sndID, int8 volume_offset);
235 void RegisterSoundAbsolute(uint32 obj, const char *sfxName, uint32 sfxHash, const char *sndID, PXreal x, PXreal y, PXreal z, int8 volume_offset);
236 void RegisterSoundTime(uint32 obj, const char *sfxName, uint32 sfxHash, const char *sndID, int32 time, int8 volume_offset);
237 void RegisterSoundSpecial(const char *sfxName, uint32 sfxHash, const char *sndID, int32 volume, int32 pan, int8 volume_offset);
238 
239 // A special function, this plays the sound centrally on the speakers and at the given volume 0-127
240 void RegisterMenuSound(const char *sfxName, uint32 sfxHash, int32 volume, int32 pan, int8 volume_offset);
241 
242 // copies of above with no hash.....!
243 
RegisterSoundOffset(uint32 obj,const char * offsetName,const char * sfxName,const char * sndID,PXreal xo,PXreal yo,PXreal zo,int32 isNico,int32 time)244 inline void RegisterSoundOffset(uint32 obj, const char *offsetName, const char *sfxName, const char *sndID, PXreal xo, PXreal yo, PXreal zo, int32 isNico, int32 time) {
245 	RegisterSoundOffset(obj, offsetName, sfxName, NULL_HASH, sndID, xo, yo, zo, isNico, time, (int8)127);
246 }
247 
RegisterSound(uint32 obj,const char * sfxName,const char * sndID)248 inline void RegisterSound(uint32 obj, const char *sfxName, const char *sndID) { RegisterSound(obj, sfxName, NULL_HASH, sndID, (int8)127); }
249 
RegisterSoundAbsolute(uint32 obj,const char * sfxName,const char * sndID,PXreal x,PXreal y,PXreal z)250 inline void RegisterSoundAbsolute(uint32 obj, const char *sfxName, const char *sndID, PXreal x, PXreal y, PXreal z) {
251 	RegisterSoundAbsolute(obj, sfxName, NULL_HASH, sndID, x, y, z, (int8)127);
252 }
253 
RegisterSoundTime(uint32 obj,const char * sfxName,const char * sndID,int32 time)254 inline void RegisterSoundTime(uint32 obj, const char *sfxName, const char *sndID, int32 time) { RegisterSoundTime(obj, sfxName, NULL_HASH, sndID, time, (int8)127); }
255 
RegisterSoundSpecial(const char * sfxName,const char * sndID,int32 volume,int32 pan)256 inline void RegisterSoundSpecial(const char *sfxName, const char *sndID, int32 volume, int32 pan) { RegisterSoundSpecial(sfxName, NULL_HASH, sndID, volume, pan, (int8)127); }
257 
RegisterMenuSound(const char * sfxName,int32 volume,int32 pan)258 inline void RegisterMenuSound(const char *sfxName, int32 volume, int32 pan) { RegisterMenuSound(sfxName, NULL_HASH, volume, pan, (int8)127); }
259 
260 // end of no hash copies
261 
262 void RemoveRegisteredSound(uint32 obj, const char *sndID);
263 
264 void RemoveAllSoundsWithID(uint32 obj);
265 
266 void StopAllSoundsNow();
267 
268 } // End of namespace ICB
269 
270 #endif
271