1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
/* ScummVM - Scumm Interpreter
* Copyright (C) 2005-2006 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#include "lure/sound.h"
#include "lure/game.h"
#include "lure/res.h"
#include "lure/room.h"
DECLARE_SINGLETON(Lure::SoundManager);
namespace Lure {
SoundManager::SoundManager() {
_descs = Disk::getReference().getEntry(SOUND_DESC_RESOURCE_ID);
_numDescs = _descs->size() / sizeof(SoundDescResource);
for (int channelNum = 0; channelNum < NUM_CHANNELS; ++channelNum)
_channels[channelNum] = 0;
}
void SoundManager::bellsBodge() {
Resources &res = Resources::getReference();
Room &room = Room::getReference();
RoomData *roomData = res.getRoom(room.roomNumber());
if (roomData->areaFlag != res.fieldList().getField(AREA_FLAG)) {
res.fieldList().setField(AREA_FLAG, roomData->areaFlag);
switch (roomData->areaFlag) {
case 0:
killSound(1);
break;
case 1:
addSound(2);
killSound(33);
break;
case 2:
setVolume(0, 15);
// Deliberate fall through
default:
killSound(1);
break;
}
}
}
void SoundManager::killSounds() {
// Stop the player playing all sounds
musicInterface_KillAll();
// Clear the active sounds
_activeSounds.clear();
for (int channelNum = 0; channelNum < NUM_CHANNELS; ++channelNum)
_channels[channelNum] = 0;
}
void SoundManager::addSound(uint8 soundIndex, bool tidyFlag) {
Game &game = Game::getReference();
if (tidyFlag)
tidySounds();
if (game.preloadFlag())
// Don't add a sound if in room preloading
return;
SoundDescResource &rec = soundDescs()[soundIndex];
int numChannels = (rec.numChannels >> 2) & 3;
int channelCtr = 0;
while (channelCtr < NUM_CHANNELS) {
if (_channels[channelCtr] == 0) {
bool foundSpace = true;
int channelCtr2 = 0;
while (channelCtr2 < numChannels) {
foundSpace = _channels[channelCtr2] == 0;
if (!foundSpace) break;
++channelCtr2;
}
if (foundSpace)
break;
}
++channelCtr;
}
if (channelCtr == 8)
// No channels free
return;
// Mark the found channels as in use
for (int channelCtr2 = 0; channelCtr2 < numChannels; ++channelCtr2)
_channels[channelCtr + channelCtr2] = 1;
SoundDescResource *newEntry = new SoundDescResource();
newEntry->soundNumber = rec.soundNumber;
newEntry->channel = channelCtr;
newEntry->numChannels = numChannels;
newEntry->flags = rec.flags;
newEntry->volume = rec.volume;
_activeSounds.push_back(newEntry);
musicInterface_Play(rec.soundNumber, false, channelCtr);
setVolume(rec.soundNumber, rec.volume);
}
void SoundManager::addSound2(uint8 soundIndex) {
tidySounds();
if (soundIndex == 6)
// Chinese torture
addSound(6);
else
{
SoundDescResource &descEntry = soundDescs()[soundIndex];
SoundDescResource *rec = findSound(descEntry.soundNumber);
if (rec == NULL)
// Sound isn't active, so go and add it
addSound(soundIndex, false);
}
}
void SoundManager::stopSound(uint8 soundIndex) {
SoundDescResource &rec = soundDescs()[soundIndex];
musicInterface_Stop(rec.soundNumber & 0x7f);
}
void SoundManager::killSound(uint8 soundNumber) {
musicInterface_Stop(soundNumber & 0x7f);
}
void SoundManager::setVolume(uint8 soundNumber, uint8 volume) {
SoundDescResource *entry = findSound(soundNumber);
if (entry == NULL) return;
// Special check is done for Adlib in original game, to ignore any volume changes
}
SoundDescResource *SoundManager::findSound(uint8 soundNumber) {
ManagedList<SoundDescResource *>::iterator i;
for (i = _activeSounds.begin(); i != _activeSounds.end(); ++i) {
SoundDescResource *rec = *i;
if (rec->soundNumber == soundNumber)
return rec;
}
// Signal that sound wasn't found
return NULL;
}
void SoundManager::tidySounds() {
ManagedList<SoundDescResource *>::iterator i = _activeSounds.begin();
while (i != _activeSounds.end()) {
SoundDescResource *rec = *i;
if (musicInterface_CheckPlaying(rec->soundNumber & 0x7f))
// Still playing, so move to next entry
++i;
else {
// Mark the channels that it used as now being free
for (int channelCtr = 0; channelCtr < rec->numChannels; ++channelCtr)
_channels[rec->channel + channelCtr] = 0;
i = _activeSounds.erase(i);
}
}
}
void SoundManager::removeSounds() {
bellsBodge();
ManagedList<SoundDescResource *>::iterator i = _activeSounds.begin();
while (i != _activeSounds.end()) {
SoundDescResource *rec = *i;
if ((rec->flags & SF_IN_USE) != 0)
musicInterface_Stop(rec->soundNumber);
++i;
}
}
void SoundManager::restoreSounds() {
ManagedList<SoundDescResource *>::iterator i = _activeSounds.begin();
while (i != _activeSounds.end()) {
SoundDescResource *rec = *i;
if ((rec->numChannels != 0) && ((rec->flags & SF_RESTORE) != 0)) {
for (int channelCtr = 0; channelCtr < rec->numChannels; ++channelCtr)
_channels[rec->channel + channelCtr] = 1;
musicInterface_Play(rec->soundNumber, false, rec->channel);
musicInterface_SetVolume(rec->soundNumber, rec->volume);
}
++i;
}
}
/*------------------------------------------------------------------------*/
// musicInterface_CheckPlaying
// Play the specified sound
void SoundManager::musicInterface_Play(uint8 soundNumber, bool isEffect, uint8 channelNumber) {
}
// musicInterface_Stop
// Stops the specified sound from playing
void SoundManager::musicInterface_Stop(uint8 soundNumber) {
}
// musicInterface_CheckPlaying
// Returns true if a sound is still player
bool SoundManager::musicInterface_CheckPlaying(uint8 soundNumber) {
return true;
}
// musicInterface_SetVolume
// Sets the volume of the specified channel
void SoundManager::musicInterface_SetVolume(uint8 channelNum, uint8 volume) {
}
void SoundManager::musicInterface_KillAll() {
}
void SoundManager::musicInterface_ContinuePlaying() {
}
void SoundManager::musicInterface_TrashReverb() {
}
} // end of namespace Lure
|