aboutsummaryrefslogtreecommitdiff
path: root/kyra
diff options
context:
space:
mode:
authorJohannes Schickel2006-02-10 16:39:56 +0000
committerJohannes Schickel2006-02-10 16:39:56 +0000
commit5398ef1532fc5839d0ee4c4c15de0bc7c826476d (patch)
tree361252441a2a8a1f65ce3d05fe3d743867a8e714 /kyra
parent410261e8b443f70c5d98bb16a11274d3778537cf (diff)
downloadscummvm-rg350-5398ef1532fc5839d0ee4c4c15de0bc7c826476d.tar.gz
scummvm-rg350-5398ef1532fc5839d0ee4c4c15de0bc7c826476d.tar.bz2
scummvm-rg350-5398ef1532fc5839d0ee4c4c15de0bc7c826476d.zip
Added support for compressed speech in the engine (I only tried ogg and flac I guess mp3 should work too...)
Also changed some formatting. svn-id: r20480
Diffstat (limited to 'kyra')
-rw-r--r--kyra/resource.cpp56
-rw-r--r--kyra/resource.h15
-rw-r--r--kyra/sound.cpp57
-rw-r--r--kyra/sound.h8
4 files changed, 115 insertions, 21 deletions
diff --git a/kyra/resource.cpp b/kyra/resource.cpp
index 313c06d719..0dd76ff5de 100644
--- a/kyra/resource.cpp
+++ b/kyra/resource.cpp
@@ -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 @@ Resource::Resource(KyraEngine* engine) {
// 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 @@ Resource::Resource(KyraEngine* engine) {
"CHAPTER1.VRM", 0
};
- const char** usedFilelist = 0;
+ const char **usedFilelist = 0;
if (_engine->features() & GF_FLOPPY)
usedFilelist = kyra1Filelist;
@@ -83,7 +83,7 @@ Resource::Resource(KyraEngine* engine) {
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 @@ Resource::~Resource() {
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 @@ bool Resource::isInPakList(const char *filename) {
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 @@ uint8* Resource::fileData(const char* file, uint32* size) {
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 @@ PAKFile::~PAKFile() {
}
}
-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 @@ uint8* PAKFile::getFile(const char* file) {
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))
diff --git a/kyra/resource.h b/kyra/resource.h
index 3355d6c819..1a479c0b73 100644
--- a/kyra/resource.h
+++ b/kyra/resource.h
@@ -43,11 +43,12 @@ class PAKFile {
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 VMContext;
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 {
diff --git a/kyra/sound.cpp b/kyra/sound.cpp
index 68f06d4fa6..48e59a5d15 100644
--- a/kyra/sound.cpp
+++ b/kyra/sound.cpp
@@ -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::beginFadeOut() {
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 @@ void KyraEngine::snd_playVoiceFile(int id) {
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 @@ void KyraEngine::snd_voiceWaitForFinish(bool ingame) {
}
}
+// 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
diff --git a/kyra/sound.h b/kyra/sound.h
index 150ee4c927..7af201cd9f 100644
--- a/kyra/sound.h
+++ b/kyra/sound.h
@@ -141,6 +141,14 @@ protected:
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