aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/gob/coktelvideo.cpp7
-rw-r--r--engines/gob/coktelvideo.h5
-rw-r--r--engines/gob/inter_v4.cpp13
-rw-r--r--engines/gob/module.mk3
-rw-r--r--engines/gob/sound/bgatmosphere.cpp126
-rw-r--r--engines/gob/sound/bgatmosphere.h75
-rw-r--r--engines/gob/sound/sound.cpp64
-rw-r--r--engines/gob/sound/sound.h14
-rw-r--r--engines/gob/sound/soundblaster.cpp2
-rw-r--r--engines/gob/videoplayer.cpp23
-rw-r--r--engines/gob/videoplayer.h1
11 files changed, 324 insertions, 9 deletions
diff --git a/engines/gob/coktelvideo.cpp b/engines/gob/coktelvideo.cpp
index d508dc75f9..c3625574d0 100644
--- a/engines/gob/coktelvideo.cpp
+++ b/engines/gob/coktelvideo.cpp
@@ -270,6 +270,13 @@ void Imd::disableSound() {
_mixer = 0;
}
+bool Imd::isSoundPlaying() const {
+ if (_audioStream && _mixer->isSoundHandleActive(_audioHandle))
+ return true;
+
+ return false;
+}
+
void Imd::seekFrame(int32 frame, int16 whence, bool restart) {
if (!_stream)
// Nothing to do
diff --git a/engines/gob/coktelvideo.h b/engines/gob/coktelvideo.h
index 4f9543e8d0..581ac2ae81 100644
--- a/engines/gob/coktelvideo.h
+++ b/engines/gob/coktelvideo.h
@@ -139,6 +139,9 @@ public:
/** Don't play sound or stop currently playing sound. */
virtual void disableSound() = 0;
+ /** Is sound currently playing? */
+ virtual bool isSoundPlaying() const = 0;
+
/** Seek to a specific frame.
*
* @param frame The frame to which to seek.
@@ -203,6 +206,8 @@ public:
void enableSound(Audio::Mixer &mixer);
void disableSound();
+ bool isSoundPlaying() const;
+
void seekFrame(int32 frame, int16 whence = SEEK_SET, bool restart = false);
State nextFrame();
diff --git a/engines/gob/inter_v4.cpp b/engines/gob/inter_v4.cpp
index cbda4d6726..76b11752e0 100644
--- a/engines/gob/inter_v4.cpp
+++ b/engines/gob/inter_v4.cpp
@@ -32,6 +32,7 @@
#include "gob/game.h"
#include "gob/parse.h"
#include "gob/videoplayer.h"
+#include "gob/sound/sound.h"
namespace Gob {
@@ -742,7 +743,7 @@ void Inter_v4::o4_playVmdOrMusic() {
if (lastFrame == -1) {
close = true;
} else if (lastFrame == -3) {
- warning("Woodruff Stub: Video/Music command -3: Play background video %s, %d, %d, %d, %d", fileName, startFrame, x, y, VAR_OFFSET(7872));
+// warning("Woodruff Stub: Video/Music command -3: Play background video %s, %d, %d, %d, %d", fileName, startFrame, x, y, VAR_OFFSET(7872));
_vm->_mult->_objects[startFrame].pAnimData->animation = -startFrame - 1;
@@ -766,16 +767,20 @@ void Inter_v4::o4_playVmdOrMusic() {
warning("Woodruff Stub: Video/Music command -4: Play background video %s", fileName);
return;
} else if (lastFrame == -5) {
- warning("Woodruff Stub: Video/Music command -5: Stop background music");
+// warning("Woodruff Stub: Video/Music command -5: Stop background music");
+ _vm->_sound->bgStop();
return;
} else if (lastFrame == -6) {
- warning("Woodruff Stub: Video/Music command -6: Load background video %s", fileName);
+// warning("Woodruff Stub: Video/Music command -6: Load background video %s", fileName);
return;
} else if (lastFrame == -8) {
warning("Woodruff Stub: Video/Music command -8: Play background video %s", fileName);
return;
} else if (lastFrame == -9) {
- warning("Woodruff Stub: Video/Music command -9: Play background music %s (%d-%d)", fileName, palEnd, palStart);
+// warning("Woodruff Stub: Video/Music command -9: Play background music %s (%d-%d)", fileName, palEnd, palStart);
+ _vm->_sound->bgStop();
+ _vm->_sound->bgSetPlayMode(BackgroundAtmosphere::kPlayModeRandom);
+ _vm->_sound->bgPlay(fileName, palStart);
return;
} else if (lastFrame < 0) {
warning("Unknown Video/Music command: %d, %s", lastFrame, fileName);
diff --git a/engines/gob/module.mk b/engines/gob/module.mk
index 9f407daee5..09664f15b4 100644
--- a/engines/gob/module.mk
+++ b/engines/gob/module.mk
@@ -58,7 +58,8 @@ MODULE_OBJS := \
sound/infogrames.o \
sound/soundmixer.o \
sound/soundblaster.o \
- sound/cdrom.o
+ sound/cdrom.o \
+ sound/bgatmosphere.o
# This module can be built as a plugin
ifeq ($(ENABLE_GOB), DYNAMIC_PLUGIN)
diff --git a/engines/gob/sound/bgatmosphere.cpp b/engines/gob/sound/bgatmosphere.cpp
new file mode 100644
index 0000000000..3c61f4f76a
--- /dev/null
+++ b/engines/gob/sound/bgatmosphere.cpp
@@ -0,0 +1,126 @@
+/* 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 "common/system.h"
+#include "common/events.h"
+
+#include "gob/sound/bgatmosphere.h"
+
+namespace Gob {
+
+BackgroundAtmosphere::BackgroundAtmosphere(Audio::Mixer &mixer) : SoundMixer(mixer) {
+ _playMode = kPlayModeLinear;
+ _queuePos = -1;
+ _shaded = false;
+
+ g_system->getEventManager()->registerRandomSource(_rnd, "gobBA");
+}
+
+BackgroundAtmosphere::~BackgroundAtmosphere() {
+ queueClear();
+}
+
+void BackgroundAtmosphere::play() {
+ Common::StackLock slock(_mutex);
+
+ _queuePos = -1;
+ getNextQueuePos();
+
+ if (_queuePos == -1)
+ return;
+
+ SoundMixer::play(*_queue[_queuePos], 1, 0);
+}
+
+void BackgroundAtmosphere::stop() {
+ SoundMixer::stop(0);
+}
+
+void BackgroundAtmosphere::setPlayMode(PlayMode mode) {
+ _playMode = mode;
+}
+
+void BackgroundAtmosphere::queueSample(SoundDesc &sndDesc) {
+ Common::StackLock slock(_mutex);
+
+ _queue.push_back(&sndDesc);
+}
+
+void BackgroundAtmosphere::queueClear() {
+ Common::StackLock slock(_mutex);
+
+ SoundMixer::stop(0);
+ for (uint i = 0; i < _queue.size(); i++)
+ delete _queue[i];
+
+ _queue.clear();
+ _queuePos = -1;
+}
+
+void BackgroundAtmosphere::checkEndSample() {
+ Common::StackLock slock(_mutex);
+
+ getNextQueuePos();
+
+ if (_queuePos == -1) {
+ _end = true;
+ _playingSound = 0;
+ } else {
+ SoundMixer::setSample(*_queue[_queuePos], 1, 0, 0);
+ if (_shaded)
+ _fadeVol = 20000;
+ }
+}
+
+void BackgroundAtmosphere::getNextQueuePos() {
+ if (_queue.size() == 0) {
+ _queuePos = -1;
+ return;
+ }
+
+ switch (_playMode) {
+
+ case kPlayModeLinear:
+ _queuePos = (_queuePos + 1) % _queue.size();
+ break;
+
+ case kPlayModeRandom:
+ _queuePos = _rnd.getRandomNumber(_queue.size() - 1);
+ break;
+
+ }
+}
+
+void BackgroundAtmosphere::shade() {
+ _shaded = true;
+ _fadeVol = 32768;
+}
+
+void BackgroundAtmosphere::unshade() {
+ _shaded = false;
+ _fadeVol = 65536;
+}
+
+} // End of namespace Gob
diff --git a/engines/gob/sound/bgatmosphere.h b/engines/gob/sound/bgatmosphere.h
new file mode 100644
index 0000000000..72b5614282
--- /dev/null
+++ b/engines/gob/sound/bgatmosphere.h
@@ -0,0 +1,75 @@
+/* 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$
+ *
+ */
+
+#ifndef GOB_SOUND_BGATMOSPHERE_H
+#define GOB_SOUND_BGATMOSPHERE_H
+
+#include "sound/mixer.h"
+#include "common/mutex.h"
+
+#include "gob/sound/sounddesc.h"
+#include "gob/sound/soundmixer.h"
+
+namespace Gob {
+
+class BackgroundAtmosphere : private SoundMixer {
+public:
+ enum PlayMode {
+ kPlayModeLinear,
+ kPlayModeRandom
+ };
+
+ BackgroundAtmosphere(Audio::Mixer &mixer);
+ ~BackgroundAtmosphere();
+
+ void play();
+ void stop();
+
+ void setPlayMode(PlayMode mode);
+
+ void queueSample(SoundDesc &sndDesc);
+ void queueClear();
+
+ void shade();
+ void unshade();
+
+private:
+ PlayMode _playMode;
+
+ Common::Array<SoundDesc *> _queue;
+ int _queuePos;
+ bool _shaded;
+
+ Common::Mutex _mutex;
+
+ Common::RandomSource _rnd;
+
+ void checkEndSample();
+ void getNextQueuePos();
+};
+
+} // End of namespace Gob
+
+#endif // GOB_SOUND_BGATMOSPHERE_H
diff --git a/engines/gob/sound/sound.cpp b/engines/gob/sound/sound.cpp
index 5c375c260a..63b74ca36f 100644
--- a/engines/gob/sound/sound.cpp
+++ b/engines/gob/sound/sound.cpp
@@ -39,6 +39,7 @@ Sound::Sound(GobEngine *vm) : _vm(vm) {
_adlib = 0;
_infogrames = 0;
_cdrom = 0;
+ _bgatmos = 0;
if (!_vm->_noMusic && _vm->hasAdlib())
_adlib = new AdLib(*_vm->_mixer);
@@ -46,6 +47,8 @@ Sound::Sound(GobEngine *vm) : _vm(vm) {
_infogrames = new Infogrames(*_vm->_mixer);
if (_vm->isCD())
_cdrom = new CDROM;
+ if (_vm->getGameType() == kGameTypeWoodruff)
+ _bgatmos = new BackgroundAtmosphere(*_vm->_mixer);
}
Sound::~Sound() {
@@ -85,10 +88,18 @@ int Sound::sampleGetNextFreeSlot() const {
return -1;
}
-bool Sound::sampleLoad(SoundDesc *sndDesc, const char *fileName) {
+bool Sound::sampleLoad(SoundDesc *sndDesc, const char *fileName, bool tryExist) {
if (!sndDesc)
return false;
+ int16 handle = _vm->_dataIO->openData(fileName);
+ if (handle < 0) {
+ warning("Can't open sample file \"%s\"", fileName);
+ return false;
+ }
+
+ _vm->_dataIO->closeData(handle);
+
byte *data;
uint32 size;
@@ -458,4 +469,55 @@ void Sound::cdTest(int trySubst, const char *label) {
_cdrom->testCD(trySubst, label);
}
+void Sound::bgPlay(const char *base, int count) {
+ if (!_bgatmos)
+ return;
+
+ _bgatmos->stop();
+ _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.SND", base, i);
+
+ sndDesc = new SoundDesc;
+ if (sampleLoad(sndDesc, fileName))
+ _bgatmos->queueSample(*sndDesc);
+ }
+
+ _bgatmos->play();
+}
+
+void Sound::bgStop() {
+ if (!_bgatmos)
+ return;
+
+ _bgatmos->stop();
+ _bgatmos->queueClear();
+}
+
+void Sound::bgSetPlayMode(BackgroundAtmosphere::PlayMode mode) {
+ if (!_bgatmos)
+ return;
+
+ _bgatmos->setPlayMode(mode);
+}
+
+void Sound::bgShade() {
+ if (!_bgatmos)
+ return;
+
+ _bgatmos->shade();
+}
+
+void Sound::bgUnshade() {
+ if (!_bgatmos)
+ return;
+
+ _bgatmos->unshade();
+}
+
} // End of namespace Gob
diff --git a/engines/gob/sound/sound.h b/engines/gob/sound/sound.h
index 81b48688c4..b59510e4bb 100644
--- a/engines/gob/sound/sound.h
+++ b/engines/gob/sound/sound.h
@@ -32,6 +32,7 @@
#include "gob/sound/adlib.h"
#include "gob/sound/infogrames.h"
#include "gob/sound/cdrom.h"
+#include "gob/sound/bgatmosphere.h"
namespace Gob {
@@ -49,7 +50,7 @@ public:
const SoundDesc *sampleGetBySlot(int slot) const;
int sampleGetNextFreeSlot() const;
- bool sampleLoad(SoundDesc *sndDesc, const char *fileName);
+ bool sampleLoad(SoundDesc *sndDesc, const char *fileName, bool tryExist = true);
void sampleFree(SoundDesc *sndDesc, bool noteAdlib = false, int index = -1);
@@ -118,6 +119,16 @@ public:
void cdTest(int trySubst, const char *label);
+
+ // Background Atmosphere
+ void bgPlay(const char *base, int count);
+ void bgStop();
+
+ void bgSetPlayMode(BackgroundAtmosphere::PlayMode mode);
+
+ void bgShade();
+ void bgUnshade();
+
private:
GobEngine *_vm;
@@ -128,6 +139,7 @@ private:
AdLib *_adlib;
Infogrames *_infogrames;
CDROM *_cdrom;
+ BackgroundAtmosphere *_bgatmos;
};
} // End of namespace Gob
diff --git a/engines/gob/sound/soundblaster.cpp b/engines/gob/sound/soundblaster.cpp
index bacb16a6d3..cfa11b6ff9 100644
--- a/engines/gob/sound/soundblaster.cpp
+++ b/engines/gob/sound/soundblaster.cpp
@@ -23,7 +23,7 @@
*
*/
-#include "gob/sound/sound.h"
+#include "gob/sound/soundblaster.h"
namespace Gob {
diff --git a/engines/gob/videoplayer.cpp b/engines/gob/videoplayer.cpp
index 6b21c18676..c435136b75 100644
--- a/engines/gob/videoplayer.cpp
+++ b/engines/gob/videoplayer.cpp
@@ -33,6 +33,7 @@
#include "gob/palanim.h"
#include "gob/inter.h"
#include "gob/map.h"
+#include "gob/sound/sound.h"
namespace Gob {
@@ -289,6 +290,8 @@ void VideoPlayer::primaryPlay(int16 startFrame, int16 lastFrame, int16 breakKey,
if (doPlay(startFrame, breakKey, palCmd, palStart, palEnd, palFrame, endFrame))
break;
+ evalBgShading(video);
+
if (fade) {
_vm->_palAnim->fade(_vm->_global->_pPaletteDesc, -2, 0);
fade = false;
@@ -299,18 +302,27 @@ void VideoPlayer::primaryPlay(int16 startFrame, int16 lastFrame, int16 breakKey,
startFrame++;
}
+ evalBgShading(video);
+
if (reverseTo >= 0) {
int16 toFrame = video.getFramesCount() - reverseTo;
for (int i = video.getCurrentFrame(); i >= toFrame; i--) {
video.seekFrame(i, SEEK_SET, true);
- if (doPlay(i, breakKey, 0, 0, 0, 0, 0)) {
+
+ bool b = doPlay(i, breakKey, 0, 0, 0, 0, 0);
+ evalBgShading(video);
+
+ if (b) {
_vm->_palAnim->fade(0, -2, 0);
memset((char *) _vm->_draw->_vgaPalette, 0, 768);
}
+
if (!_noCursorSwitch)
video.waitEndFrame();
}
}
+
+ evalBgShading(video);
}
void VideoPlayer::primaryClose() {
@@ -360,6 +372,8 @@ void VideoPlayer::slotPlay(int slot, int16 frame) {
_videoSlots[slot]->nextFrame();
WRITE_VAR(11, frame);
+
+ evalBgShading(video);
}
void VideoPlayer::slotClose(int slot) {
@@ -598,4 +612,11 @@ void VideoPlayer::writeVideoInfo(const char *videoFile, int16 varX, int16 varY,
}
}
+void VideoPlayer::evalBgShading(CoktelVideo &video) {
+ if (video.isSoundPlaying())
+ _vm->_sound->bgShade();
+ else
+ _vm->_sound->bgUnshade();
+}
+
} // End of namespace Gob
diff --git a/engines/gob/videoplayer.h b/engines/gob/videoplayer.h
index a04a0dbc9d..29531f7ce2 100644
--- a/engines/gob/videoplayer.h
+++ b/engines/gob/videoplayer.h
@@ -132,6 +132,7 @@ private:
bool doPlay(int16 frame, int16 breakKey,
uint16 palCmd, int16 palStart, int16 palEnd,
int16 palFrame, int16 endFrame);
+ void evalBgShading(CoktelVideo &video);
};
} // End of namespace Gob