[Scummvm-cvs-logs] SF.net SVN: scummvm: [31949] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Thu May 8 17:51:03 CEST 2008


Revision: 31949
          http://scummvm.svn.sourceforge.net/scummvm/?rev=31949&view=rev
Author:   drmccoy
Date:     2008-05-08 08:51:02 -0700 (Thu, 08 May 2008)

Log Message:
-----------
Implemented the background "music" / atmospheric sounds in Woodruff

Modified Paths:
--------------
    scummvm/trunk/engines/gob/coktelvideo.cpp
    scummvm/trunk/engines/gob/coktelvideo.h
    scummvm/trunk/engines/gob/inter_v4.cpp
    scummvm/trunk/engines/gob/module.mk
    scummvm/trunk/engines/gob/sound/sound.cpp
    scummvm/trunk/engines/gob/sound/sound.h
    scummvm/trunk/engines/gob/sound/soundblaster.cpp
    scummvm/trunk/engines/gob/videoplayer.cpp
    scummvm/trunk/engines/gob/videoplayer.h

Added Paths:
-----------
    scummvm/trunk/engines/gob/sound/bgatmosphere.cpp
    scummvm/trunk/engines/gob/sound/bgatmosphere.h

Modified: scummvm/trunk/engines/gob/coktelvideo.cpp
===================================================================
--- scummvm/trunk/engines/gob/coktelvideo.cpp	2008-05-08 13:23:02 UTC (rev 31948)
+++ scummvm/trunk/engines/gob/coktelvideo.cpp	2008-05-08 15:51:02 UTC (rev 31949)
@@ -270,6 +270,13 @@
 	_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

Modified: scummvm/trunk/engines/gob/coktelvideo.h
===================================================================
--- scummvm/trunk/engines/gob/coktelvideo.h	2008-05-08 13:23:02 UTC (rev 31948)
+++ scummvm/trunk/engines/gob/coktelvideo.h	2008-05-08 15:51:02 UTC (rev 31949)
@@ -139,6 +139,9 @@
 	/** 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 @@
 	void enableSound(Audio::Mixer &mixer);
 	void disableSound();
 
+	bool isSoundPlaying() const;
+
 	void seekFrame(int32 frame, int16 whence = SEEK_SET, bool restart = false);
 
 	State nextFrame();

Modified: scummvm/trunk/engines/gob/inter_v4.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter_v4.cpp	2008-05-08 13:23:02 UTC (rev 31948)
+++ scummvm/trunk/engines/gob/inter_v4.cpp	2008-05-08 15:51:02 UTC (rev 31949)
@@ -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 @@
 	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 @@
 		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);

Modified: scummvm/trunk/engines/gob/module.mk
===================================================================
--- scummvm/trunk/engines/gob/module.mk	2008-05-08 13:23:02 UTC (rev 31948)
+++ scummvm/trunk/engines/gob/module.mk	2008-05-08 15:51:02 UTC (rev 31949)
@@ -58,7 +58,8 @@
 	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)

Added: scummvm/trunk/engines/gob/sound/bgatmosphere.cpp
===================================================================
--- scummvm/trunk/engines/gob/sound/bgatmosphere.cpp	                        (rev 0)
+++ scummvm/trunk/engines/gob/sound/bgatmosphere.cpp	2008-05-08 15:51:02 UTC (rev 31949)
@@ -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


Property changes on: scummvm/trunk/engines/gob/sound/bgatmosphere.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: scummvm/trunk/engines/gob/sound/bgatmosphere.h
===================================================================
--- scummvm/trunk/engines/gob/sound/bgatmosphere.h	                        (rev 0)
+++ scummvm/trunk/engines/gob/sound/bgatmosphere.h	2008-05-08 15:51:02 UTC (rev 31949)
@@ -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


Property changes on: scummvm/trunk/engines/gob/sound/bgatmosphere.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Modified: scummvm/trunk/engines/gob/sound/sound.cpp
===================================================================
--- scummvm/trunk/engines/gob/sound/sound.cpp	2008-05-08 13:23:02 UTC (rev 31948)
+++ scummvm/trunk/engines/gob/sound/sound.cpp	2008-05-08 15:51:02 UTC (rev 31949)
@@ -39,6 +39,7 @@
 	_adlib = 0;
 	_infogrames = 0;
 	_cdrom = 0;
+	_bgatmos = 0;
 
 	if (!_vm->_noMusic && _vm->hasAdlib())
 		_adlib = new AdLib(*_vm->_mixer);
@@ -46,6 +47,8 @@
 		_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 @@
 	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 @@
 	_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

Modified: scummvm/trunk/engines/gob/sound/sound.h
===================================================================
--- scummvm/trunk/engines/gob/sound/sound.h	2008-05-08 13:23:02 UTC (rev 31948)
+++ scummvm/trunk/engines/gob/sound/sound.h	2008-05-08 15:51:02 UTC (rev 31949)
@@ -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 @@
 	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 @@
 
 	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 @@
 	AdLib *_adlib;
 	Infogrames *_infogrames;
 	CDROM *_cdrom;
+	BackgroundAtmosphere *_bgatmos;
 };
 
 } // End of namespace Gob

Modified: scummvm/trunk/engines/gob/sound/soundblaster.cpp
===================================================================
--- scummvm/trunk/engines/gob/sound/soundblaster.cpp	2008-05-08 13:23:02 UTC (rev 31948)
+++ scummvm/trunk/engines/gob/sound/soundblaster.cpp	2008-05-08 15:51:02 UTC (rev 31949)
@@ -23,7 +23,7 @@
  *
  */
 
-#include "gob/sound/sound.h"
+#include "gob/sound/soundblaster.h"
 
 namespace Gob {
 

Modified: scummvm/trunk/engines/gob/videoplayer.cpp
===================================================================
--- scummvm/trunk/engines/gob/videoplayer.cpp	2008-05-08 13:23:02 UTC (rev 31948)
+++ scummvm/trunk/engines/gob/videoplayer.cpp	2008-05-08 15:51:02 UTC (rev 31949)
@@ -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 @@
 		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 @@
 		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 @@
 
 	_videoSlots[slot]->nextFrame();
 	WRITE_VAR(11, frame);
+
+	evalBgShading(video);
 }
 
 void VideoPlayer::slotClose(int slot) {
@@ -598,4 +612,11 @@
 	}
 }
 
+void VideoPlayer::evalBgShading(CoktelVideo &video) {
+	if (video.isSoundPlaying())
+		_vm->_sound->bgShade();
+	else
+		_vm->_sound->bgUnshade();
+}
+
 } // End of namespace Gob

Modified: scummvm/trunk/engines/gob/videoplayer.h
===================================================================
--- scummvm/trunk/engines/gob/videoplayer.h	2008-05-08 13:23:02 UTC (rev 31948)
+++ scummvm/trunk/engines/gob/videoplayer.h	2008-05-08 15:51:02 UTC (rev 31949)
@@ -132,6 +132,7 @@
 	bool doPlay(int16 frame, int16 breakKey,
 			uint16 palCmd, int16 palStart, int16 palEnd,
 			int16 palFrame, int16 endFrame);
+	void evalBgShading(CoktelVideo &video);
 };
 
 } // End of namespace Gob


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list