[Scummvm-cvs-logs] SF.net SVN: scummvm:[35845] scummvm/trunk/engines/made

john_doe at users.sourceforge.net john_doe at users.sourceforge.net
Tue Jan 13 17:18:23 CET 2009


Revision: 35845
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35845&view=rev
Author:   john_doe
Date:     2009-01-13 16:18:22 +0000 (Tue, 13 Jan 2009)

Log Message:
-----------
Reworked the sound energy code

Modified Paths:
--------------
    scummvm/trunk/engines/made/made.h
    scummvm/trunk/engines/made/resource.cpp
    scummvm/trunk/engines/made/resource.h
    scummvm/trunk/engines/made/scriptfuncs.cpp
    scummvm/trunk/engines/made/sound.cpp
    scummvm/trunk/engines/made/sound.h

Modified: scummvm/trunk/engines/made/made.h
===================================================================
--- scummvm/trunk/engines/made/made.h	2009-01-13 15:40:46 UTC (rev 35844)
+++ scummvm/trunk/engines/made/made.h	2009-01-13 16:18:22 UTC (rev 35845)
@@ -45,6 +45,8 @@
 
 #include "engines/engine.h"
 
+#include "made/sound.h"
+
 namespace Made {
 
 enum MadeGameID {
@@ -115,6 +117,8 @@
 
 	int _soundRate;
 	bool _autoStopSound;
+	uint _soundEnergyIndex;
+	SoundEnergyArray *_soundEnergyArray;
 
 	// 2 = LGOP2, Manhole N&E
 	// 3 = Return to Zork

Modified: scummvm/trunk/engines/made/resource.cpp
===================================================================
--- scummvm/trunk/engines/made/resource.cpp	2009-01-13 15:40:46 UTC (rev 35844)
+++ scummvm/trunk/engines/made/resource.cpp	2009-01-13 16:18:22 UTC (rev 35845)
@@ -157,8 +157,8 @@
 }
 
 SoundResource::~SoundResource() {
-	if (_soundData)
-		delete[] _soundData;
+	delete[] _soundData;
+	delete _soundEnergyArray;
 }
 
 void SoundResource::load(byte *source, int size) {
@@ -169,7 +169,10 @@
 	_soundSize = chunkCount * chunkSize;
 	_soundData = new byte[_soundSize];
 
-	decompressSound(source + 14, _soundData, chunkSize, chunkCount);
+	_soundEnergyArray = new SoundEnergyArray;
+
+	decompressSound(source + 14, _soundData, chunkSize, chunkCount, _soundEnergyArray);
+	
 }
 
 Audio::AudioStream *SoundResource::getAudioStream(int soundRate, bool loop) {

Modified: scummvm/trunk/engines/made/resource.h
===================================================================
--- scummvm/trunk/engines/made/resource.h	2009-01-13 15:40:46 UTC (rev 35844)
+++ scummvm/trunk/engines/made/resource.h	2009-01-13 16:18:22 UTC (rev 35845)
@@ -33,6 +33,8 @@
 #include "graphics/surface.h"
 #include "sound/audiostream.h"
 
+#include "made/sound.h"
+
 namespace Made {
 
 const int kMaxResourceCacheCount = 100;
@@ -104,9 +106,11 @@
 	~SoundResource();
 	void load(byte *source, int size);
 	Audio::AudioStream *getAudioStream(int soundRate, bool loop = false);
+	SoundEnergyArray *getSoundEnergyArray() const { return _soundEnergyArray; }
 protected:
 	byte *_soundData;
 	int _soundSize;
+	SoundEnergyArray *_soundEnergyArray;
 };
 
 class MenuResource : public Resource {

Modified: scummvm/trunk/engines/made/scriptfuncs.cpp
===================================================================
--- scummvm/trunk/engines/made/scriptfuncs.cpp	2009-01-13 15:40:46 UTC (rev 35844)
+++ scummvm/trunk/engines/made/scriptfuncs.cpp	2009-01-13 16:18:22 UTC (rev 35845)
@@ -237,8 +237,11 @@
 		_vm->_autoStopSound = (argv[0] == 1);
 	}
 	if (soundNum > 0) {
+		SoundResource *soundRes = _vm->_res->getSound(soundNum);
 		_vm->_mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_audioStreamHandle,
-			_vm->_res->getSound(soundNum)->getAudioStream(_vm->_soundRate, false));
+			soundRes->getAudioStream(_vm->_soundRate, false));
+		_vm->_soundEnergyArray = soundRes->getSoundEnergyArray();
+		_vm->_soundEnergyIndex = 0;
 	}
 	return 0;
 }
@@ -616,20 +619,20 @@
 	// This is called while in-game voices are played to animate 
 	// mouths when NPCs are talking
 
-	// FIXME: the mouth animations are out of sync. This occurs
-	// because the original unpacked sounds on the fly, whereas
-	// in ScummVM we unpack them when they're loaded. In ScummVM,
-	// the "sound energy" values are stored in an array (used as
-	// a stack), which means that sfGetSoundEnergy can empty that
-	// array prematurely. A proper fix would be to figure out
-	// when a value should be popped from the sound energy stack,
-	// or to unpack sounds on the fly like the original does 
+	int result = 0;
 
-	int result = 0;
-	if (soundEnergy.size() > 0) {
-		result = *soundEnergy.begin();
-		soundEnergy.pop_front();
+	if (_vm->_mixer->isSoundHandleActive(_audioStreamHandle) && _vm->_soundEnergyArray &&
+		_vm->_soundEnergyIndex < _vm->_soundEnergyArray->size()) {
+		
+		uint32 position = (_vm->_soundRate / 1000) * _vm->_mixer->getSoundElapsedTime(_audioStreamHandle);
+		SoundEnergyItem *soundEnergyItem = &_vm->_soundEnergyArray->operator[](_vm->_soundEnergyIndex);
+
+		result = soundEnergyItem->energy;
+		
+		if (position >= soundEnergyItem->position)
+			_vm->_soundEnergyIndex++;
 	}
+
 	return result;
 }
 

Modified: scummvm/trunk/engines/made/sound.cpp
===================================================================
--- scummvm/trunk/engines/made/sound.cpp	2009-01-13 15:40:46 UTC (rev 35844)
+++ scummvm/trunk/engines/made/sound.cpp	2009-01-13 16:18:22 UTC (rev 35845)
@@ -31,10 +31,8 @@
 
 namespace Made {
 
-Common::List<int> soundEnergy;
+void decompressSound(byte *source, byte *dest, uint16 chunkSize, uint16 chunkCount, SoundEnergyArray *soundEnergyArray) {
 
-void decompressSound(byte *source, byte *dest, uint16 chunkSize, uint16 chunkCount) {
-
 	int16 prevSample = 0, workSample = 0;
 	byte soundBuffer[1025];
 	byte deltaSoundBuffer[1024];
@@ -45,6 +43,8 @@
 	uint16 ofs = 0;
 	uint16 i = 0, l = 0;
 	byte val;
+	
+	SoundEnergyItem soundEnergyItem;
 
 	const int modeValues[3][4] = {
 		{ 2, 8, 0x01, 1},
@@ -52,8 +52,11 @@
 		{16, 2, 0x0F, 4}
 	};
 
-	soundEnergy.clear();
+	soundEnergyItem.position = 0;
 
+	if (soundEnergyArray)
+		soundEnergyArray->clear();
+
 	while (chunkCount--) {
 		deltaType = (*source) >> 6;
 		workChunkSize = chunkSize;
@@ -71,8 +74,12 @@
 
 		case 0:
 			memset(soundBuffer, 0x80, workChunkSize);
-			workSample = 0;			
-			soundEnergy.push_back(0);
+			workSample = 0;
+
+			soundEnergyItem.energy = 0;
+			if (soundEnergyArray)
+				soundEnergyArray->push_back(soundEnergyItem);
+
 			break;
 
 		case 1:
@@ -99,14 +106,21 @@
 				}
 			}
 
-			soundEnergy.push_back(type - 1);
+			soundEnergyItem.energy = type - 1;
+			if (soundEnergyArray)
+				soundEnergyArray->push_back(soundEnergyItem);
+
 			break;
 
 		case 5:
 			for (i = 0; i < workChunkSize; i++)
 				soundBuffer[i] = *source++;
 			workSample = soundBuffer[workChunkSize - 1] - 128;
-			soundEnergy.push_back(type - 1);
+			
+			soundEnergyItem.energy = type - 1;
+			if (soundEnergyArray)
+				soundEnergyArray->push_back(soundEnergyItem);
+			
 			break;
 
 		default:
@@ -137,6 +151,7 @@
 		prevSample = workSample;
 		memcpy(dest, soundBuffer, chunkSize);
 		dest += chunkSize;
+		soundEnergyItem.position += chunkSize;
 
 	}
 

Modified: scummvm/trunk/engines/made/sound.h
===================================================================
--- scummvm/trunk/engines/made/sound.h	2009-01-13 15:40:46 UTC (rev 35844)
+++ scummvm/trunk/engines/made/sound.h	2009-01-13 16:18:22 UTC (rev 35845)
@@ -33,10 +33,15 @@
 
 namespace Made {
 
-extern Common::List<int> soundEnergy;
+struct SoundEnergyItem {
+	uint32 position;
+	byte energy;
+};
 
-void decompressSound(byte *source, byte *dest, uint16 chunkSize, uint16 chunkCount);
+typedef Common::Array<SoundEnergyItem> SoundEnergyArray;
 
+void decompressSound(byte *source, byte *dest, uint16 chunkSize, uint16 chunkCount, SoundEnergyArray *soundEnergyArray = NULL);
+
 } // End of namespace Made
 
 #endif /* MADE_H */


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