aboutsummaryrefslogtreecommitdiff
path: root/engines/dreamweb
diff options
context:
space:
mode:
Diffstat (limited to 'engines/dreamweb')
-rw-r--r--engines/dreamweb/dreamweb.cpp23
-rw-r--r--engines/dreamweb/dreamweb.h43
-rw-r--r--engines/dreamweb/keypad.cpp11
-rw-r--r--engines/dreamweb/monitor.cpp7
-rw-r--r--engines/dreamweb/newplace.cpp3
-rw-r--r--engines/dreamweb/people.cpp16
-rw-r--r--engines/dreamweb/print.cpp8
-rw-r--r--engines/dreamweb/rain.cpp7
-rw-r--r--engines/dreamweb/saveload.cpp4
-rw-r--r--engines/dreamweb/sound.cpp90
-rw-r--r--engines/dreamweb/sound.h91
-rw-r--r--engines/dreamweb/sprite.cpp26
-rw-r--r--engines/dreamweb/stubs.cpp42
-rw-r--r--engines/dreamweb/talk.cpp28
-rw-r--r--engines/dreamweb/titles.cpp50
-rw-r--r--engines/dreamweb/use.cpp33
-rw-r--r--engines/dreamweb/vgafades.cpp3
17 files changed, 276 insertions, 209 deletions
diff --git a/engines/dreamweb/dreamweb.cpp b/engines/dreamweb/dreamweb.cpp
index 11e8e3f8cc..0ca98d5a7b 100644
--- a/engines/dreamweb/dreamweb.cpp
+++ b/engines/dreamweb/dreamweb.cpp
@@ -35,6 +35,7 @@
#include "graphics/palette.h"
#include "graphics/surface.h"
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
namespace DreamWeb {
@@ -46,21 +47,15 @@ DreamWebEngine::DreamWebEngine(OSystem *syst, const DreamWebGameDescription *gam
_roomDesc(kNumRoomTexts), _freeDesc(kNumFreeTexts),
_personText(kNumPersonTexts) {
- // Setup mixer
- _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
- _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
- _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
-
_vSyncInterrupt = false;
_console = 0;
+ _sound = 0;
DebugMan.addDebugChannel(kDebugAnimation, "Animation", "Animation Debug Flag");
DebugMan.addDebugChannel(kDebugSaveLoad, "SaveLoad", "Track Save/Load Function");
_speed = 1;
_turbo = false;
_oldMouseState = 0;
- _channel0 = 0;
- _channel1 = 0;
_datafilePrefix = "DREAMWEB.";
_speechDirName = "SPEECH";
@@ -85,16 +80,6 @@ DreamWebEngine::DreamWebEngine(OSystem *syst, const DreamWebGameDescription *gam
_openChangeSize = kInventx+(4*kItempicsize);
_quitRequested = false;
- _currentSample = 0xff;
- _channel0Playing = 0;
- _channel0Repeat = 0;
- _channel1Playing = 0xff;
-
- _volume = 0;
- _volumeTo = 0;
- _volumeDirection = 0;
- _volumeCount = 0;
-
_speechLoaded = false;
_backdropBlocks = 0;
@@ -246,6 +231,7 @@ DreamWebEngine::DreamWebEngine(OSystem *syst, const DreamWebGameDescription *gam
DreamWebEngine::~DreamWebEngine() {
DebugMan.clearAllDebugChannels();
delete _console;
+ delete _sound;
}
static void vSyncInterrupt(void *refCon) {
@@ -286,7 +272,7 @@ void DreamWebEngine::processEvents() {
return;
}
- soundHandler();
+ _sound->soundHandler();
Common::Event event;
int softKey, hardKey;
while (_eventMan->pollEvent(event)) {
@@ -382,6 +368,7 @@ void DreamWebEngine::processEvents() {
Common::Error DreamWebEngine::run() {
syncSoundSettings();
_console = new DreamWebConsole(this);
+ _sound = new DreamWebSound(this);
ConfMan.registerDefault("originalsaveload", "false");
ConfMan.registerDefault("bright_palette", true);
diff --git a/engines/dreamweb/dreamweb.h b/engines/dreamweb/dreamweb.h
index 468a1f58a8..48d44c0380 100644
--- a/engines/dreamweb/dreamweb.h
+++ b/engines/dreamweb/dreamweb.h
@@ -99,10 +99,12 @@ enum {
};
struct DreamWebGameDescription;
+class DreamWebSound;
class DreamWebEngine : public Engine {
private:
DreamWebConsole *_console;
+ DreamWebSound *_sound;
bool _vSyncInterrupt;
protected:
@@ -142,7 +144,6 @@ public:
void quit();
- void loadSounds(uint bank, const Common::String &suffix);
bool loadSpeech(const Common::String &filename);
void enableSavingOrLoading(bool enable = true) { _enableSavingOrLoading = enable; }
@@ -151,15 +152,12 @@ public:
uint8 modifyChar(uint8 c) const;
Common::String modifyFileName(const char *);
- void stopSound(uint8 channel);
-
const Common::String& getDatafilePrefix() { return _datafilePrefix; };
+ const Common::String& getSpeechDirName() { return _speechDirName; };
private:
void keyPressed(uint16 ascii);
void setSpeed(uint speed);
- void soundHandler();
- void playSound(uint8 channel, uint8 id, uint8 loops);
const DreamWebGameDescription *_gameDescription;
Common::RandomSource _rnd;
@@ -171,22 +169,6 @@ private:
uint _oldMouseState;
bool _enableSavingOrLoading;
- struct Sample {
- uint offset;
- uint size;
- Sample(): offset(), size() {}
- };
-
- struct SoundData {
- Common::Array<Sample> samples;
- Common::Array<uint8> data;
- };
- SoundData _soundData[2];
- Common::Array<uint8> _speechData;
-
- Audio::SoundHandle _channelHandle[2];
- uint8 _channel0, _channel1;
-
protected:
GameVars _vars; // saved variables
@@ -327,16 +309,6 @@ public:
// sound related
uint8 _roomsSample;
- uint8 _currentSample;
- uint8 _channel0Playing;
- uint8 _channel0Repeat;
- uint8 _channel1Playing;
-
- uint8 _volume;
- uint8 _volumeTo;
- int8 _volumeDirection;
- uint8 _volumeCount;
-
bool _speechLoaded;
// misc variables
@@ -715,15 +687,6 @@ public:
void showSaveOps();
void showLoadOps();
- // from sound.cpp
- bool loadSpeech(byte type1, int idx1, byte type2, int idx2);
- void volumeAdjust();
- void cancelCh0();
- void cancelCh1();
- void loadRoomsSample();
- void playChannel0(uint8 index, uint8 repeat);
- void playChannel1(uint8 index);
-
// from sprite.cpp
void printSprites();
void printASprite(const Sprite *sprite);
diff --git a/engines/dreamweb/keypad.cpp b/engines/dreamweb/keypad.cpp
index 002588cb70..3580f8ad52 100644
--- a/engines/dreamweb/keypad.cpp
+++ b/engines/dreamweb/keypad.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
namespace DreamWeb {
@@ -85,7 +86,7 @@ void DreamWebEngine::enterCode(uint8 digit0, uint8 digit1, uint8 digit2, uint8 d
if (_pressed == 11) {
if (isItRight(digit0, digit1, digit2, digit3))
_vars._lockStatus = 0;
- playChannel1(11);
+ _sound->playChannel1(11);
_lightCount = 120;
_pressPointer = 0;
}
@@ -180,7 +181,7 @@ void DreamWebEngine::buttonPress(uint8 buttonId) {
_graphicPress = buttonId + 21;
_pressCount = 40;
if (buttonId != 11)
- playChannel1(10);
+ _sound->playChannel1(10);
}
}
@@ -532,7 +533,7 @@ void DreamWebEngine::enterSymbol() {
_symbolGraphics.clear();
restoreReels();
workToScreenM();
- playChannel1(13);
+ _sound->playChannel1(13);
} else {
removeSetObject(46);
placeSetObject(43);
@@ -820,7 +821,7 @@ void DreamWebEngine::diaryKeyP() {
_pressCount)
return; // notkeyp
- playChannel1(16);
+ _sound->playChannel1(16);
_pressCount = 12;
_pressed = 'P';
_diaryPage--;
@@ -837,7 +838,7 @@ void DreamWebEngine::diaryKeyN() {
_pressCount)
return; // notkeyn
- playChannel1(16);
+ _sound->playChannel1(16);
_pressCount = 12;
_pressed = 'N';
_diaryPage++;
diff --git a/engines/dreamweb/monitor.cpp b/engines/dreamweb/monitor.cpp
index 4c66e7a599..4e9d8eecc1 100644
--- a/engines/dreamweb/monitor.cpp
+++ b/engines/dreamweb/monitor.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
namespace DreamWeb {
@@ -97,7 +98,7 @@ void DreamWebEngine::useMon() {
_textFile3.clear();
_getBack = 1;
- playChannel1(26);
+ _sound->playChannel1(26);
_manIsOffScreen = 0;
restoreAll();
redrawMainScrn();
@@ -180,7 +181,7 @@ void DreamWebEngine::monitorLogo() {
printLogo();
//fadeUpMon(); // FIXME: Commented out in ASM
printLogo();
- playChannel1(26);
+ _sound->playChannel1(26);
randomAccess(20);
} else {
printLogo();
@@ -288,7 +289,7 @@ void DreamWebEngine::scrollMonitor() {
printLogo();
printUnderMonitor();
workToScreen();
- playChannel1(25);
+ _sound->playChannel1(25);
}
void DreamWebEngine::showCurrentFile() {
diff --git a/engines/dreamweb/newplace.cpp b/engines/dreamweb/newplace.cpp
index ab6537422a..5b4b0260f5 100644
--- a/engines/dreamweb/newplace.cpp
+++ b/engines/dreamweb/newplace.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
namespace DreamWeb {
@@ -55,7 +56,7 @@ void DreamWebEngine::selectLocation() {
_pointerFrame = 0;
showPointer();
workToScreen();
- playChannel0(9, 255);
+ _sound->playChannel0(9, 255);
_newLocation = 255;
while (_newLocation == 255) {
diff --git a/engines/dreamweb/people.cpp b/engines/dreamweb/people.cpp
index dfb5c62618..36a756a49b 100644
--- a/engines/dreamweb/people.cpp
+++ b/engines/dreamweb/people.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
namespace DreamWeb {
@@ -149,7 +150,7 @@ void DreamWebEngine::madmanText() {
if (hasSpeech()) {
if (_speechCount > 15)
return;
- if (_channel1Playing != 255)
+ if (_sound->isChannel1Playing())
return;
origCount = _speechCount;
++_speechCount;
@@ -250,7 +251,7 @@ bool DreamWebEngine::checkSpeed(ReelRoutine &routine) {
void DreamWebEngine::sparkyDrip(ReelRoutine &routine) {
if (checkSpeed(routine))
- playChannel0(14, 0);
+ _sound->playChannel0(14, 0);
}
void DreamWebEngine::genericPerson(ReelRoutine &routine) {
@@ -430,7 +431,7 @@ void DreamWebEngine::drinker(ReelRoutine &routine) {
void DreamWebEngine::alleyBarkSound(ReelRoutine &routine) {
uint16 prevReelPointer = routine.reelPointer() - 1;
if (prevReelPointer == 0) {
- playChannel1(14);
+ _sound->playChannel1(14);
routine.setReelPointer(1000);
} else {
routine.setReelPointer(prevReelPointer);
@@ -523,7 +524,7 @@ void DreamWebEngine::gates(ReelRoutine &routine) {
if (checkSpeed(routine)) {
uint16 nextReelPointer = routine.reelPointer() + 1;
if (nextReelPointer == 116)
- playChannel1(17);
+ _sound->playChannel1(17);
if (nextReelPointer >= 110)
routine.period = 2;
if (nextReelPointer == 120) {
@@ -579,12 +580,12 @@ void DreamWebEngine::carParkDrip(ReelRoutine &routine) {
if (!checkSpeed(routine))
return; // cantdrip2
- playChannel1(14);
+ _sound->playChannel1(14);
}
void DreamWebEngine::foghornSound(ReelRoutine &routine) {
if (randomNumber() == 198)
- playChannel1(13);
+ _sound->playChannel1(13);
}
void DreamWebEngine::train(ReelRoutine &routine) {
@@ -1027,8 +1028,7 @@ void DreamWebEngine::endGameSeq(ReelRoutine &routine) {
fadeScreenDownHalf();
} else if (nextReelPointer == 324) {
fadeScreenDowns();
- _volumeTo = 7;
- _volumeDirection = 1;
+ _sound->volumeChange(7, 1);
}
if (nextReelPointer == 340)
diff --git a/engines/dreamweb/print.cpp b/engines/dreamweb/print.cpp
index a96d1f9d58..3a2c45e07b 100644
--- a/engines/dreamweb/print.cpp
+++ b/engines/dreamweb/print.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
namespace DreamWeb {
@@ -246,10 +247,9 @@ const char *DreamWebEngine::monPrint(const char *string) {
}
void DreamWebEngine::rollEndCreditsGameWon() {
- playChannel0(16, 255);
- _volume = 7;
- _volumeTo = 0;
- _volumeDirection = -1;
+ _sound->playChannel0(16, 255);
+ _sound->volumeSet(7);
+ _sound->volumeChange(0, -1);
multiGet(_mapStore, 75, 20, 160, 160);
diff --git a/engines/dreamweb/rain.cpp b/engines/dreamweb/rain.cpp
index 7db4744cbf..8e42e0c161 100644
--- a/engines/dreamweb/rain.cpp
+++ b/engines/dreamweb/rain.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
namespace DreamWeb {
@@ -50,7 +51,7 @@ void DreamWebEngine::showRain() {
}
}
- if (_channel1Playing != 255)
+ if (_sound->isChannel1Playing())
return;
if (_realLocation == 2 && _vars._beenMugged != 1)
return;
@@ -61,11 +62,11 @@ void DreamWebEngine::showRain() {
return;
uint8 soundIndex;
- if (_channel0Playing != 6)
+ if (_sound->getChannel0Playing() != 6)
soundIndex = 4;
else
soundIndex = 7;
- playChannel1(soundIndex);
+ _sound->playChannel1(soundIndex);
}
uint8 DreamWebEngine::getBlockOfPixel(uint8 x, uint8 y) {
diff --git a/engines/dreamweb/saveload.cpp b/engines/dreamweb/saveload.cpp
index 8ed17c9348..c8fb537fec 100644
--- a/engines/dreamweb/saveload.cpp
+++ b/engines/dreamweb/saveload.cpp
@@ -20,7 +20,9 @@
*
*/
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
+
#include "engines/metaengine.h"
#include "graphics/thumbnail.h"
#include "gui/saveload.h"
@@ -181,7 +183,7 @@ void DreamWebEngine::doLoad(int savegameId) {
_saveGraphics.clear();
startLoading(g_madeUpRoomDat);
- loadRoomsSample();
+ _sound->loadRoomsSample(_roomsSample);
_roomLoaded = 1;
_newLocation = 255;
clearSprites();
diff --git a/engines/dreamweb/sound.cpp b/engines/dreamweb/sound.cpp
index fcbcb9d0a0..83ddebc552 100644
--- a/engines/dreamweb/sound.cpp
+++ b/engines/dreamweb/sound.cpp
@@ -20,27 +20,52 @@
*
*/
-#include "dreamweb/dreamweb.h"
-
-#include "audio/mixer.h"
#include "audio/decoders/raw.h"
-
#include "common/config-manager.h"
+#include "common/debug.h"
+#include "common/file.h"
+
+#include "dreamweb/dreamweb.h"
+#include "dreamweb/sound.h"
namespace DreamWeb {
-bool DreamWebEngine::loadSpeech(byte type1, int idx1, byte type2, int idx2) {
+DreamWebSound::DreamWebSound(DreamWebEngine *vm) : _vm(vm) {
+ _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
+ _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
+ _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
+
+ _channel0 = 0;
+ _channel1 = 0;
+
+ _currentSample = 0xff;
+ _channel0Playing = 0;
+ _channel0Repeat = 0;
+ _channel1Playing = 255;
+
+ _volume = 0;
+ _volumeTo = 0;
+ _volumeDirection = 0;
+ _volumeCount = 0;
+}
+
+DreamWebSound::~DreamWebSound() {
+}
+
+bool DreamWebSound::loadSpeech(byte type1, int idx1, byte type2, int idx2) {
cancelCh1();
Common::String name = Common::String::format("%c%02d%c%04d.RAW", type1, idx1, type2, idx2);
- //debug("name = %s", name.c_str());
- bool result = loadSpeech(name);
+ debug(2, "loadSpeech() name:%s", name.c_str());
+ return loadSpeech(name);
+}
- _speechLoaded = result;
- return result;
+void DreamWebSound::volumeChange(uint8 value, int8 direction) {
+ _volumeTo = value;
+ _volumeDirection = direction;
}
-void DreamWebEngine::volumeAdjust() {
+void DreamWebSound::volumeAdjust() {
if (_volumeDirection == 0)
return;
if (_volume != _volumeTo) {
@@ -53,34 +78,33 @@ void DreamWebEngine::volumeAdjust() {
}
}
-void DreamWebEngine::playChannel0(uint8 index, uint8 repeat) {
+void DreamWebSound::playChannel0(uint8 index, uint8 repeat) {
debug(1, "playChannel0(index:%d, repeat:%d)", index, repeat);
_channel0Playing = index;
_channel0Repeat = repeat;
}
-void DreamWebEngine::playChannel1(uint8 index) {
+void DreamWebSound::playChannel1(uint8 index) {
if (_channel1Playing == 7)
return;
_channel1Playing = index;
}
-void DreamWebEngine::cancelCh0() {
+void DreamWebSound::cancelCh0() {
debug(1, "cancelCh0()");
_channel0Playing = 255;
_channel0Repeat = 0;
stopSound(0);
}
-void DreamWebEngine::cancelCh1() {
+void DreamWebSound::cancelCh1() {
_channel1Playing = 255;
stopSound(1);
}
-void DreamWebEngine::loadRoomsSample() {
- debug(1, "loadRoomsSample() _roomsSample:%d", _roomsSample);
- uint8 sample = _roomsSample;
+void DreamWebSound::loadRoomsSample(uint8 sample) {
+ debug(1, "loadRoomsSample(sample:%d)", sample);
if (sample == 255 || _currentSample == sample)
return; // loaded already
@@ -98,7 +122,7 @@ void DreamWebEngine::loadRoomsSample() {
loadSounds(1, sampleSuffix.c_str());
}
-void DreamWebEngine::playSound(uint8 channel, uint8 id, uint8 loops) {
+void DreamWebSound::playSound(uint8 channel, uint8 id, uint8 loops) {
debug(1, "playSound(%u, %u, %u)", channel, id, loops);
int bank = 0;
@@ -149,27 +173,27 @@ void DreamWebEngine::playSound(uint8 channel, uint8 id, uint8 loops) {
} else
stream = raw;
- if (_mixer->isSoundHandleActive(_channelHandle[channel]))
- _mixer->stopHandle(_channelHandle[channel]);
- _mixer->playStream(type, &_channelHandle[channel], stream);
+ if (_vm->_mixer->isSoundHandleActive(_channelHandle[channel]))
+ _vm->_mixer->stopHandle(_channelHandle[channel]);
+ _vm->_mixer->playStream(type, &_channelHandle[channel], stream);
}
-void DreamWebEngine::stopSound(uint8 channel) {
+void DreamWebSound::stopSound(uint8 channel) {
debug(1, "stopSound(%u)", channel);
assert(channel == 0 || channel == 1);
- _mixer->stopHandle(_channelHandle[channel]);
+ _vm->_mixer->stopHandle(_channelHandle[channel]);
if (channel == 0)
_channel0 = 0;
else
_channel1 = 0;
}
-bool DreamWebEngine::loadSpeech(const Common::String &filename) {
- if (!hasSpeech())
+bool DreamWebSound::loadSpeech(const Common::String &filename) {
+ if (!_vm->hasSpeech())
return false;
Common::File file;
- if (!file.open(_speechDirName + "/" + filename))
+ if (!file.open(_vm->getSpeechDirName() + "/" + filename))
return false;
debug(1, "loadSpeech(%s)", filename.c_str());
@@ -181,13 +205,13 @@ bool DreamWebEngine::loadSpeech(const Common::String &filename) {
return true;
}
-void DreamWebEngine::soundHandler() {
+void DreamWebSound::soundHandler() {
static uint8 volumeOld = 0, channel0Old = 0, channel0PlayingOld = 0;
if (_volume != volumeOld || _channel0 != channel0Old || _channel0Playing != channel0PlayingOld)
debug(1, "soundHandler() _volume: %d _channel0: %d _channel0Playing: %d", _volume, _channel0, _channel0Playing);
volumeOld = _volume, channel0Old = _channel0, channel0PlayingOld = _channel0Playing;
- _subtitles = ConfMan.getBool("subtitles");
+ _vm->_subtitles = ConfMan.getBool("subtitles");
volumeAdjust();
uint volume = _volume;
@@ -204,7 +228,7 @@ void DreamWebEngine::soundHandler() {
if (volume >= 8)
volume = 7;
volume = (8 - volume) * Audio::Mixer::kMaxChannelVolume / 8;
- _mixer->setChannelVolume(_channelHandle[0], volume);
+ _vm->_mixer->setChannelVolume(_channelHandle[0], volume);
uint8 ch0 = _channel0Playing;
if (ch0 == 255)
@@ -226,20 +250,20 @@ void DreamWebEngine::soundHandler() {
playSound(1, ch1, 1);
}
}
- if (!_mixer->isSoundHandleActive(_channelHandle[0])) {
+ if (!_vm->_mixer->isSoundHandleActive(_channelHandle[0])) {
if (_channel0Playing != 255 && _channel0 != 0)
debug(1, "!_mixer->isSoundHandleActive _channelHandle[0] _channel0Playing:%d _channel0:%d", _channel0Playing, _channel0);
_channel0Playing = 255;
_channel0 = 0;
}
- if (!_mixer->isSoundHandleActive(_channelHandle[1])) {
+ if (!_vm->_mixer->isSoundHandleActive(_channelHandle[1])) {
_channel1Playing = 255;
_channel1 = 0;
}
}
-void DreamWebEngine::loadSounds(uint bank, const Common::String &suffix) {
- Common::String filename = getDatafilePrefix() + suffix;
+void DreamWebSound::loadSounds(uint bank, const Common::String &suffix) {
+ Common::String filename = _vm->getDatafilePrefix() + suffix;
debug(1, "loadSounds(%u, %s)", bank, filename.c_str());
Common::File file;
if (!file.open(filename)) {
diff --git a/engines/dreamweb/sound.h b/engines/dreamweb/sound.h
new file mode 100644
index 0000000000..62def157e7
--- /dev/null
+++ b/engines/dreamweb/sound.h
@@ -0,0 +1,91 @@
+/* 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.
+ *
+ */
+
+#ifndef DREAMWEB_SOUND_H
+#define DREAMWEB_SOUND_H
+
+#include "common/array.h"
+#include "common/str.h"
+#include "audio/mixer.h"
+
+namespace DreamWeb {
+
+class DreamWebEngine;
+
+class DreamWebSound {
+public:
+ DreamWebSound(DreamWebEngine *vm);
+ ~DreamWebSound();
+
+ bool loadSpeech(byte type1, int idx1, byte type2, int idx2);
+ void volumeSet(uint8 value) { _volume = value; }
+ void volumeChange(uint8 value, int8 direction);
+ void playChannel0(uint8 index, uint8 repeat);
+ void playChannel1(uint8 index);
+ uint8 getChannel0Playing() { return _channel0Playing; }
+ bool isChannel1Playing() { return _channel1Playing != 255; }
+ void cancelCh0();
+ void cancelCh1();
+ void loadRoomsSample(uint8 sample);
+ void soundHandler();
+ void loadSounds(uint bank, const Common::String &suffix);
+
+private:
+ DreamWebEngine *_vm;
+
+ struct Sample {
+ uint offset;
+ uint size;
+ Sample(): offset(), size() {}
+ };
+
+ struct SoundData {
+ Common::Array<Sample> samples;
+ Common::Array<uint8> data;
+ };
+
+ SoundData _soundData[2];
+ Common::Array<uint8> _speechData;
+
+ Audio::SoundHandle _channelHandle[2];
+
+ uint8 _channel0, _channel1;
+
+ uint8 _currentSample;
+ uint8 _channel0Playing;
+ uint8 _channel0Repeat;
+ uint8 _channel1Playing;
+
+ uint8 _volume;
+ uint8 _volumeTo;
+ int8 _volumeDirection;
+ uint8 _volumeCount;
+
+ void volumeAdjust();
+ void playSound(uint8 channel, uint8 id, uint8 loops);
+ void stopSound(uint8 channel);
+ bool loadSpeech(const Common::String &filename);
+};
+
+} // End of namespace DreamWeb
+
+#endif
diff --git a/engines/dreamweb/sprite.cpp b/engines/dreamweb/sprite.cpp
index 3df324abe1..5b6cf6a6ac 100644
--- a/engines/dreamweb/sprite.cpp
+++ b/engines/dreamweb/sprite.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
namespace DreamWeb {
@@ -298,7 +299,7 @@ void DreamWebEngine::doDoor(Sprite *sprite, SetObject *objData, Common::Rect che
soundIndex = 13;
else
soundIndex = 0;
- playChannel1(soundIndex);
+ _sound->playChannel1(soundIndex);
}
if (objData->frames[sprite->animFrame] == 255)
--sprite->animFrame;
@@ -315,7 +316,7 @@ void DreamWebEngine::doDoor(Sprite *sprite, SetObject *objData, Common::Rect che
soundIndex = 13;
else
soundIndex = 1;
- playChannel1(soundIndex);
+ _sound->playChannel1(soundIndex);
}
if (sprite->animFrame != 0)
--sprite->animFrame;
@@ -346,7 +347,7 @@ void DreamWebEngine::lockedDoorway(Sprite *sprite, SetObject *objData) {
if (openDoor) {
if (sprite->animFrame == 1) {
- playChannel1(0);
+ _sound->playChannel1(0);
}
if (sprite->animFrame == 6)
@@ -367,7 +368,7 @@ void DreamWebEngine::lockedDoorway(Sprite *sprite, SetObject *objData) {
// shut door
if (sprite->animFrame == 5) {
- playChannel1(1);
+ _sound->playChannel1(1);
}
if (sprite->animFrame != 0)
@@ -505,7 +506,7 @@ void DreamWebEngine::intro1Text() {
if (_introCount != 2 && _introCount != 4 && _introCount != 6)
return;
- if (hasSpeech() && _channel1Playing != 255) {
+ if (hasSpeech() && _sound->isChannel1Playing()) {
_introCount--;
} else {
if (_introCount == 2)
@@ -578,7 +579,7 @@ void DreamWebEngine::textForEnd() {
}
void DreamWebEngine::textForMonkHelper(uint8 textIndex, uint8 voiceIndex, uint8 x, uint8 y, uint16 countToTimed, uint16 timeCount) {
- if (hasSpeech() && _channel1Playing != 255)
+ if (hasSpeech() && _sound->isChannel1Playing())
_introCount--;
else
setupTimedTemp(textIndex, voiceIndex, x, y, countToTimed, timeCount);
@@ -614,8 +615,7 @@ void DreamWebEngine::textForMonk() {
else if (_introCount == 53) {
fadeScreenDowns();
if (hasSpeech()) {
- _volumeTo = 7;
- _volumeDirection = 1;
+ _sound->volumeChange(7, 1);
}
}
}
@@ -905,14 +905,14 @@ void DreamWebEngine::soundOnReels(uint16 reelPointer) {
continue;
_lastSoundReel = r->_reelPointer;
if (r->_sample < 64) {
- playChannel1(r->_sample);
+ _sound->playChannel1(r->_sample);
return;
}
if (r->_sample < 128) {
- playChannel0(r->_sample & 63, 0);
+ _sound->playChannel0(r->_sample & 63, 0);
return;
}
- playChannel0(r->_sample & 63, 255);
+ _sound->playChannel0(r->_sample & 63, 255);
}
if (_lastSoundReel != reelPointer)
@@ -955,9 +955,9 @@ void DreamWebEngine::getRidOfReels() {
void DreamWebEngine::liftNoise(uint8 index) {
if (_realLocation == 5 || _realLocation == 21)
- playChannel1(13); // hiss noise
+ _sound->playChannel1(13); // hiss noise
else
- playChannel1(index);
+ _sound->playChannel1(index);
}
void DreamWebEngine::checkForExit(Sprite *sprite) {
diff --git a/engines/dreamweb/stubs.cpp b/engines/dreamweb/stubs.cpp
index e453fced5f..3aa8e6da74 100644
--- a/engines/dreamweb/stubs.cpp
+++ b/engines/dreamweb/stubs.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
#include "common/config-manager.h"
@@ -578,7 +579,7 @@ void DreamWebEngine::dreamweb() {
readSetData();
_wonGame = false;
- loadSounds(0, "V99"); // basic sample
+ _sound->loadSounds(0, "V99"); // basic sample
bool firstLoop = true;
@@ -654,7 +655,7 @@ void DreamWebEngine::dreamweb() {
_vars._location = 255;
_vars._roomAfterDream = 1;
_newLocation = 35;
- _volume = 7;
+ _sound->volumeSet(7);
loadRoom();
clearSprites();
initMan();
@@ -664,8 +665,7 @@ void DreamWebEngine::dreamweb() {
initialInv();
_lastFlag = 32;
startup1();
- _volumeTo = 0;
- _volumeDirection = -1;
+ _sound->volumeChange(0, -1);
_commandType = 255;
}
@@ -930,7 +930,7 @@ void DreamWebEngine::processTrigger() {
void DreamWebEngine::useTimedText() {
if (_previousTimedTemp._string) {
// TODO: It might be nice to make subtitles wait for the speech
- // to finish (_channel1Playing) when we're in speech+subtitles mode,
+ // to finish (_sound->isChannel1Playing()) when we're in speech+subtitles mode,
// instead of waiting the pre-specified amount of time.
@@ -967,9 +967,9 @@ void DreamWebEngine::useTimedText() {
void DreamWebEngine::setupTimedTemp(uint8 textIndex, uint8 voiceIndex, uint8 x, uint8 y, uint16 countToTimed, uint16 timeCount) {
if (hasSpeech() && voiceIndex != 0) {
- if (loadSpeech('T', voiceIndex, 'T', textIndex)) {
- playChannel1(50+12);
- }
+ _speechLoaded = _sound->loadSpeech('T', voiceIndex, 'T', textIndex);
+ if (_speechLoaded)
+ _sound->playChannel1(50+12);
if (_speechLoaded && !_subtitles)
return;
@@ -1846,7 +1846,7 @@ void DreamWebEngine::loadRoom() {
_vars._location = _newLocation;
const Room &room = g_roomData[_newLocation];
startLoading(room);
- loadRoomsSample();
+ _sound->loadRoomsSample(_roomsSample);
switchRyanOn();
drawFlags();
@@ -2146,12 +2146,12 @@ void DreamWebEngine::atmospheres() {
continue;
if (a->_mapX != _mapX || a->_mapY != _mapY)
continue;
- if (a->_sound != _channel0Playing) {
+ if (a->_sound != _sound->getChannel0Playing()) {
if (_vars._location == 45 && _vars._reelToWatch == 45)
continue; // "web"
- playChannel0(a->_sound, a->_repeat);
+ _sound->playChannel0(a->_sound, a->_repeat);
// NB: The asm here reads
// cmp reallocation,2
@@ -2161,21 +2161,21 @@ void DreamWebEngine::atmospheres() {
// I'm interpreting this as if the cmp reallocation is below the jz
if (_mapY == 0) {
- _volume = 0; // "fullvol"
+ _sound->volumeSet(0); // "fullvol"
return;
}
if (_realLocation == 2 && _mapX == 22 && _mapY == 10)
- _volume = 5; // "louisvol"
+ _sound->volumeSet(5); // "louisvol"
if (hasSpeech() && _realLocation == 14) {
if (_mapX == 33) {
- _volume = 0; // "ismad2"
+ _sound->volumeSet(0); // "ismad2"
return;
}
if (_mapX == 22) {
- _volume = 5;
+ _sound->volumeSet(5);
return;
}
@@ -2184,19 +2184,19 @@ void DreamWebEngine::atmospheres() {
if (_realLocation == 2) {
if (_mapX == 22) {
- _volume = 5; // "louisvol"
+ _sound->volumeSet(5); // "louisvol"
return;
}
if (_mapX == 11) {
- _volume = 0; // "fullvol"
+ _sound->volumeSet(0); // "fullvol"
return;
}
}
return;
}
- cancelCh0();
+ _sound->cancelCh0();
}
void DreamWebEngine::readKey() {
@@ -2642,8 +2642,8 @@ void DreamWebEngine::showGun() {
_numToFade = 128;
hangOn(200);
_roomsSample = 34;
- loadRoomsSample();
- _volume = 0;
+ _sound->loadRoomsSample(_roomsSample);
+ _sound->volumeSet(0);
GraphicsFile graphics;
loadGraphicsFile(graphics, "G13");
createPanel2();
@@ -2653,7 +2653,7 @@ void DreamWebEngine::showGun() {
graphics.clear();
fadeScreenUp();
hangOn(160);
- playChannel0(12, 0);
+ _sound->playChannel0(12, 0);
loadTempText("T83");
rollEndCreditsGameLost();
getRidOfTempText();
diff --git a/engines/dreamweb/talk.cpp b/engines/dreamweb/talk.cpp
index 26eafdcb51..ca99269cc8 100644
--- a/engines/dreamweb/talk.cpp
+++ b/engines/dreamweb/talk.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
namespace DreamWeb {
@@ -67,9 +68,8 @@ void DreamWebEngine::talk() {
redrawMainScrn();
workToScreenM();
if (_speechLoaded) {
- cancelCh1();
- _volumeDirection = -1;
- _volumeTo = 0;
+ _sound->cancelCh1();
+ _sound->volumeChange(0, -1);
}
}
@@ -99,12 +99,10 @@ void DreamWebEngine::startTalk() {
printDirect(&str, 66, &y, 241, true);
if (hasSpeech()) {
- _speechLoaded = false;
- loadSpeech('R', _realLocation, 'C', 64*(_character & 0x7F));
+ _speechLoaded = _sound->loadSpeech('R', _realLocation, 'C', 64*(_character & 0x7F));
if (_speechLoaded) {
- _volumeDirection = 1;
- _volumeTo = 6;
- playChannel1(50 + 12);
+ _sound->volumeChange(6, 1);
+ _sound->playChannel1(50 + 12);
}
}
}
@@ -155,9 +153,9 @@ void DreamWebEngine::doSomeTalk() {
printDirect(str, 164, 64, 144, false);
- loadSpeech('R', _realLocation, 'C', (64 * (_character & 0x7F)) + _talkPos);
+ _speechLoaded = _sound->loadSpeech('R', _realLocation, 'C', (64 * (_character & 0x7F)) + _talkPos);
if (_speechLoaded)
- playChannel1(62);
+ _sound->playChannel1(62);
_pointerMode = 3;
workToScreenM();
@@ -181,9 +179,9 @@ void DreamWebEngine::doSomeTalk() {
convIcons();
printDirect(str, 48, 128, 144, false);
- loadSpeech('R', _realLocation, 'C', (64 * (_character & 0x7F)) + _talkPos);
+ _speechLoaded = _sound->loadSpeech('R', _realLocation, 'C', (64 * (_character & 0x7F)) + _talkPos);
if (_speechLoaded)
- playChannel1(62);
+ _sound->playChannel1(62);
_pointerMode = 3;
workToScreenM();
@@ -220,11 +218,11 @@ bool DreamWebEngine::hangOnPQ() {
// Quit conversation
delPointer();
_pointerMode = 0;
- cancelCh1();
+ _sound->cancelCh1();
return true;
}
- if (_speechLoaded && _channel1Playing == 255) {
+ if (_speechLoaded && !_sound->isChannel1Playing()) {
speechFlag++;
if (speechFlag == 40)
break;
@@ -237,7 +235,7 @@ bool DreamWebEngine::hangOnPQ() {
}
void DreamWebEngine::redes() {
- if (_channel1Playing != 255 || _talkMode != 2) {
+ if (_sound->isChannel1Playing() || _talkMode != 2) {
blank();
return;
}
diff --git a/engines/dreamweb/titles.cpp b/engines/dreamweb/titles.cpp
index 3ed31fe13a..fa6b1060fb 100644
--- a/engines/dreamweb/titles.cpp
+++ b/engines/dreamweb/titles.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
#include "engines/util.h"
@@ -32,38 +33,36 @@ void DreamWebEngine::endGame() {
return;
gettingShot();
getRidOfTempText();
- _volumeTo = 7;
- _volumeDirection = 1;
+ _sound->volumeChange(7, 1);
hangOn(200);
}
void DreamWebEngine::monkSpeaking() {
_roomsSample = 35;
- loadRoomsSample();
+ _sound->loadRoomsSample(_roomsSample);
GraphicsFile graphics;
loadGraphicsFile(graphics, "G15");
clearWork();
showFrame(graphics, 160, 72, 0, 128); // show monk
workToScreen();
- _volume = 7;
- _volumeDirection = -1;
- _volumeTo = hasSpeech() ? 5 : 0;
- playChannel0(12, 255);
+ _sound->volumeSet(7);
+ _sound->volumeChange(hasSpeech() ? 5 : 0, -1);
+ _sound->playChannel0(12, 255);
fadeScreenUps();
hangOn(300);
// TODO: Subtitles+speech mode
if (hasSpeech()) {
for (int i = 40; i < 48; i++) {
- loadSpeech('T', 83, 'T', i);
+ _speechLoaded = _sound->loadSpeech('T', 83, 'T', i);
- playChannel1(50 + 12);
+ _sound->playChannel1(50 + 12);
do {
waitForVSync();
if (_quitRequested)
return;
- } while (_channel1Playing != 255);
+ } while (_sound->isChannel1Playing());
}
} else {
for (int i = 40; i <= 44; i++) {
@@ -83,8 +82,7 @@ void DreamWebEngine::monkSpeaking() {
}
}
- _volumeDirection = 1;
- _volumeTo = 7;
+ _sound->volumeChange(7, 1);
fadeScreenDowns();
hangOn(300);
graphics.clear();
@@ -95,8 +93,7 @@ void DreamWebEngine::gettingShot() {
clearPalette();
loadIntroRoom();
fadeScreenUps();
- _volumeTo = 0;
- _volumeDirection = -1;
+ _sound->volumeChange(0, -1);
runEndSeq();
clearBeforeLoad();
}
@@ -127,7 +124,7 @@ void DreamWebEngine::bibleQuote() {
return; // "biblequotearly"
}
- cancelCh0();
+ _sound->cancelCh0();
_lastHardKey = 0;
}
@@ -147,10 +144,9 @@ void DreamWebEngine::intro() {
_newLocation = 50;
clearPalette();
loadIntroRoom();
- _volume = 7;
- _volumeDirection = -1;
- _volumeTo = hasSpeech() ? 4 : 0;
- playChannel0(12, 255);
+ _sound->volumeSet(7);
+ _sound->volumeChange(hasSpeech() ? 4 : 0, -1);
+ _sound->playChannel0(12, 255);
fadeScreenUps();
runIntroSeq();
@@ -286,14 +282,14 @@ void DreamWebEngine::set16ColPalette() {
void DreamWebEngine::realCredits() {
_roomsSample = 33;
- loadRoomsSample();
- _volume = 0;
+ _sound->loadRoomsSample(_roomsSample);
+ _sound->volumeSet(0);
initGraphics(640, 480, true);
hangOn(35);
showPCX("I01");
- playChannel0(12, 0);
+ _sound->playChannel0(12, 0);
hangOne(2);
@@ -319,7 +315,7 @@ void DreamWebEngine::realCredits() {
}
showPCX("I02");
- playChannel0(12, 0);
+ _sound->playChannel0(12, 0);
hangOne(2);
if (_lastHardKey == 1) {
@@ -344,7 +340,7 @@ void DreamWebEngine::realCredits() {
}
showPCX("I03");
- playChannel0(12, 0);
+ _sound->playChannel0(12, 0);
hangOne(2);
if (_lastHardKey == 1) {
@@ -369,7 +365,7 @@ void DreamWebEngine::realCredits() {
}
showPCX("I04");
- playChannel0(12, 0);
+ _sound->playChannel0(12, 0);
hangOne(2);
if (_lastHardKey == 1) {
@@ -394,7 +390,7 @@ void DreamWebEngine::realCredits() {
}
showPCX("I05");
- playChannel0(12, 0);
+ _sound->playChannel0(12, 0);
hangOne(2);
if (_lastHardKey == 1) {
@@ -427,7 +423,7 @@ void DreamWebEngine::realCredits() {
return; // "realcreditsearly"
}
- playChannel0(13, 0);
+ _sound->playChannel0(13, 0);
hangOne(350);
if (_lastHardKey == 1) {
diff --git a/engines/dreamweb/use.cpp b/engines/dreamweb/use.cpp
index e59843539f..995eef04cd 100644
--- a/engines/dreamweb/use.cpp
+++ b/engines/dreamweb/use.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
namespace DreamWeb {
@@ -201,13 +202,13 @@ void DreamWebEngine::edensCDPlayer() {
}
void DreamWebEngine::hotelBell() {
- playChannel1(12);
+ _sound->playChannel1(12);
showFirstUse();
putBackObStuff();
}
void DreamWebEngine::playGuitar() {
- playChannel1(14);
+ _sound->playChannel1(14);
showFirstUse();
putBackObStuff();
}
@@ -273,13 +274,13 @@ void DreamWebEngine::useHatch() {
}
void DreamWebEngine::wheelSound() {
- playChannel1(17);
+ _sound->playChannel1(17);
showFirstUse();
putBackObStuff();
}
void DreamWebEngine::callHotelLift() {
- playChannel1(12);
+ _sound->playChannel1(12);
showFirstUse();
_vars._countToOpen = 8;
_getBack = 1;
@@ -382,7 +383,7 @@ void DreamWebEngine::sitDownInBar() {
}
void DreamWebEngine::useDryer() {
- playChannel1(12);
+ _sound->playChannel1(12);
showFirstUse();
_getBack = 1;
}
@@ -887,7 +888,7 @@ void DreamWebEngine::usePlate() {
if (compare(_withObject, _withType, "SCRW")) {
// Unscrew plate
- playChannel1(20);
+ _sound->playChannel1(20);
showFirstUse();
placeSetObject(28);
placeSetObject(24);
@@ -992,7 +993,7 @@ void DreamWebEngine::useCart() {
removeSetObject(_command);
placeSetObject(_command + 1);
_vars._progressPoints++;
- playChannel1(17);
+ _sound->playChannel1(17);
showFirstUse();
_getBack = 1;
}
@@ -1035,7 +1036,7 @@ void DreamWebEngine::openHotelDoor() {
if (defaultUseHandler("KEYA"))
return;
- playChannel1(16);
+ _sound->playChannel1(16);
showFirstUse();
_vars._lockStatus = 0;
_getBack = 1;
@@ -1045,7 +1046,7 @@ void DreamWebEngine::openHotelDoor2() {
if (defaultUseHandler("KEYA"))
return;
- playChannel1(16);
+ _sound->playChannel1(16);
showFirstUse();
putBackObStuff();
}
@@ -1067,7 +1068,7 @@ void DreamWebEngine::usePoolReader() {
showSecondUse();
putBackObStuff();
} else {
- playChannel1(17);
+ _sound->playChannel1(17);
showFirstUse();
_vars._countToOpen = 6;
_getBack = 1;
@@ -1088,7 +1089,7 @@ void DreamWebEngine::useCardReader1() {
putBackObStuff();
} else {
// Get cash
- playChannel1(16);
+ _sound->playChannel1(16);
showPuzText(18, 300);
_vars._progressPoints++;
_vars._card1Money = 12432;
@@ -1113,7 +1114,7 @@ void DreamWebEngine::useCardReader2() {
showPuzText(22, 300);
putBackObStuff();
} else {
- playChannel1(18);
+ _sound->playChannel1(18);
showPuzText(19, 300);
placeSetObject(94);
_vars._gunPassFlag = 1;
@@ -1136,7 +1137,7 @@ void DreamWebEngine::useCardReader3() {
showPuzText(26, 300);
putBackObStuff();
} else {
- playChannel1(16);
+ _sound->playChannel1(16);
showPuzText(25, 300);
_vars._progressPoints++;
_vars._card1Money -= 8300;
@@ -1232,7 +1233,7 @@ void DreamWebEngine::useControl() {
}
if (compare(_withObject, _withType, "KEYA")) { // Right key
- playChannel1(16);
+ _sound->playChannel1(16);
if (_vars._location == 21) { // Going down
showPuzText(3, 300);
_newLocation = 30;
@@ -1257,7 +1258,7 @@ void DreamWebEngine::useControl() {
placeSetObject(30);
removeSetObject(16);
removeSetObject(17);
- playChannel1(14);
+ _sound->playChannel1(14);
showPuzText(10, 300);
_vars._progressPoints++;
_getBack = 1;
@@ -1375,7 +1376,7 @@ void DreamWebEngine::runTap() {
// Fill cup from tap
DynObject *exObject = getExAd(_withObject);
exObject->objId[3] = 'F'-'A'; // CUPE (empty cup) -> CUPF (full cup)
- playChannel1(8);
+ _sound->playChannel1(8);
showPuzText(57, 300);
putBackObStuff();
return;
diff --git a/engines/dreamweb/vgafades.cpp b/engines/dreamweb/vgafades.cpp
index 6f9fd5f53c..c8f05641b5 100644
--- a/engines/dreamweb/vgafades.cpp
+++ b/engines/dreamweb/vgafades.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
namespace DreamWeb {
@@ -123,7 +124,7 @@ void DreamWebEngine::fadeUpMonFirst() {
_colourPos = 0;
_numToFade = 128;
hangOn(64);
- playChannel1(26);
+ _sound->playChannel1(26);
hangOn(64);
}