[Scummvm-cvs-logs] SF.net SVN: scummvm: [20480] scummvm/trunk/kyra

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Fri Feb 10 08:41:08 CET 2006


Revision: 20480
Author:   lordhoto
Date:     2006-02-10 08:39:56 -0800 (Fri, 10 Feb 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm?rev=20480&view=rev

Log Message:
-----------
Added support for compressed speech in the engine (I only tried ogg and flac I guess mp3 should work too...)
Also changed some formatting.

Modified Paths:
--------------
    scummvm/trunk/kyra/resource.cpp
    scummvm/trunk/kyra/resource.h
    scummvm/trunk/kyra/sound.cpp
    scummvm/trunk/kyra/sound.h
Modified: scummvm/trunk/kyra/resource.cpp
===================================================================
--- scummvm/trunk/kyra/resource.cpp	2006-02-10 16:35:10 UTC (rev 20479)
+++ scummvm/trunk/kyra/resource.cpp	2006-02-10 16:39:56 UTC (rev 20480)
@@ -28,7 +28,7 @@
 #include "kyra/screen.h"
 
 namespace Kyra {
-Resource::Resource(KyraEngine* engine) {
+Resource::Resource(KyraEngine *engine) {
 	_engine = engine;
 
 	// No PAK files in the demo version
@@ -40,13 +40,13 @@
 	// ugly a hardcoded list
 	// TODO: use the FS Backend to get all .PAK Files and load them
 	// or any other thing to get all files
-	static const char* kyra1Filelist[] = {
+	static const char *kyra1Filelist[] = {
 		"A_E.PAK", "DAT.PAK", "F_L.PAK", "MAP_5.PAK", "MSC.PAK", "M_S.PAK",
 		"S_Z.PAK", "WSA1.PAK", "WSA2.PAK", "WSA3.PAK", "WSA4.PAK", "WSA5.PAK",
 		"WSA6.PAK", 0
 	};
 
-	static const char* kyra1CDFilelist[] = {
+	static const char *kyra1CDFilelist[] = {
 		"ALTAR.APK", "BELROOM.APK", "BONKBG.APK", "BROKEN.APK", "CASTLE.APK", "CAVE.APK", "CGATE.APK",
 		"DEAD.APK", "DNSTAIR.APK", "DRAGON1.APK", "DRAGON2.APK", "EXTPOT.APK", "FORESTA.APK", "FORESTB.APK",
 		"FOUNTN.APK", "FOYER.APK", "GATECV.APK", "GEM.APK", "GEMCUT.APK", "GENHALL.APK", "GLADE.APK", 
@@ -72,7 +72,7 @@
 		"CHAPTER1.VRM", 0
 	};
 
-	const char** usedFilelist = 0;
+	const char **usedFilelist = 0;
 
 	if (_engine->features() & GF_FLOPPY)
 		usedFilelist = kyra1Filelist;
@@ -83,7 +83,7 @@
 
 	for (uint32 tmp = 0; usedFilelist[tmp]; ++tmp) {
 		// prefetch file
-		PAKFile* file = new PAKFile(usedFilelist[tmp]);
+		PAKFile *file = new PAKFile(usedFilelist[tmp]);
 		assert(file);
 
 		PakFileEntry newPak;
@@ -110,7 +110,7 @@
 bool Resource::loadPakFile(const char *filename) {
 	if (isInPakList(filename))
 		return true;
-	PAKFile* file = new PAKFile(filename);
+	PAKFile *file = new PAKFile(filename);
 	if (!file) {
 		error("couldn't load file: '%s'", filename);
 	}
@@ -142,8 +142,8 @@
 	return false;
 }
 
-uint8* Resource::fileData(const char* file, uint32* size) {
-	uint8* buffer = 0;
+uint8 *Resource::fileData(const char *file, uint32 *size) {
+	uint8 *buffer = 0;
 	Common::File file_;
 
 	// test to open it in the main dir
@@ -178,6 +178,28 @@
 	return buffer;
 }
 
+bool Resource::fileHandle(const char *file, uint32 *size, Common::File &filehandle) {
+	filehandle.close();
+
+	if (filehandle.open(file))
+		return true;
+
+	Common::List<PakFileEntry>::iterator start = _pakfiles.begin();
+
+	for (;start != _pakfiles.end(); ++start) {
+		*size = start->_file->getFileSize(file);
+		
+		if (!(*size))
+			continue;
+
+		if (start->_file->getFileHandle(file, filehandle)) {
+			return true;
+		}
+	}
+	
+	return false;
+}
+
 ///////////////////////////////////////////
 // Pak file manager
 #define PAKFile_Iterate Common::List<PakChunk*>::iterator start=_files.begin();start != _files.end(); ++start
@@ -256,7 +278,7 @@
 	}
 }
 
-uint8* PAKFile::getFile(const char* file) {
+uint8 *PAKFile::getFile(const char *file) {
 	for (PAKFile_Iterate) {
 		if (!scumm_stricmp((*start)->_name, file)) {
 			Common::File pakfile;
@@ -274,6 +296,22 @@
 	return 0;
 }
 
+bool PAKFile::getFileHandle(const char *file, Common::File &filehandle) {
+	filehandle.close();
+
+	for (PAKFile_Iterate) {
+		if (!scumm_stricmp((*start)->_name, file)) {
+			if (!filehandle.open(_filename)) {
+				debug(3, "couldn't open pakfile '%s'\n", _filename);
+				return 0;
+			}
+			filehandle.seek((*start)->_start);
+			return true;
+		}
+	}
+	return false;
+}
+
 uint32 PAKFile::getFileSize(const char* file) {
 	for (PAKFile_Iterate) {
 		if (!scumm_stricmp((*start)->_name, file))

Modified: scummvm/trunk/kyra/resource.h
===================================================================
--- scummvm/trunk/kyra/resource.h	2006-02-10 16:35:10 UTC (rev 20479)
+++ scummvm/trunk/kyra/resource.h	2006-02-10 16:39:56 UTC (rev 20480)
@@ -43,11 +43,12 @@
 
 public:
 
-	PAKFile(const Common::String& file);
+	PAKFile(const Common::String &file);
 	~PAKFile();
 
-	uint8* getFile(const char* file);
-	uint32 getFileSize(const char* file);
+	uint8* getFile(const char *file);
+	bool getFileHandle(const char *file, Common::File &filehandle);
+	uint32 getFileSize(const char *file);
 
 	bool isValid(void) const { return (_filename != 0); }
 	bool isOpen(void) const { return _open; }
@@ -66,14 +67,18 @@
 class Resource {
 public:
 
-	Resource(KyraEngine* engine);
+	Resource(KyraEngine *engine);
 	~Resource();
 	
 	bool loadPakFile(const char *filename);
 	void unloadPakFile(const char *filename);
 	bool isInPakList(const char *filename);
 
-	uint8* fileData(const char* file, uint32* size);
+	uint8* fileData(const char *file, uint32 *size);
+	// it gives back a file handle (used for the speech player)
+	// it could be that the needed file is embedded in the returned
+	// handle
+	bool fileHandle(const char *file, uint32 *size, Common::File &filehandle);
 
 protected:
 	struct PakFileEntry {

Modified: scummvm/trunk/kyra/sound.cpp
===================================================================
--- scummvm/trunk/kyra/sound.cpp	2006-02-10 16:35:10 UTC (rev 20479)
+++ scummvm/trunk/kyra/sound.cpp	2006-02-10 16:39:56 UTC (rev 20480)
@@ -29,6 +29,10 @@
 #include "sound/voc.h"
 #include "sound/audiostream.h"
 
+#include "sound/mp3.h"
+#include "sound/vorbis.h"
+#include "sound/flac.h"
+
 namespace Kyra {
 
 SoundPC::SoundPC(MidiDriver *driver, Audio::Mixer *mixer, KyraEngine *engine) : Sound() {
@@ -332,14 +336,38 @@
 void SoundPC::voicePlay(const char *file) {
 	uint32 fileSize = 0;
 	byte *fileData = 0;
-	fileData = _engine->resource()->fileData(file, &fileSize);
-	assert(fileData);
-	Common::MemoryReadStream vocStream(fileData, fileSize);
-	_mixer->stopHandle(_vocHandle);
-	_currentVocFile = makeVOCStream(vocStream);
+	bool found = false;
+	char filenamebuffer[25];
+
+	for (int i = 0; _supportedCodes[i].fileext; ++i) {
+		strcpy(filenamebuffer, file);
+		strcat(filenamebuffer, _supportedCodes[i].fileext);
+
+		_engine->resource()->fileHandle(filenamebuffer, &fileSize, _compressHandle);
+		if (!_compressHandle.isOpen())
+			continue;
+		
+		_currentVocFile = _supportedCodes[i].streamFunc(&_compressHandle, fileSize);
+		found = true;
+		break;
+	}
+
+	if (!found) {
+		strcpy(filenamebuffer, file);
+		strcat(filenamebuffer, ".VOC");
+		
+		fileData = _engine->resource()->fileData(filenamebuffer, &fileSize);
+		if (!fileData)
+			return;
+
+		Common::MemoryReadStream vocStream(fileData, fileSize);
+		_mixer->stopHandle(_vocHandle);
+		_currentVocFile = makeVOCStream(vocStream);
+	}
+
 	if (_currentVocFile)
 		_mixer->playInputStream(Audio::Mixer::kSpeechSoundType, &_vocHandle, _currentVocFile);
-	delete fileData;
+	delete [] fileData;
 	fileSize = 0;
 }
 
@@ -416,7 +444,7 @@
 	debug(9, "KyraEngine::snd_playVoiceFile(%d)", id);
 	char vocFile[9];
 	assert(id >= 0 && id < 9999);
-	sprintf(vocFile, "%03d.VOC", id);
+	sprintf(vocFile, "%03d", id);
 	_sound->voicePlay(vocFile);
 }
 
@@ -431,4 +459,19 @@
 	}
 }
 
+// static res
+
+const SoundPC::SpeechCodecs SoundPC::_supportedCodes[] = {
+#ifdef USE_MAD
+	{ ".VO3", makeMP3Stream },
+#endif // USE_MAD
+#ifdef USE_VORBIS
+	{ ".VOG", makeVorbisStream },
+#endif // USE_VORBIS
+#ifdef USE_FLAC
+	{ ".VOF", makeFlacStream },
+#endif // USE_FLAC
+	{ 0, 0 }
+};
+
 } // end of namespace Kyra

Modified: scummvm/trunk/kyra/sound.h
===================================================================
--- scummvm/trunk/kyra/sound.h	2006-02-10 16:35:10 UTC (rev 20479)
+++ scummvm/trunk/kyra/sound.h	2006-02-10 16:39:56 UTC (rev 20480)
@@ -141,6 +141,14 @@
 	Audio::Mixer *_mixer;
 	AudioStream *_currentVocFile;
 	Audio::SoundHandle _vocHandle;
+	Common::File _compressHandle;
+	
+	struct SpeechCodecs {
+		const char *fileext;
+		AudioStream *(*streamFunc)(Common::File*, uint32);
+	};
+	
+	static const SpeechCodecs _supportedCodes[];
 };
 } // end of namespace Kyra
 







More information about the Scummvm-git-logs mailing list