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