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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 "gob/gob.h"
#include "gob/sound/sound.h"
#include "gob/global.h"
#include "gob/util.h"
#include "gob/dataio.h"
#include "gob/game.h"
#include "gob/inter.h"
#include "gob/sound/pcspeaker.h"
#include "gob/sound/soundblaster.h"
#include "gob/sound/adlib.h"
#include "gob/sound/infogrames.h"
#include "gob/sound/protracker.h"
#include "gob/sound/cdrom.h"
namespace Gob {
Sound::Sound(GobEngine *vm) : _vm(vm) {
_pcspeaker = new PCSpeaker(*_vm->_mixer);
_blaster = new SoundBlaster(*_vm->_mixer);
_adlPlayer = 0;
_mdyPlayer = 0;
_infogrames = 0;
_protracker = 0;
_cdrom = 0;
_bgatmos = 0;
_hasAdLib = (!_vm->_noMusic && _vm->hasAdLib());
if (!_vm->_noMusic && (_vm->getPlatform() == Common::kPlatformAmiga)) {
_infogrames = new Infogrames(*_vm->_mixer);
_protracker = new Protracker(*_vm->_mixer);
}
if (_vm->isCD())
_cdrom = new CDROM;
if (_vm->getGameType() == kGameTypeWoodruff)
_bgatmos = new BackgroundAtmosphere(*_vm->_mixer);
if ((_vm->getGameType() == kGameTypeUrban) ||
(_vm->getGameType() == kGameTypeAdibou2)) {
_bgatmos = new BackgroundAtmosphere(*_vm->_mixer);
_bgatmos->setShadable(false);
}
}
Sound::~Sound() {
delete _pcspeaker;
delete _blaster;
delete _adlPlayer;
delete _mdyPlayer;
delete _infogrames;
delete _protracker;
delete _cdrom;
delete _bgatmos;
for (int i = 0; i < kSoundsCount; i++)
_sounds[i].free();
}
void Sound::convToSigned(byte *buffer, int length) {
while (length-- > 0)
*buffer++ ^= 0x80;
}
SoundDesc *Sound::sampleGetBySlot(int slot) {
if ((slot < 0) || (slot >= kSoundsCount))
return 0;
return &_sounds[slot];
}
const SoundDesc *Sound::sampleGetBySlot(int slot) const {
if ((slot < 0) || (slot >= kSoundsCount))
return 0;
return &_sounds[slot];
}
int Sound::sampleGetNextFreeSlot() const {
for (int i = 0; i < kSoundsCount; i++)
if (_sounds[i].empty())
return i;
return -1;
}
bool Sound::sampleLoad(SoundDesc *sndDesc, SoundType type, const char *fileName, bool tryExist) {
if (!sndDesc)
return false;
debugC(2, kDebugSound, "Loading sample \"%s\"", fileName);
int32 size;
byte *data = _vm->_dataIO->getFile(fileName, size);
if (!data) {
warning("Can't open sample file \"%s\"", fileName);
return false;
}
return sndDesc->load(type, data, size);
}
void Sound::sampleFree(SoundDesc *sndDesc, bool noteAdLib, int index) {
if (!sndDesc || sndDesc->empty())
return;
if (sndDesc->getType() == SOUND_ADL) {
if (noteAdLib) {
if (_adlPlayer)
if ((index == -1) || (_adlPlayer->getIndex() == index))
_adlPlayer->stopPlay();
if (_mdyPlayer)
if ((index == -1) || (_mdyPlayer->getIndex() == index))
_mdyPlayer->stopPlay();
}
} else {
if (_blaster)
_blaster->stopSound(0, sndDesc);
}
sndDesc->free();
}
void Sound::speakerOn(int16 frequency, int32 length) {
if (!_pcspeaker)
return;
debugC(1, kDebugSound, "PCSpeaker: Playing tone (%d, %d)", frequency, length);
_pcspeaker->speakerOn(frequency, length);
}
void Sound::speakerOff() {
if (!_pcspeaker)
return;
debugC(1, kDebugSound, "PCSpeaker: Stopping tone");
_pcspeaker->speakerOff();
}
void Sound::speakerOnUpdate(uint32 millis) {
if (!_pcspeaker)
return;
_pcspeaker->onUpdate(millis);
}
bool Sound::infogramesLoadInstruments(const char *fileName) {
if (!_infogrames)
return false;
debugC(1, kDebugSound, "Infogrames: Loading instruments \"%s\"", fileName);
return _infogrames->loadInstruments(fileName);
}
bool Sound::infogramesLoadSong(const char *fileName) {
if (!_infogrames)
return false;
debugC(1, kDebugSound, "Infogrames: Loading song \"%s\"", fileName);
return _infogrames->loadSong(fileName);
}
bool Sound::protrackerPlay(const char *fileName) {
if (!_protracker)
return false;
debugC(1, kDebugSound, "Protracker: Playing song \"%s\"", fileName);
return _protracker->play(fileName);
}
void Sound::protrackerStop() {
if (!_protracker)
return;
debugC(1, kDebugSound, "Protracker: Stopping playback");
_protracker->stop();
}
void Sound::infogramesPlay() {
if (!_infogrames)
return;
debugC(1, kDebugSound, "Infogrames: Starting playback");
_infogrames->play();
}
void Sound::infogramesStop() {
if (!_infogrames)
return;
debugC(1, kDebugSound, "Infogrames: Stopping playback");
_infogrames->stop();
}
bool Sound::adlibLoadADL(const char *fileName) {
if (!_hasAdLib)
return false;
if (!_adlPlayer)
_adlPlayer = new ADLPlayer(*_vm->_mixer);
debugC(1, kDebugSound, "AdLib: Loading ADL data (\"%s\")", fileName);
return _adlPlayer->load(fileName);
}
bool Sound::adlibLoadADL(byte *data, uint32 size, int index) {
if (!_hasAdLib)
return false;
if (!_adlPlayer)
_adlPlayer = new ADLPlayer(*_vm->_mixer);
debugC(1, kDebugSound, "AdLib: Loading ADL data (%d)", index);
return _adlPlayer->load(data, size, index);
}
void Sound::adlibUnload() {
if (!_hasAdLib)
return;
debugC(1, kDebugSound, "AdLib: Unloading data");
if (_adlPlayer)
_adlPlayer->unload();
if (_mdyPlayer)
_mdyPlayer->unload();
}
bool Sound::adlibLoadMDY(const char *fileName) {
if (!_hasAdLib)
return false;
if (!_mdyPlayer)
_mdyPlayer = new MDYPlayer(*_vm->_mixer);
debugC(1, kDebugSound, "AdLib: Loading MDY data (\"%s\")", fileName);
Common::SeekableReadStream *stream = _vm->_dataIO->getFile(fileName);
if (!stream) {
warning("Can't open MDY file \"%s\"", fileName);
return false;
}
bool loaded = _mdyPlayer->loadMDY(*stream);
delete stream;
return loaded;
}
bool Sound::adlibLoadTBR(const char *fileName) {
if (!_hasAdLib)
return false;
if (!_mdyPlayer)
_mdyPlayer = new MDYPlayer(*_vm->_mixer);
Common::SeekableReadStream *stream = _vm->_dataIO->getFile(fileName);
if (!stream) {
warning("Can't open TBR file \"%s\"", fileName);
return false;
}
debugC(1, kDebugSound, "AdLib: Loading MDY instruments (\"%s\")", fileName);
bool loaded = _mdyPlayer->loadTBR(*stream);
delete stream;
return loaded;
}
void Sound::adlibPlayTrack(const char *trackname) {
if (!_hasAdLib)
return;
if (!_adlPlayer)
_adlPlayer = new ADLPlayer(*_vm->_mixer);
if (_adlPlayer->isPlaying())
return;
debugC(1, kDebugSound, "AdLib: Playing ADL track \"%s\"", trackname);
_adlPlayer->unload();
_adlPlayer->load(trackname);
_adlPlayer->startPlay();
}
void Sound::adlibPlayBgMusic() {
if (!_hasAdLib)
return;
if (!_adlPlayer)
_adlPlayer = new ADLPlayer(*_vm->_mixer);
static const char *tracksMac[] = {
// "musmac1.adl", // TODO: This track isn't played correctly at all yet
"musmac2.adl",
"musmac3.adl",
"musmac4.adl",
"musmac5.adl",
"musmac6.adl"
};
static const char *tracksWin[] = {
"musmac1.mid",
"musmac2.mid",
"musmac3.mid",
"musmac4.mid",
"musmac5.mid"
};
if (_vm->getPlatform() == Common::kPlatformWindows) {
int track = _vm->_util->getRandom(ARRAYSIZE(tracksWin));
adlibPlayTrack(tracksWin[track]);
} else {
int track = _vm->_util->getRandom(ARRAYSIZE(tracksMac));
adlibPlayTrack(tracksMac[track]);
}
}
void Sound::adlibPlay() {
if (!_hasAdLib)
return;
debugC(1, kDebugSound, "AdLib: Starting playback");
if (_adlPlayer)
_adlPlayer->startPlay();
if (_mdyPlayer)
_mdyPlayer->startPlay();
}
void Sound::adlibStop() {
if (!_hasAdLib)
return;
debugC(1, kDebugSound, "AdLib: Stopping playback");
if (_adlPlayer)
_adlPlayer->stopPlay();
if (_mdyPlayer)
_mdyPlayer->stopPlay();
}
bool Sound::adlibIsPlaying() const {
if (!_hasAdLib)
return false;
if (_adlPlayer && _adlPlayer->isPlaying())
return true;
if (_mdyPlayer && _mdyPlayer->isPlaying())
return true;
return false;
}
int Sound::adlibGetIndex() const {
if (!_hasAdLib)
return -1;
if (_adlPlayer)
return _adlPlayer->getIndex();
if (_mdyPlayer)
return _mdyPlayer->getIndex();
return -1;
}
bool Sound::adlibGetRepeating() const {
if (!_hasAdLib)
return false;
if (_adlPlayer)
return _adlPlayer->getRepeating();
if (_mdyPlayer)
return _mdyPlayer->getRepeating();
return false;
}
void Sound::adlibSetRepeating(int32 repCount) {
if (!_hasAdLib)
return;
if (_adlPlayer)
_adlPlayer->setRepeating(repCount);
if (_mdyPlayer)
_mdyPlayer->setRepeating(repCount);
}
void Sound::blasterPlay(SoundDesc *sndDesc, int16 repCount,
int16 frequency, int16 fadeLength) {
if (!_blaster || !sndDesc)
return;
debugC(1, kDebugSound, "SoundBlaster: Playing sample (%d, %d, %d)",
repCount, frequency, fadeLength);
_blaster->playSample(*sndDesc, repCount, frequency, fadeLength);
}
void Sound::blasterStop(int16 fadeLength, SoundDesc *sndDesc) {
if (!_blaster)
return;
debugC(1, kDebugSound, "SoundBlaster: Stopping playback");
_blaster->stopSound(fadeLength, sndDesc);
}
void Sound::blasterPlayComposition(int16 *composition, int16 freqVal,
SoundDesc *sndDescs, int8 sndCount) {
if (!_blaster)
return;
debugC(1, kDebugSound, "SoundBlaster: Playing composition (%d, %d)",
freqVal, sndCount);
blasterWaitEndPlay();
_blaster->stopComposition();
if (!sndDescs)
sndDescs = _sounds;
_blaster->playComposition(composition, freqVal, sndDescs, sndCount);
}
void Sound::blasterStopComposition() {
if (!_blaster)
return;
debugC(1, kDebugSound, "SoundBlaster: Stopping composition");
_blaster->stopComposition();
}
char Sound::blasterPlayingSound() const {
if (!_blaster)
return 0;
return _blaster->getPlayingSound();
}
void Sound::blasterSetRepeating(int32 repCount) {
if (!_blaster)
return;
_blaster->setRepeating(repCount);
}
void Sound::blasterWaitEndPlay(bool interruptible, bool stopComp) {
if (!_blaster)
return;
debugC(1, kDebugSound, "SoundBlaster: Waiting for playback to end");
if (stopComp)
_blaster->endComposition();
while (_blaster->isPlaying() && !_vm->shouldQuit()) {
if (interruptible && (_vm->_util->checkKey() == kKeyEscape)) {
WRITE_VAR(57, (uint32) -1);
return;
}
_vm->_util->longDelay(200);
}
_blaster->stopSound(0);
}
void Sound::cdLoadLIC(const Common::String &fname) {
if (!_cdrom)
return;
debugC(1, kDebugSound, "CDROM: Loading LIC \"%s\"", fname.c_str());
Common::SeekableReadStream *stream = _vm->_dataIO->getFile(fname);
if (!stream)
return;
_cdrom->readLIC(*stream);
delete stream;
}
void Sound::cdUnloadLIC() {
if (!_cdrom)
return;
debugC(1, kDebugSound, "CDROM: Unloading LIC");
_cdrom->freeLICBuffer();
}
void Sound::cdPlayBgMusic() {
if (!_cdrom)
return;
static const char *tracks[][2] = {
{"avt00.tot", "mine"},
{"avt001.tot", "nuit"},
{"avt002.tot", "campagne"},
{"avt003.tot", "extsor1"},
{"avt004.tot", "interieure"},
{"avt005.tot", "zombie"},
{"avt006.tot", "zombie"},
{"avt007.tot", "campagne"},
{"avt008.tot", "campagne"},
{"avt009.tot", "extsor1"},
{"avt010.tot", "extsor1"},
{"avt011.tot", "interieure"},
{"avt012.tot", "zombie"},
{"avt014.tot", "nuit"},
{"avt015.tot", "interieure"},
{"avt016.tot", "statue"},
{"avt017.tot", "zombie"},
{"avt018.tot", "statue"},
{"avt019.tot", "mine"},
{"avt020.tot", "statue"},
{"avt021.tot", "mine"},
{"avt022.tot", "zombie"}
};
for (int i = 0; i < ARRAYSIZE(tracks); i++)
if (_vm->isCurrentTot(tracks[i][0])) {
debugC(1, kDebugSound, "CDROM: Playing background music \"%s\" (\"%s\")", tracks[i][1], tracks[i][0]);
_cdrom->startTrack(tracks[i][1]);
break;
}
}
void Sound::cdPlayMultMusic() {
if (!_cdrom)
return;
static const char *tracks[][6] = {
{"avt005.tot", "fra1", "all1", "ang1", "esp1", "ita1"},
{"avt006.tot", "fra2", "all2", "ang2", "esp2", "ita2"},
{"avt012.tot", "fra3", "all3", "ang3", "esp3", "ita3"},
{"avt016.tot", "fra4", "all4", "ang4", "esp4", "ita4"},
{"avt019.tot", "fra5", "all5", "ang5", "esp5", "ita5"},
{"avt022.tot", "fra6", "all6", "ang6", "esp6", "ita6"}
};
// Default to "ang?" for other languages (including EN_USA)
int language = _vm->_global->_language <= 4 ? _vm->_global->_language : 2;
for (int i = 0; i < ARRAYSIZE(tracks); i++)
if (_vm->isCurrentTot(tracks[i][0])) {
debugC(1, kDebugSound, "CDROM: Playing mult music \"%s\" (\"%s\")", tracks[i][language + 1], tracks[i][0]);
_cdrom->startTrack(tracks[i][language + 1]);
break;
}
}
void Sound::cdPlay(const Common::String &trackName) {
if (!_cdrom)
return;
debugC(1, kDebugSound, "CDROM: Playing track \"%s\"", trackName.c_str());
// WORKAROUND - In Fascination CD, in the storage room, a track has the wrong
// name in the scripts, and therefore doesn't play. This fixes the problem.
if ((_vm->getGameType() == kGameTypeFascination) && trackName.equalsIgnoreCase("boscle"))
_cdrom->startTrack("bosscle");
else
_cdrom->startTrack(trackName.c_str());
}
void Sound::cdStop() {
if (!_cdrom)
return;
debugC(1, kDebugSound, "CDROM: Stopping playback");
_cdrom->stopPlaying();
}
bool Sound::cdIsPlaying() const {
if (!_cdrom)
return false;
return _cdrom->isPlaying();
}
int32 Sound::cdGetTrackPos(const char *keyTrack) const {
if (!_cdrom)
return -1;
return _cdrom->getTrackPos(keyTrack);
}
const char *Sound::cdGetCurrentTrack() const {
if (!_cdrom)
return "";
return _cdrom->getCurTrack();
}
void Sound::cdTest(int trySubst, const char *label) {
if (!_cdrom)
return;
_cdrom->testCD(trySubst, label);
}
void Sound::bgPlay(const char *file, SoundType type) {
if (!_bgatmos)
return;
debugC(1, kDebugSound, "BackgroundAtmosphere: Playing \"%s\"", file);
_bgatmos->stopBA();
_bgatmos->queueClear();
SoundDesc *sndDesc = new SoundDesc;
if (!sampleLoad(sndDesc, type, file)) {
delete sndDesc;
return;
}
_bgatmos->queueSample(*sndDesc);
_bgatmos->playBA();
}
void Sound::bgPlay(const char *base, const char *ext, SoundType type, int count) {
if (!_bgatmos)
return;
debugC(1, kDebugSound, "BackgroundAtmosphere: Playing \"%s\" (%d)", base, count);
_bgatmos->stopBA();
_bgatmos->queueClear();
int length = strlen(base) + 7;
char *fileName = new char[length];
SoundDesc *sndDesc;
for (int i = 1; i <= count; i++) {
snprintf(fileName, length, "%s%02d.%s", base, i, ext);
sndDesc = new SoundDesc;
if (sampleLoad(sndDesc, type, fileName))
_bgatmos->queueSample(*sndDesc);
else
delete sndDesc;
}
_bgatmos->playBA();
}
void Sound::bgStop() {
if (!_bgatmos)
return;
debugC(1, kDebugSound, "BackgroundAtmosphere: Stopping playback");
_bgatmos->stopBA();
_bgatmos->queueClear();
}
void Sound::bgSetPlayMode(BackgroundAtmosphere::PlayMode mode) {
if (!_bgatmos)
return;
_bgatmos->setPlayMode(mode);
}
void Sound::bgShade() {
if (!_bgatmos)
return;
debugC(1, kDebugSound, "BackgroundAtmosphere: Shading playback");
_bgatmos->shade();
}
void Sound::bgUnshade() {
if (!_bgatmos)
return;
debugC(1, kDebugSound, "BackgroundAtmosphere: Unshading playback");
_bgatmos->unshade();
}
} // End of namespace Gob
|