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

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Wed Jan 31 14:17:51 CET 2007


Revision: 25307
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25307&view=rev
Author:   drmccoy
Date:     2007-01-31 05:17:50 -0800 (Wed, 31 Jan 2007)

Log Message:
-----------
- Correctly setting of Snd::_playingSound
- Implemented sound fading in/out
- o2_stub0x81 -> o2_scroll

Modified Paths:
--------------
    scummvm/trunk/engines/gob/dataio.h
    scummvm/trunk/engines/gob/game.cpp
    scummvm/trunk/engines/gob/inter.h
    scummvm/trunk/engines/gob/inter_v2.cpp
    scummvm/trunk/engines/gob/mult.h
    scummvm/trunk/engines/gob/mult_v1.cpp
    scummvm/trunk/engines/gob/mult_v2.cpp
    scummvm/trunk/engines/gob/sound.cpp
    scummvm/trunk/engines/gob/sound.h

Modified: scummvm/trunk/engines/gob/dataio.h
===================================================================
--- scummvm/trunk/engines/gob/dataio.h	2007-01-31 10:42:18 UTC (rev 25306)
+++ scummvm/trunk/engines/gob/dataio.h	2007-01-31 13:17:50 UTC (rev 25307)
@@ -28,7 +28,7 @@
 
 namespace Gob {
 
-#define MAX_DATA_FILES	3
+#define MAX_DATA_FILES	6
 #define MAX_SLOT_COUNT	4
 
 class DataIO {

Modified: scummvm/trunk/engines/gob/game.cpp
===================================================================
--- scummvm/trunk/engines/gob/game.cpp	2007-01-31 10:42:18 UTC (rev 25306)
+++ scummvm/trunk/engines/gob/game.cpp	2007-01-31 13:17:50 UTC (rev 25307)
@@ -1058,7 +1058,9 @@
 
 	if (imdPtr->verMin & 0x4000) {
 		// loc_29C4F
-		error("GOB2 Stub! loadImdFile, imdPtr->verMin & 0x4000");
+		warning("GOB2 Stub! loadImdFile, imdPtr->verMin & 0x4000");
+		warning("Can't open IMD \"%s.IMD\"", path);
+		return 0;
 		// Sound stuff, I presume...
 	}
 

Modified: scummvm/trunk/engines/gob/inter.h
===================================================================
--- scummvm/trunk/engines/gob/inter.h	2007-01-31 10:42:18 UTC (rev 25306)
+++ scummvm/trunk/engines/gob/inter.h	2007-01-31 13:17:50 UTC (rev 25307)
@@ -321,7 +321,7 @@
 	void o2_switchTotSub(void);
 	void o2_stub0x54(void);
 	void o2_stub0x55(void);
-	void o2_stub0x81(void);
+	void o2_scroll(void);
 	void o2_stub0x85(void);
 	bool o2_getFreeMem(char &cmdCount, int16 &counter, int16 &retFlag);
 	bool o2_readData(char &cmdCount, int16 &counter, int16 &retFlag);

Modified: scummvm/trunk/engines/gob/inter_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter_v2.cpp	2007-01-31 10:42:18 UTC (rev 25306)
+++ scummvm/trunk/engines/gob/inter_v2.cpp	2007-01-31 13:17:50 UTC (rev 25307)
@@ -286,7 +286,7 @@
 		{NULL, ""},
 		/* 80 */
 		OPCODE(o2_initScreen),
-		OPCODE(o2_stub0x81),
+		OPCODE(o2_scroll),
 		OPCODE(o2_setScrollOffset),
 		OPCODE(o2_playImd),
 		/* 84 */
@@ -812,23 +812,6 @@
 	}
 }
 
-void Inter_v2::o2_stub0x81(void) {
-	int16 var1;
-	int16 var2;
-	int16 var3;
-	int16 var4;
-	int16 var5;
-	int16 var6;
-
-	var1 = _vm->_parse->parseValExpr();
-	var2 = _vm->_parse->parseValExpr();
-	var3 = _vm->_parse->parseValExpr();
-	var4 = _vm->_parse->parseValExpr();
-	var5 = _vm->_parse->parseValExpr();
-	var6 = _vm->_parse->parseValExpr();
-	warning("GOB2 Stub! o2_stub0x81(%d, %d, %d, %d, %d, %d)", var1, var2, var3, var4, var5, var6);
-}
-
 void Inter_v2::o2_stub0x85(void) {
 	char dest[32];
 
@@ -1508,6 +1491,7 @@
 	cmd = load16();
 	_vm->_global->_inter_execPtr += 2;
 
+	warning("goblinFunc %d", cmd);
 	if (cmd != 101)
 		executeGoblinOpcode(cmd, extraData, NULL, NULL);
 	return false;
@@ -2231,6 +2215,37 @@
 */
 }
 
+void Inter_v2::o2_scroll(void) {
+	int16 startX;
+	int16 startY;
+	int16 endX;
+	int16 endY;
+	int16 stepX;
+	int16 stepY;
+	int16 curX;
+	int16 curY;
+
+	startX = _vm->_parse->parseValExpr();
+	startY = _vm->_parse->parseValExpr();
+	endX = _vm->_parse->parseValExpr();
+	endY = _vm->_parse->parseValExpr();
+	stepX = _vm->_parse->parseValExpr();
+	stepY = _vm->_parse->parseValExpr();
+
+	if ((stepY != 0) || (startY > 0) || (endY > 0))
+		warning("GOB2 Stub! Vertical scrolling / high surfaces");
+
+	curX = startX;
+	curY = startY;
+	while ((curX != endX) || (curY != endY)) {
+		curX = stepX > 0 ? MIN(curX + stepX, (int) endX) : MAX(curX + stepX, (int) endX);
+		curY = stepY > 0 ? MIN(curY + stepY, (int) endY) : MAX(curY + stepY, (int) endY);
+		_vm->_draw->_word_2FC9E = curX;
+		_vm->_video->_scrollOffset = _vm->_draw->_word_2FC9E;
+		_vm->_video->waitRetrace(_vm->_global->_videoMode);
+	}
+}
+
 void Inter_v2::o2_totSub(void) {
 	char totFile[14];
 	byte length;

Modified: scummvm/trunk/engines/gob/mult.h
===================================================================
--- scummvm/trunk/engines/gob/mult.h	2007-01-31 10:42:18 UTC (rev 25306)
+++ scummvm/trunk/engines/gob/mult.h	2007-01-31 13:17:50 UTC (rev 25307)
@@ -146,7 +146,7 @@
 		int16 frame;
 		int16 cmd;
 		int16 freq;
-		int16 channel;
+		int16 fadeLength;
 		int16 repCount;
 		int16 resId;
 		int16 soundIndex;
@@ -248,7 +248,7 @@
 				  char handleMouse) = 0;
 	virtual void animate(void) = 0;
 	virtual void playSound(Snd::SoundDesc * soundDesc, int16 repCount,
-				  int16 freq, int16 channel) = 0;
+				  int16 freq, int16 fadeLength) = 0;
 	virtual void freeMult(void) = 0;
 	virtual void freeMultKeys(void) = 0;
 
@@ -280,7 +280,7 @@
 				  char handleMouse);
 	virtual void animate(void);
 	virtual void playSound(Snd::SoundDesc * soundDesc, int16 repCount,
-				  int16 freq, int16 channel);
+				  int16 freq, int16 fadeLength);
 	virtual void freeMult(void);
 	virtual void freeMultKeys(void);
 
@@ -367,7 +367,7 @@
 				  char handleMouse);
 	virtual void animate(void);
 	virtual void playSound(Snd::SoundDesc * soundDesc, int16 repCount,
-				  int16 freq, int16 channel);
+				  int16 freq, int16 fadeLength);
 	virtual void freeMult(void);
 	virtual void freeMultKeys(void);
 

Modified: scummvm/trunk/engines/gob/mult_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/mult_v1.cpp	2007-01-31 10:42:18 UTC (rev 25306)
+++ scummvm/trunk/engines/gob/mult_v1.cpp	2007-01-31 13:17:50 UTC (rev 25307)
@@ -143,7 +143,7 @@
 		_sndKeys[i].frame = data.readSint16LE();
 		_sndKeys[i].cmd = data.readSint16LE();
 		_sndKeys[i].freq = data.readSint16LE();
-		_sndKeys[i].channel = data.readSint16LE();
+		_sndKeys[i].fadeLength = data.readSint16LE();
 		_sndKeys[i].repCount = data.readSint16LE();
 		_sndKeys[i].soundIndex = -1;
 		_sndKeys[i].resId = -1;
@@ -589,17 +589,17 @@
 				_vm->_snd->stopSound(0);
 				stop = 0;
 				playSound(_vm->_game->_soundSamples[sndKey->soundIndex], sndKey->repCount,
-				    sndKey->freq, sndKey->channel);
+				    sndKey->freq, sndKey->fadeLength);
 
 			} else if (sndKey->cmd == 4) {
 				_vm->_snd->stopSound(0);
 				stop = 0;
 				playSound(_vm->_game->_soundSamples[sndKey->soundIndex], sndKey->repCount,
-				    sndKey->freq, sndKey->channel);
+				    sndKey->freq, sndKey->fadeLength);
 			}
 		} else {
 			if (_vm->_snd->_playingSound)
-				_vm->_snd->stopSound(sndKey->channel);
+				_vm->_snd->stopSound(sndKey->fadeLength);
 		}
 	}
 	return stop;
@@ -904,8 +904,8 @@
 }
 
 void Mult_v1::playSound(Snd::SoundDesc * soundDesc, int16 repCount, int16 freq,
-	    int16 channel) {
-	_vm->_snd->playSample(soundDesc, repCount, freq);
+	    int16 fadeLength) {
+	_vm->_snd->playSample(soundDesc, repCount, freq, fadeLength);
 }
 
 void Mult_v1::freeMultKeys(void) {

Modified: scummvm/trunk/engines/gob/mult_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/mult_v2.cpp	2007-01-31 10:42:18 UTC (rev 25306)
+++ scummvm/trunk/engines/gob/mult_v2.cpp	2007-01-31 13:17:50 UTC (rev 25307)
@@ -203,7 +203,7 @@
 		_multData2->sndKeys[i].frame = data.readSint16LE();
 		_multData2->sndKeys[i].cmd = data.readSint16LE();
 		_multData2->sndKeys[i].freq = data.readSint16LE();
-		_multData2->sndKeys[i].channel = data.readSint16LE();
+		_multData2->sndKeys[i].fadeLength = data.readSint16LE();
 		_multData2->sndKeys[i].repCount = data.readSint16LE();
 		_multData2->sndKeys[i].soundIndex = -1;
 		_multData2->sndKeys[i].resId = -1;
@@ -564,8 +564,8 @@
 			_animDataAllocated = 0;
 		}
 
-		if (_vm->_snd->_playingSound != 0)
-			_vm->_snd->stopSound(10);
+/*		if (_vm->_snd->_playingSound != 0)
+			_vm->_snd->stopSound(10);*/
 
 		WRITE_VAR(57, (uint32)-1);
 	} else
@@ -862,11 +862,11 @@
 				if (_vm->_game->_soundSamples[sndKey->soundIndex] == 0)
 					continue;
 				playSound(_vm->_game->_soundSamples[sndKey->soundIndex], sndKey->repCount,
-				    sndKey->freq, sndKey->channel);
+				    sndKey->freq, sndKey->fadeLength);
 			}
 		} else {
 			if (_vm->_snd->_playingSound)
-				_vm->_snd->stopSound(sndKey->channel);
+				_vm->_snd->stopSound(sndKey->fadeLength);
 		}
 	}
 	return stop;
@@ -1299,8 +1299,8 @@
 }
 
 void Mult_v2::playSound(Snd::SoundDesc * soundDesc, int16 repCount, int16 freq,
-	    int16 channel) {
-	_vm->_snd->playSample(soundDesc, repCount, freq);
+	    int16 fadeLength) {
+	_vm->_snd->playSample(soundDesc, repCount, freq, fadeLength);
 }
 
 void Mult_v2::freeMult(void) {

Modified: scummvm/trunk/engines/gob/sound.cpp
===================================================================
--- scummvm/trunk/engines/gob/sound.cpp	2007-01-31 10:42:18 UTC (rev 25306)
+++ scummvm/trunk/engines/gob/sound.cpp	2007-01-31 13:17:50 UTC (rev 25307)
@@ -72,6 +72,16 @@
 	_repCount = 0;
 	_offset = 0.0;
 
+	_frac = 0.0;
+	_cur = 0;
+	_last = 0;
+
+	_fade = false;
+	_fadeVol = 255.0;
+	_fadeVolStep = 0.0;
+	_fadeSamples = 0;
+	_curFadeSamples = 0;
+
 	_compositionPos = -1;
 
 	_vm->_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_handle,
@@ -98,16 +108,26 @@
 	return _composition[_compositionPos];
 }
 
-void Snd::stopSound(int16 arg)
+void Snd::stopSound(int16 fadeLength)
 {
 	Common::StackLock slock(_mutex);
 
-	_data = 0;
-	_end = true;
+	if (fadeLength <= 0) {
+		_data = 0;
+		_end = true;
+		_playingSound = 0;
+		return;
+	}
+
+	_fade = true;
+	_fadeVol = 255.0;
+	_fadeSamples = (int) (fadeLength * (((double) _rate) / 10.0));
+	_fadeVolStep = 255.0 / ((double) _fadeSamples);
+	_curFadeSamples = 0;
 }
 
 void Snd::waitEndPlay(void) {
-	while (!_end)
+	while (!_end && !_vm->_quitRequested)
 		_vm->_util->longDelay(200);
 	stopSound(0);
 }
@@ -125,7 +145,7 @@
 	while ((++_compositionPos < 50) && ((slot = _composition[_compositionPos]) != -1)) {
 		if ((slot >= 0) && (slot <= 60) && (_vm->_game->_soundSamples[slot] != 0)
 				&& !(_vm->_game->_soundTypes[slot] & 8)) {
-			setSample(_vm->_game->_soundSamples[slot], 1, 0);
+			setSample(_vm->_game->_soundSamples[slot], 1, 0, 0);
 			return;
 		}
 	}
@@ -165,7 +185,7 @@
 	delete sndDesc;
 }
 
-void Snd::setSample(Snd::SoundDesc *sndDesc, int16 repCount, int16 frequency) {
+void Snd::setSample(Snd::SoundDesc *sndDesc, int16 repCount, int16 frequency, int16 fadeLength) {
 	if (frequency <= 0)
 		frequency = sndDesc->frequency;
 
@@ -183,16 +203,29 @@
 	_last = 0;
 	_repCount = repCount;
 	_end = false;
-	_playingSound = 0;
+	_playingSound = 1;
+
+	_curFadeSamples = 0;
+	if (fadeLength == 0) {
+		_fade = false;
+		_fadeVol = 255.0;
+		_fadeSamples = 0;
+		_fadeVolStep = 0.0;
+	} else {
+		_fade = true;
+		_fadeVol = 0.0;
+		_fadeSamples = (int) (fadeLength * (((double) _rate) / 10.0));
+		_fadeVolStep = -(255.0 / ((double) _fadeSamples));
+	}
 }
 
-void Snd::playSample(Snd::SoundDesc *sndDesc, int16 repCount, int16 frequency) {
+void Snd::playSample(Snd::SoundDesc *sndDesc, int16 repCount, int16 frequency, int16 fadeLength) {
 	Common::StackLock slock(_mutex);
 
 	if (!_end)
 		return; 
 
-	setSample(sndDesc, repCount, frequency);
+	setSample(sndDesc, repCount, frequency, fadeLength);
 	if (!_vm->_mixer->isSoundHandleActive(_handle))
 		_vm->_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_handle,
 				this, -1, 255, 0, false, true);
@@ -204,7 +237,7 @@
 	else if ((_repCount == -1) || (--_repCount > 0)) {
 		_offset = 0.0;
 		_end = false;
-		_playingSound = 0;
+		_playingSound = 1;
 	} else {
 		_end = true;
 		_playingSound = 0;
@@ -224,13 +257,29 @@
 		if (_end)
 			return i;
 
-		*buffer++ = (int) (_last + (_cur - _last) * _frac);
+		*buffer++ = (int16) ((_last + (_cur - _last) * _frac) * _fadeVol);
 		_frac += _ratio;
 		while (_frac > 1) {
 			_frac -= 1;
 			_last = _cur;
-			_cur = _data[(int) _offset] << 8;
+			_cur = _data[(int) _offset];
 		}
+
+		if (_fade) {
+			if (++_curFadeSamples < _fadeSamples) {
+				_fadeVol -= _fadeVolStep;
+			} else {
+				if (_fadeVolStep > 0) {
+					_data = 0;
+					_end = true;
+					_playingSound = 0;
+				} else {
+					_fadeVol = 255.0;
+					_fade = false;
+				}
+			}
+		}
+
 		_offset += _ratio;
 	}
 	return numSamples;

Modified: scummvm/trunk/engines/gob/sound.h
===================================================================
--- scummvm/trunk/engines/gob/sound.h	2007-01-31 10:42:18 UTC (rev 25306)
+++ scummvm/trunk/engines/gob/sound.h	2007-01-31 13:17:50 UTC (rev 25307)
@@ -52,8 +52,8 @@
 	void speakerOn(int16 frequency, int32 length);
 	void speakerOff(void);
 	SoundDesc *loadSoundData(const char *path);
-	void stopSound(int16 arg);
-	void playSample(SoundDesc *sndDesc, int16 repCount, int16 frequency);
+	void stopSound(int16 fadeLength);
+	void playSample(SoundDesc *sndDesc, int16 repCount, int16 frequency, int16 fadeLength = 0);
 	void playComposition(int16 *composition, int16 freqVal);
 	void stopComposition(void);
 	int8 getCompositionSlot(void);
@@ -113,10 +113,18 @@
 	int32 _repCount;
 	double _offset;
 	double _ratio;
+
 	double _frac;
 	int16 _cur;
 	int16 _last;
 
+	bool _fade;
+	double _fadeVol;
+	double _fadeVolStep;
+	uint8 _fadeLength;
+	uint32 _fadeSamples;
+	uint32 _curFadeSamples;
+
 	GobEngine *_vm;
 
 	void cleanupFuncCallback() {;}
@@ -127,7 +135,7 @@
 	void writeAdlib(int16 port, int16 data);
 	void setBlasterPort(int16 port);
 	void setResetTimerFlag(char flag){return;}
-	void setSample(Snd::SoundDesc *sndDesc, int16 repCount, int16 frequency);
+	void setSample(Snd::SoundDesc *sndDesc, int16 repCount, int16 frequency, int16 fadeLength);
 	void checkEndSample(void);
 	void nextCompositionPos(void);
 };


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