[Scummvm-cvs-logs] SF.net SVN: scummvm:[43733] scummvm/trunk/engines/tucker

cyx at users.sourceforge.net cyx at users.sourceforge.net
Tue Aug 25 23:28:29 CEST 2009


Revision: 43733
          http://scummvm.svn.sourceforge.net/scummvm/?rev=43733&view=rev
Author:   cyx
Date:     2009-08-25 21:28:29 +0000 (Tue, 25 Aug 2009)

Log Message:
-----------
TUCKER: add support for commpressed intro sound effects

Modified Paths:
--------------
    scummvm/trunk/engines/tucker/resource.cpp
    scummvm/trunk/engines/tucker/sequences.cpp
    scummvm/trunk/engines/tucker/tucker.cpp
    scummvm/trunk/engines/tucker/tucker.h

Modified: scummvm/trunk/engines/tucker/resource.cpp
===================================================================
--- scummvm/trunk/engines/tucker/resource.cpp	2009-08-25 21:26:56 UTC (rev 43732)
+++ scummvm/trunk/engines/tucker/resource.cpp	2009-08-25 21:28:29 UTC (rev 43733)
@@ -211,13 +211,14 @@
 	return p;
 }
 
-void TuckerEngine::openCompressedSoundFile() {
+void CompressedSound::openFile() {
 	_compressedSoundType = -1;
 	for (int i = 0; compressedSoundFilesTable[i].filename; ++i) {
 		if (_fCompressedSound.open(compressedSoundFilesTable[i].filename)) {
 			int version = _fCompressedSound.readUint16LE();
 			if (version == kCurrentCompressedSoundDataVersion) {
 				_compressedSoundType = i;
+				_compressedSoundFlags = _fCompressedSound.readUint16LE();
 				debug(1, "Using compressed sound file '%s'", compressedSoundFilesTable[i].filename);
 				return;
 			}
@@ -226,10 +227,52 @@
 	}
 }
 
-void TuckerEngine::closeCompressedSoundFile() {
+void CompressedSound::closeFile() {
 	_fCompressedSound.close();
 }
 
+Audio::AudioStream *CompressedSound::load(CompressedSoundType type, int num, bool loop) {
+	if (_compressedSoundType < 0) {
+		return 0;
+	}
+	int offset = 0;
+	switch (type) {
+	case kSoundTypeFx:
+		offset = kCompressedSoundDataFileHeaderSize;
+		break;
+	case kSoundTypeMusic:
+		offset = kCompressedSoundDataFileHeaderSize + 8;
+		break;
+	case kSoundTypeSpeech:
+		offset = kCompressedSoundDataFileHeaderSize + 16;
+		break;
+	case kSoundTypeIntro:
+		if (_compressedSoundFlags & 1) {
+			offset = kCompressedSoundDataFileHeaderSize + 24;
+		}
+		break;
+	}
+	Audio::AudioStream *stream = 0;
+	_fCompressedSound.seek(offset);
+	int dirOffset = _fCompressedSound.readUint32LE();
+	int dirSize = _fCompressedSound.readUint32LE();
+	if (num < dirSize) {
+		const int dirHeaderSize = (_compressedSoundFlags & 1) ? 4 * 8 : 3 * 8;
+		dirOffset += kCompressedSoundDataFileHeaderSize + dirHeaderSize;
+		_fCompressedSound.seek(dirOffset + num * 8);
+		int soundOffset = _fCompressedSound.readUint32LE();
+		int soundSize = _fCompressedSound.readUint32LE();
+		if (soundSize != 0) {
+			_fCompressedSound.seek(dirOffset + dirSize * 8 + soundOffset);
+			Common::MemoryReadStream *tmp = _fCompressedSound.readStream(soundSize);
+			if (tmp) {
+				stream = (compressedSoundFilesTable[_compressedSoundType].makeStream)(tmp, true, 0, 0, loop ? 0 : 1);
+			}
+		}
+	}
+	return stream;
+}
+
 void TuckerEngine::loadImage(const char *fname, uint8 *dst, int type) {
 	char filename[80];
 	strcpy(filename, fname);
@@ -866,7 +909,20 @@
 
 void TuckerEngine::loadSound(Audio::Mixer::SoundType type, int num, int volume, bool loop, Audio::SoundHandle *handle) {
 	Audio::AudioStream *stream = 0;
-	if (_compressedSoundType < 0) {
+	switch (type) {
+	case Audio::Mixer::kSFXSoundType:
+		stream = _compressedSound.load(kSoundTypeFx, num, loop);
+		break;
+	case Audio::Mixer::kMusicSoundType:
+		stream = _compressedSound.load(kSoundTypeMusic, num, loop);
+		break;
+	case Audio::Mixer::kSpeechSoundType:
+		stream = _compressedSound.load(kSoundTypeSpeech, num, loop);
+		break;
+	default:
+		return;
+	}
+	if (!stream) {
 		const char *fmt = 0;
 		switch (type) {
 		case Audio::Mixer::kSFXSoundType:
@@ -899,37 +955,6 @@
 				}
 			}
 		}
-	} else {
-		int offset = 0;
-		switch (type) {
-		case Audio::Mixer::kSFXSoundType:
-			offset = kCompressedSoundDataFileHeaderSize;
-			break;
-		case Audio::Mixer::kMusicSoundType:
-			offset = kCompressedSoundDataFileHeaderSize + 8;
-			break;
-		case Audio::Mixer::kSpeechSoundType:
-			offset = kCompressedSoundDataFileHeaderSize + 16;
-			break;
-		default:
-			return;
-		}
-		_fCompressedSound.seek(offset);
-		int dirOffset = _fCompressedSound.readUint32LE();
-		int dirSize = _fCompressedSound.readUint32LE();
-		if (num < dirSize) {
-			dirOffset += kCompressedSoundDataFileHeaderSize + 3 * 8;
-			_fCompressedSound.seek(dirOffset + num * 8);
-			int soundOffset = _fCompressedSound.readUint32LE();
-			int soundSize = _fCompressedSound.readUint32LE();
-			if (soundSize != 0) {
-				_fCompressedSound.seek(dirOffset + dirSize * 8 + soundOffset);
-				Common::MemoryReadStream *tmp = _fCompressedSound.readStream(soundSize);
-				if (tmp) {
-					stream = (compressedSoundFilesTable[_compressedSoundType].makeStream)(tmp, true, 0, 0, loop ? 0 : 1);
-				}
-			}
-		}
 	}
 	if (stream) {
 		_mixer->stopHandle(*handle);

Modified: scummvm/trunk/engines/tucker/sequences.cpp
===================================================================
--- scummvm/trunk/engines/tucker/sequences.cpp	2009-08-25 21:26:56 UTC (rev 43732)
+++ scummvm/trunk/engines/tucker/sequences.cpp	2009-08-25 21:28:29 UTC (rev 43733)
@@ -35,7 +35,7 @@
 
 void TuckerEngine::handleIntroSequence() {
 	const int firstSequence = (_gameFlags & kGameFlagDemo) != 0 ? kFirstAnimationSequenceDemo : kFirstAnimationSequenceGame;
-	_player = new AnimationSequencePlayer(_system, _mixer, _eventMan, firstSequence);
+	_player = new AnimationSequencePlayer(_system, _mixer, _eventMan, &_compressedSound, firstSequence);
 	_player->mainLoop();
 	delete _player;
 	_player = 0;
@@ -492,8 +492,8 @@
 	return 1;
 }
 
-AnimationSequencePlayer::AnimationSequencePlayer(OSystem *system, Audio::Mixer *mixer, Common::EventManager *event, int num)
-	: _system(system), _mixer(mixer), _event(event), _seqNum(num) {
+AnimationSequencePlayer::AnimationSequencePlayer(OSystem *system, Audio::Mixer *mixer, Common::EventManager *event, CompressedSound *sound, int num)
+	: _system(system), _mixer(mixer), _event(event), _compressedSound(sound), _seqNum(num) {
 	memset(_animationPalette, 0, sizeof(_animationPalette));
 	_soundSeqDataCount = 0;
 	_soundSeqDataIndex = 0;
@@ -585,8 +585,11 @@
 	} while (_lastFrameTime <= end);
 }
 
-Audio::AudioStream *AnimationSequencePlayer::loadSoundFileAsStream(int index, AnimationSoundType type) {
-	Audio::AudioStream *stream = 0;
+Audio::AudioStream *AnimationSequencePlayer::loadSound(int index, AnimationSoundType type) {
+	Audio::AudioStream *stream = _compressedSound->load(kSoundTypeIntro, index, type == kAnimationSoundTypeLoopingWAV);
+	if (stream) {
+		return stream;
+	}
 	char fileName[64];
 	snprintf(fileName, sizeof(fileName), "audio/%s", _audioFileNamesTable[index]);
 	Common::File f;
@@ -626,7 +629,7 @@
 void AnimationSequencePlayer::loadSounds(int num) {
 	if (_soundSeqDataList[num].musicVolume != 0) {
 		Audio::AudioStream *s;
-		if ((s = loadSoundFileAsStream(_soundSeqDataList[num].musicIndex, kAnimationSoundType8BitsRAW)) != 0) {
+		if ((s = loadSound(_soundSeqDataList[num].musicIndex, kAnimationSoundType8BitsRAW)) != 0) {
 			_mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, s, -1, scaleMixerVolume(_soundSeqDataList[num].musicVolume));
 		}
 	}
@@ -641,12 +644,12 @@
 	while (_soundSeqDataIndex < _soundSeqDataCount && p->timestamp <= _frameCounter) {
 		switch (p->opcode) {
 		case 0:
-			if ((s = loadSoundFileAsStream(p->num, kAnimationSoundTypeWAV)) != 0) {
+			if ((s = loadSound(p->num, kAnimationSoundTypeWAV)) != 0) {
 				_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_soundsHandle[p->index], s, -1, scaleMixerVolume(p->volume));
 			}
 			break;
 		case 1:
-			if ((s = loadSoundFileAsStream(p->num, kAnimationSoundTypeLoopingWAV)) != 0) {
+			if ((s = loadSound(p->num, kAnimationSoundTypeLoopingWAV)) != 0) {
 				_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_soundsHandle[p->index], s, -1, scaleMixerVolume(p->volume));
 			}
 			break;
@@ -658,18 +661,18 @@
 			break;
 		case 4:
 			_mixer->stopHandle(_musicHandle);
-			if ((s = loadSoundFileAsStream(p->num, kAnimationSoundType8BitsRAW)) != 0) {
+			if ((s = loadSound(p->num, kAnimationSoundType8BitsRAW)) != 0) {
 				_mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, s, -1, scaleMixerVolume(p->volume));
 			}
 			break;
 		case 5:
-			if ((s = loadSoundFileAsStream(p->num, kAnimationSoundTypeWAV)) != 0) {
+			if ((s = loadSound(p->num, kAnimationSoundTypeWAV)) != 0) {
 				_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, s, -1, scaleMixerVolume(p->volume));
 			}
 			break;
 		case 6:
 			_mixer->stopHandle(_musicHandle);
-			if ((s = loadSoundFileAsStream(p->num, kAnimationSoundType16BitsRAW)) != 0) {
+			if ((s = loadSound(p->num, kAnimationSoundType16BitsRAW)) != 0) {
 				_mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, s, -1, scaleMixerVolume(p->volume));
 			}
 			break;

Modified: scummvm/trunk/engines/tucker/tucker.cpp
===================================================================
--- scummvm/trunk/engines/tucker/tucker.cpp	2009-08-25 21:26:56 UTC (rev 43732)
+++ scummvm/trunk/engines/tucker/tucker.cpp	2009-08-25 21:28:29 UTC (rev 43733)
@@ -55,11 +55,12 @@
 Common::Error TuckerEngine::run() {
 	initGraphics(kScreenWidth, kScreenHeight, false);
 	syncSoundSettings();
-
+	_compressedSound.openFile();
 	handleIntroSequence();
 	if ((_gameFlags & kGameFlagIntroOnly) == 0 && !shouldQuit()) {
 		mainLoop();
 	}
+	_compressedSound.closeFile();
 	return Common::kNoError;
 }
 
@@ -332,7 +333,6 @@
 	allocateBuffers();
 	restart();
 
-	openCompressedSoundFile();
 	loadCharSizeDta();
 	if ((_gameFlags & kGameFlagDemo) != 0) {
 		addObjectToInventory(30);
@@ -586,7 +586,6 @@
 	if (_flagsTable[100] == 1) {
 		handleCongratulationsSequence();
 	}
-	closeCompressedSoundFile();
 	unloadSprA02_01();
 	unloadSprC02_01();
 	freeBuffers();

Modified: scummvm/trunk/engines/tucker/tucker.h
===================================================================
--- scummvm/trunk/engines/tucker/tucker.h	2009-08-25 21:26:56 UTC (rev 43732)
+++ scummvm/trunk/engines/tucker/tucker.h	2009-08-25 21:28:29 UTC (rev 43733)
@@ -210,6 +210,29 @@
 	kGameFlagIntroOnly = 1 << 3
 };
 
+enum CompressedSoundType {
+	kSoundTypeFx,
+	kSoundTypeMusic,
+	kSoundTypeSpeech,
+	kSoundTypeIntro
+};
+
+class CompressedSound {
+public:
+
+	CompressedSound() : _compressedSoundType(-1) {}
+
+	void openFile();
+	void closeFile();
+	Audio::AudioStream *load(CompressedSoundType type, int num, bool loop);
+
+private:
+
+	int _compressedSoundType;
+	int _compressedSoundFlags;
+	Common::File _fCompressedSound;
+};
+
 inline int scaleMixerVolume(int volume, int max = 100) {
 	return volume * Audio::Mixer::kMaxChannelVolume / max;
 }
@@ -542,8 +565,6 @@
 	void copyMapRect(int x, int y, int w, int h);
 	int handleSpecialObjectSelectionSequence();
 
-	void openCompressedSoundFile();
-	void closeCompressedSoundFile();
 	uint8 *loadFile(const char *filename, uint8 *p);
 	void loadImage(const char *filename, uint8 *dst, int a);
 	void loadCursor();
@@ -574,6 +595,7 @@
 
 	Common::RandomSource _rnd;
 	AnimationSequencePlayer *_player;
+	CompressedSound _compressedSound;
 	Common::Language _gameLang;
 	uint32 _gameFlags;
 
@@ -603,8 +625,6 @@
 	int _gameHintsStringNum;
 
 	int _fileLoadSize;
-	int _compressedSoundType;
-	Common::File _fCompressedSound;
 	uint8 *_loadTempBuf;
 	uint8 *_cursorGfxBuf;
 	uint8 *_charsetGfxBuf;
@@ -890,7 +910,7 @@
 		void (AnimationSequencePlayer::*play)();
 	};
 
-	AnimationSequencePlayer(OSystem *system, Audio::Mixer *mixer, Common::EventManager *event, int num);
+	AnimationSequencePlayer(OSystem *system, Audio::Mixer *mixer, Common::EventManager *event, CompressedSound *sound, int num);
 	~AnimationSequencePlayer();
 
 	void mainLoop();
@@ -899,7 +919,7 @@
 
 	void syncTime();
 	void loadSounds(int num);
-	Audio::AudioStream *loadSoundFileAsStream(int index, AnimationSoundType type);
+	Audio::AudioStream *loadSound(int index, AnimationSoundType type);
 	void updateSounds();
 	void fadeInPalette();
 	void fadeOutPalette();
@@ -933,6 +953,7 @@
 	OSystem *_system;
 	Audio::Mixer *_mixer;
 	Common::EventManager *_event;
+	CompressedSound *_compressedSound;
 
 	int _seqNum;
 	bool _changeToNextSequence;


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