From 7ee36a97ee8c43b28c5dd4d8a0d3211698d1dc7f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 31 Dec 2015 14:41:18 +0100 Subject: TONY: As codec is always ADPCM, remove some dead code --- engines/tony/sound.cpp | 16 ++-------------- engines/tony/sound.h | 2 +- engines/tony/tony.cpp | 4 ++-- 3 files changed, 5 insertions(+), 17 deletions(-) (limited to 'engines/tony') diff --git a/engines/tony/sound.cpp b/engines/tony/sound.cpp index 2a4eb826f3..fe4e0ab0e7 100644 --- a/engines/tony/sound.cpp +++ b/engines/tony/sound.cpp @@ -219,11 +219,10 @@ bool FPSfx::loadVoiceFromVDB(Common::File &vdbFP) { * Opens a file and loads a sound effect. * * @param fileName Sfx filename - * @param codec CODEC used to uncompress the samples * * @returns True is everything is OK, False otherwise */ -bool FPSfx::loadFile(const char *fileName, uint32 codec) { +bool FPSfx::loadFile(const char *fileName) { if (!_soundSupported) return true; @@ -242,18 +241,7 @@ bool FPSfx::loadFile(const char *fileName, uint32 codec) { uint32 channels = file.readUint32LE(); Common::SeekableReadStream *buffer = file.readStream(file.size() - file.pos()); - - if (codec == FPCODEC_ADPCM) { - _rewindableStream = Audio::makeADPCMStream(buffer, DisposeAfterUse::YES, 0, Audio::kADPCMDVI, rate, channels); - } else { - byte flags = Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN; - - if (channels == 2) - flags |= Audio::FLAG_STEREO; - - _rewindableStream = Audio::makeRawStream(buffer, rate, flags, DisposeAfterUse::YES); - } - + _rewindableStream = Audio::makeADPCMStream(buffer, DisposeAfterUse::YES, 0, Audio::kADPCMDVI, rate, channels); _fileLoaded = true; return true; } diff --git a/engines/tony/sound.h b/engines/tony/sound.h index 446dc68d80..50ef78ae0d 100644 --- a/engines/tony/sound.h +++ b/engines/tony/sound.h @@ -179,7 +179,7 @@ public: * @returns True is everything is OK, False otherwise */ - bool loadFile(const char *fileName, uint32 codec = FPCODEC_RAW); + bool loadFile(const char *fileName); bool loadWave(Common::SeekableReadStream *stream); bool loadVoiceFromVDB(Common::File &vdbFP); diff --git a/engines/tony/tony.cpp b/engines/tony/tony.cpp index 2857bb93f8..b6ed51a84c 100644 --- a/engines/tony/tony.cpp +++ b/engines/tony/tony.cpp @@ -433,7 +433,7 @@ void TonyEngine::preloadSFX(int nChannel, const char *fn) { _theSound.createSfx(&_sfx[nChannel]); - _sfx[nChannel]->loadFile(fn, FPCODEC_ADPCM); + _sfx[nChannel]->loadFile(fn); } FPSfx *TonyEngine::createSFX(Common::SeekableReadStream *stream) { @@ -453,7 +453,7 @@ void TonyEngine::preloadUtilSFX(int nChannel, const char *fn) { _theSound.createSfx(&_utilSfx[nChannel]); - _utilSfx[nChannel]->loadFile(fn, FPCODEC_ADPCM); + _utilSfx[nChannel]->loadFile(fn); _utilSfx[nChannel]->setVolume(63); } -- cgit v1.2.3 From 88c19138cf18a40e478447c4600d92d63ff0ed50 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 31 Dec 2015 14:48:38 +0100 Subject: TONY: Remove more dead code related to unused raw codec --- engines/tony/sound.cpp | 24 ++++++------------------ engines/tony/sound.h | 3 +-- engines/tony/tony.cpp | 12 ++++++------ 3 files changed, 13 insertions(+), 26 deletions(-) (limited to 'engines/tony') diff --git a/engines/tony/sound.cpp b/engines/tony/sound.cpp index fe4e0ab0e7..88379baf15 100644 --- a/engines/tony/sound.cpp +++ b/engines/tony/sound.cpp @@ -461,7 +461,7 @@ void FPStream::release() { * * @returns True is everything is OK, False otherwise */ -bool FPStream::loadFile(const Common::String &fileName, uint32 codec, int bufSize) { +bool FPStream::loadFile(const Common::String &fileName, int bufSize) { if (!_soundSupported) return true; @@ -469,7 +469,7 @@ bool FPStream::loadFile(const Common::String &fileName, uint32 codec, int bufSiz unloadFile(); // Save the codec type - _codec = codec; + _codec = FPCODEC_ADPCM; // Open the file stream for reading if (!_file.open(fileName)) { @@ -482,25 +482,13 @@ bool FPStream::loadFile(const Common::String &fileName, uint32 codec, int bufSiz // Save the size of the stream _size = _file.size(); - switch (_codec) { - case FPCODEC_RAW: - _rewindableStream = Audio::makeRawStream(&_file, 44100, Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN | Audio::FLAG_STEREO, DisposeAfterUse::NO); - break; - - case FPCODEC_ADPCM: #ifdef __amigaos4__ - // HACK: AmigaOS 4 has weird performance problems with reading in the audio thread, - // so we read the whole stream into memory. - _rewindableStream = Audio::makeADPCMStream(_file.readStream(_size), DisposeAfterUse::YES, 0, Audio::kADPCMDVI, 44100, 2); + // HACK: AmigaOS 4 has weird performance problems with reading in the audio thread, + // so we read the whole stream into memory. + _rewindableStream = Audio::makeADPCMStream(_file.readStream(_size), DisposeAfterUse::YES, 0, Audio::kADPCMDVI, 44100, 2); #else - _rewindableStream = Audio::makeADPCMStream(&_file, DisposeAfterUse::NO, 0, Audio::kADPCMDVI, 44100, 2); + _rewindableStream = Audio::makeADPCMStream(&_file, DisposeAfterUse::NO, 0, Audio::kADPCMDVI, 44100, 2); #endif - break; - - default: - _file.close(); - return false; - } // All done _fileLoaded = true; diff --git a/engines/tony/sound.h b/engines/tony/sound.h index 50ef78ae0d..6aa4ae9496 100644 --- a/engines/tony/sound.h +++ b/engines/tony/sound.h @@ -297,12 +297,11 @@ public: * Opens a file stream * * @param fileName Filename to be opened - * @param codec CODEC to be used to uncompress samples * * @returns True is everything is OK, False otherwise */ - bool loadFile(const Common::String &fileName, uint32 codec = FPCODEC_RAW, int sync = 2000); + bool loadFile(const Common::String &fileName, int sync); /** * Closes a file stream (opened or not). diff --git a/engines/tony/tony.cpp b/engines/tony/tony.cpp index b6ed51a84c..67ffd36d57 100644 --- a/engines/tony/tony.cpp +++ b/engines/tony/tony.cpp @@ -323,10 +323,10 @@ void TonyEngine::playMusic(int nChannel, const Common::String &fname, int nFX, b _stream[GLOBALS._nextChannel]->unloadFile(); if (!getIsDemo()) { - if (!_stream[GLOBALS._nextChannel]->loadFile(fname, FPCODEC_ADPCM, nSync)) + if (!_stream[GLOBALS._nextChannel]->loadFile(fname, nSync)) error("failed to open music file '%s'", fname.c_str()); } else { - _stream[GLOBALS._nextChannel]->loadFile(fname, FPCODEC_ADPCM, nSync); + _stream[GLOBALS._nextChannel]->loadFile(fname, nSync); } _stream[GLOBALS._nextChannel]->setLoop(bLoop); @@ -335,10 +335,10 @@ void TonyEngine::playMusic(int nChannel, const Common::String &fname, int nFX, b GLOBALS._flipflop = 1 - GLOBALS._flipflop; } else { if (!getIsDemo()) { - if (!_stream[nChannel]->loadFile(fname, FPCODEC_ADPCM, nSync)) + if (!_stream[nChannel]->loadFile(fname, nSync)) error("failed to open music file '%s'", fname.c_str()); } else { - _stream[nChannel]->loadFile(fname, FPCODEC_ADPCM, nSync); + _stream[nChannel]->loadFile(fname, nSync); } _stream[nChannel]->setLoop(bLoop); @@ -356,10 +356,10 @@ void TonyEngine::doNextMusic(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); if (!g_vm->getIsDemo()) { - if (!streams[GLOBALS._nextChannel]->loadFile(GLOBALS._nextMusic, FPCODEC_ADPCM, GLOBALS._nextSync)) + if (!streams[GLOBALS._nextChannel]->loadFile(GLOBALS._nextMusic, GLOBALS._nextSync)) error("failed to open next music file '%s'", GLOBALS._nextMusic.c_str()); } else { - streams[GLOBALS._nextChannel]->loadFile(GLOBALS._nextMusic, FPCODEC_ADPCM, GLOBALS._nextSync); + streams[GLOBALS._nextChannel]->loadFile(GLOBALS._nextMusic, GLOBALS._nextSync); } streams[GLOBALS._nextChannel]->setLoop(GLOBALS._nextLoop); -- cgit v1.2.3 From d4e5b72d3163287f592e10379c8a3e0feaa8480e Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 31 Dec 2015 14:56:05 +0100 Subject: TONY: Simplify some code related to LOX in RMItem::readFromStream() --- engines/tony/loc.cpp | 25 ++++++++----------------- engines/tony/loc.h | 2 +- 2 files changed, 9 insertions(+), 18 deletions(-) (limited to 'engines/tony') diff --git a/engines/tony/loc.cpp b/engines/tony/loc.cpp index 09a00deed1..e505aa46a5 100644 --- a/engines/tony/loc.cpp +++ b/engines/tony/loc.cpp @@ -506,15 +506,13 @@ void RMItem::readFromStream(Common::SeekableReadStream &ds, bool bLOX) { if (!ds.err()) { for (int i = 0; i < _nSprites && !ds.err(); i++) { // Download the sprites - if (bLOX) { + if (bLOX) _sprites[i].LOXGetSizeFromStream(ds, &dimx, &dimy); - _sprites[i].init(newItemSpriteBuffer(dimx, dimy, true)); - _sprites[i].readFromStream(ds, true); - } else { + else _sprites[i].getSizeFromStream(ds, &dimx, &dimy); - _sprites[i].init(newItemSpriteBuffer(dimx, dimy, false)); - _sprites[i].readFromStream(ds, false); - } + + _sprites[i].init(newItemSpriteBuffer(dimx, dimy, bLOX)); + _sprites[i].readFromStream(ds, bLOX); if (_cm == CM_256 && _bPal) _sprites[i].setPalette(_pal._data); @@ -523,21 +521,14 @@ void RMItem::readFromStream(Common::SeekableReadStream &ds, bool bLOX) { if (!ds.err()) { for (int i = 0; i < _nSfx && !ds.err(); i++) { - if (bLOX) - _sfx[i].readFromStream(ds, true); - else - _sfx[i].readFromStream(ds, false); + _sfx[i].readFromStream(ds, bLOX); } } // Read the pattern from pattern 1 if (!ds.err()) { - for (int i = 1; i <= _nPatterns && !ds.err(); i++) { - if (bLOX) - _patterns[i].readFromStream(ds, true); - else - _patterns[i].readFromStream(ds, false); - } + for (int i = 1; i <= _nPatterns && !ds.err(); i++) + _patterns[i].readFromStream(ds, bLOX); } // Initialize the current pattern diff --git a/engines/tony/loc.h b/engines/tony/loc.h index ac65a4a0bd..d065d60445 100644 --- a/engines/tony/loc.h +++ b/engines/tony/loc.h @@ -151,7 +151,7 @@ public: // Reads the position of the pattern RMPoint pos(); - void readFromStream(Common::ReadStream &ds, bool bLOX = false); + void readFromStream(Common::ReadStream &ds, bool bLOX); private: void updateCoord(); -- cgit v1.2.3 From 131d2f73e0781c5fd578968fa377a24b3a5f7b2a Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 1 Jan 2016 04:23:20 +0100 Subject: TONY: Fix typo in comment --- engines/tony/loc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/tony') diff --git a/engines/tony/loc.cpp b/engines/tony/loc.cpp index e505aa46a5..be2b20294f 100644 --- a/engines/tony/loc.cpp +++ b/engines/tony/loc.cpp @@ -601,7 +601,7 @@ void RMItem::draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) { // Offset direction for scrolling prim->getDst().offset(-_curScroll); - // We must offset the cordinates of the item inside the primitive + // We must offset the coordinates of the item inside the primitive // It is estimated as nonno + (babbo + figlio) prim->getDst().offset(calculatePos()); -- cgit v1.2.3 From 92f3a9f4824c89e4f300d561f1d48ac6f02e0b00 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 1 Jan 2016 04:24:17 +0100 Subject: TONY: Remove an unused variable --- engines/tony/sound.cpp | 3 --- engines/tony/sound.h | 1 - 2 files changed, 4 deletions(-) (limited to 'engines/tony') diff --git a/engines/tony/sound.cpp b/engines/tony/sound.cpp index 88379baf15..faf91c1fc5 100644 --- a/engines/tony/sound.cpp +++ b/engines/tony/sound.cpp @@ -468,9 +468,6 @@ bool FPStream::loadFile(const Common::String &fileName, int bufSize) { if (_fileLoaded) unloadFile(); - // Save the codec type - _codec = FPCODEC_ADPCM; - // Open the file stream for reading if (!_file.open(fileName)) { // Fallback: try with an extra '0' prefix diff --git a/engines/tony/sound.h b/engines/tony/sound.h index 6aa4ae9496..2ea1162d98 100644 --- a/engines/tony/sound.h +++ b/engines/tony/sound.h @@ -246,7 +246,6 @@ class FPStream { private: uint32 _bufferSize; // Buffer size (bytes) uint32 _size; // Stream size (bytes) - uint32 _codec; // CODEC used Common::File _file; // File handle used for the stream -- cgit v1.2.3 From 35f08ca0fbcead4f18b65baba35f83c3e9f2a914 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 3 Jan 2016 00:16:52 +0100 Subject: TONY: Add support for compressed music and sfx --- engines/tony/sound.cpp | 140 +++++++++++++++++++++++++++++++++++++++++++------ engines/tony/sound.h | 7 ++- 2 files changed, 128 insertions(+), 19 deletions(-) (limited to 'engines/tony') diff --git a/engines/tony/sound.cpp b/engines/tony/sound.cpp index faf91c1fc5..2fc0afa71f 100644 --- a/engines/tony/sound.cpp +++ b/engines/tony/sound.cpp @@ -28,7 +28,9 @@ #include "audio/audiostream.h" #include "audio/decoders/adpcm.h" -#include "audio/decoders/raw.h" +#include "audio/decoders/flac.h" +#include "audio/decoders/mp3.h" +#include "audio/decoders/vorbis.h" #include "audio/decoders/wave.h" #include "common/textconsole.h" #include "tony/game.h" @@ -49,6 +51,18 @@ static int remapVolume(int volume) { return (int)((double)Audio::Mixer::kMaxChannelVolume * pow(10.0, dsvol / 2000.0) + 0.5); } +// Another obvious rip from gob engine. Hi DrMcCoy! +Common::String setExtension(const Common::String &str, const Common::String &ext) { + if (str.empty()) + return str; + + const char *dot = strrchr(str.c_str(), '.'); + if (dot) + return Common::String(str.c_str(), dot - str.c_str()) + ext; + + return str + ext; +} + /****************************************************************************\ * FPSOUND Methods \****************************************************************************/ @@ -226,22 +240,59 @@ bool FPSfx::loadFile(const char *fileName) { if (!_soundSupported) return true; + SoundCodecs codec = FPCODEC_UNKNOWN; + Common::File file; - if (!file.open(fileName)) { + if (file.open(fileName)) + codec = FPCODEC_ADPCM; + else if (file.open(setExtension(fileName, ".MP3"))) + codec = FPCODEC_MP3; + else if (file.open(setExtension(fileName, ".OGG"))) + codec = FPCODEC_OGG; + else if (file.open(setExtension(fileName, ".FLA"))) + codec = FPCODEC_FLAC; + else { warning("FPSfx::LoadFile(): Cannot open sfx file!"); return false; } - if (file.readUint32BE() != MKTAG('A', 'D', 'P', 0x10)) { - warning("FPSfx::LoadFile(): Invalid ADP header!"); + Common::SeekableReadStream *buffer; + switch (codec) { + case FPCODEC_ADPCM: { + if (file.readUint32BE() != MKTAG('A', 'D', 'P', 0x10)) { + warning("FPSfx::LoadFile(): Invalid ADP header!"); + return false; + } + + uint32 rate = file.readUint32LE(); + uint32 channels = file.readUint32LE(); + + buffer = file.readStream(file.size() - file.pos()); + _rewindableStream = Audio::makeADPCMStream(buffer, DisposeAfterUse::YES, 0, Audio::kADPCMDVI, rate, channels); + } + break; + case FPCODEC_MP3: +#ifdef USE_MAD + buffer = file.readStream(file.size()); + _rewindableStream = Audio::makeMP3Stream(buffer, DisposeAfterUse::YES); +#endif + break; + case FPCODEC_OGG: +#ifdef USE_VORBIS + buffer = file.readStream(file.size()); + _rewindableStream = Audio::makeVorbisStream(buffer, DisposeAfterUse::YES); +#endif + break; + case FPCODEC_FLAC: + buffer = file.readStream(file.size()); +#ifdef USE_FLAC + _rewindableStream = Audio::makeFLACStream(buffer, DisposeAfterUse::YES); +#endif + break; + default: return false; } - uint32 rate = file.readUint32LE(); - uint32 channels = file.readUint32LE(); - - Common::SeekableReadStream *buffer = file.readStream(file.size() - file.pos()); - _rewindableStream = Audio::makeADPCMStream(buffer, DisposeAfterUse::YES, 0, Audio::kADPCMDVI, rate, channels); _fileLoaded = true; return true; } @@ -457,7 +508,7 @@ void FPStream::release() { * Opens a file stream * * @param fileName Filename to be opened - * @param codec CODEC to be used to uncompress samples + * @param bufSize Buffer size * * @returns True is everything is OK, False otherwise */ @@ -468,13 +519,32 @@ bool FPStream::loadFile(const Common::String &fileName, int bufSize) { if (_fileLoaded) unloadFile(); + SoundCodecs codec = FPCODEC_UNKNOWN; + // Open the file stream for reading - if (!_file.open(fileName)) { - // Fallback: try with an extra '0' prefix - if (!_file.open("0" + fileName)) - return false; + if (_file.open(fileName)) + codec = FPCODEC_ADPCM; + else if (_file.open(setExtension(fileName, ".MP3"))) + codec = FPCODEC_MP3; + else if (_file.open(setExtension(fileName, ".OGG"))) + codec = FPCODEC_OGG; + else if (_file.open(setExtension(fileName, ".FLA"))) + codec = FPCODEC_FLAC; + // Fallback: try with an extra '0' prefix + else if (_file.open("0" + fileName)) { + codec = FPCODEC_ADPCM; warning("FPStream::loadFile(): Fallback from %s to %s", fileName.c_str(), _file.getName()); - } + } else if (_file.open(setExtension("0" + fileName, ".MP3"))) { + codec = FPCODEC_MP3; + warning("FPStream::loadFile(): Fallback from %s to %s", fileName.c_str(), _file.getName()); + } else if (_file.open(setExtension("0" + fileName, ".OGG"))) { + codec = FPCODEC_OGG; + warning("FPStream::loadFile(): Fallback from %s to %s", fileName.c_str(), _file.getName()); + } else if (_file.open(setExtension("0" + fileName, ".FLA"))) { + codec = FPCODEC_FLAC; + warning("FPStream::loadFile(): Fallback from %s to %s", fileName.c_str(), _file.getName()); + } else + return false; // Save the size of the stream _size = _file.size(); @@ -482,9 +552,45 @@ bool FPStream::loadFile(const Common::String &fileName, int bufSize) { #ifdef __amigaos4__ // HACK: AmigaOS 4 has weird performance problems with reading in the audio thread, // so we read the whole stream into memory. - _rewindableStream = Audio::makeADPCMStream(_file.readStream(_size), DisposeAfterUse::YES, 0, Audio::kADPCMDVI, 44100, 2); + switch (codec) { + case FPCODEC_ADPCM: + _rewindableStream = Audio::makeADPCMStream(_file.readStream(_size), DisposeAfterUse::YES, 0, Audio::kADPCMDVI, 44100, 2); + break; + case FPCODEC_MP3: + _rewindableStream = Audio::makeMP3Stream(&_file, DisposeAfterUse::YES); + break; + case FPCODEC_OGG: + _rewindableStream = Audio::makeVorbisStream(&_file, DisposeAfterUse::YES); + break; + case FPCODEC_FLAC: + _rewindableStream = Audio::makeFLACStream(&_file, DisposeAfterUse::YES); + break; + default: + break; + } #else - _rewindableStream = Audio::makeADPCMStream(&_file, DisposeAfterUse::NO, 0, Audio::kADPCMDVI, 44100, 2); + switch (codec) { + case FPCODEC_ADPCM: + _rewindableStream = Audio::makeADPCMStream(&_file, DisposeAfterUse::NO, 0, Audio::kADPCMDVI, 44100, 2); + break; + case FPCODEC_MP3: +#ifdef USE_MAD + _rewindableStream = Audio::makeMP3Stream(&_file, DisposeAfterUse::NO); +#endif + break; + case FPCODEC_OGG: +#ifdef USE_VORBIS + _rewindableStream = Audio::makeVorbisStream(&_file, DisposeAfterUse::NO); +#endif + break; + case FPCODEC_FLAC: +#ifdef USE_FLAC + _rewindableStream = Audio::makeFLACStream(&_file, DisposeAfterUse::NO); +#endif + break; + default: + break; + } #endif // All done diff --git a/engines/tony/sound.h b/engines/tony/sound.h index 2ea1162d98..206935f314 100644 --- a/engines/tony/sound.h +++ b/engines/tony/sound.h @@ -45,8 +45,11 @@ class FPStream; class FPSfx; enum SoundCodecs { - FPCODEC_RAW, - FPCODEC_ADPCM + FPCODEC_UNKNOWN, + FPCODEC_ADPCM, + FPCODEC_MP3, + FPCODEC_OGG, + FPCODEC_FLAC }; /** -- cgit v1.2.3 From 35e526d34b4306739938a80c329a24b294a1860d Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 3 Jan 2016 00:51:56 +0100 Subject: TONY: Fix Amiga Build by adding missing sound ifdefs --- engines/tony/sound.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'engines/tony') diff --git a/engines/tony/sound.cpp b/engines/tony/sound.cpp index 2fc0afa71f..73205655b0 100644 --- a/engines/tony/sound.cpp +++ b/engines/tony/sound.cpp @@ -557,13 +557,19 @@ bool FPStream::loadFile(const Common::String &fileName, int bufSize) { _rewindableStream = Audio::makeADPCMStream(_file.readStream(_size), DisposeAfterUse::YES, 0, Audio::kADPCMDVI, 44100, 2); break; case FPCODEC_MP3: +#ifdef USE_MAD _rewindableStream = Audio::makeMP3Stream(&_file, DisposeAfterUse::YES); +#endif break; case FPCODEC_OGG: +#ifdef USE_VORBIS _rewindableStream = Audio::makeVorbisStream(&_file, DisposeAfterUse::YES); +#endif break; case FPCODEC_FLAC: +#ifdef USE_FLAC _rewindableStream = Audio::makeFLACStream(&_file, DisposeAfterUse::YES); +#endif break; default: break; -- cgit v1.2.3 From e6d8655a9b37af313840cca05b0e3493624ca575 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 4 Jan 2016 13:43:36 +0100 Subject: TONY: Add support to the new compressed speech containers --- engines/tony/sound.cpp | 43 ++++++++++++++++++++++++++++++++++++++----- engines/tony/tony.cpp | 39 +++++++++++++++++++++++++++++++++++---- engines/tony/tony.h | 1 + 3 files changed, 74 insertions(+), 9 deletions(-) (limited to 'engines/tony') diff --git a/engines/tony/sound.cpp b/engines/tony/sound.cpp index 73205655b0..aa86750ad5 100644 --- a/engines/tony/sound.cpp +++ b/engines/tony/sound.cpp @@ -218,12 +218,45 @@ bool FPSfx::loadVoiceFromVDB(Common::File &vdbFP) { if (!_soundSupported) return true; - uint32 size = vdbFP.readUint32LE(); - uint32 rate = vdbFP.readUint32LE(); - _isVoice = true; - - _rewindableStream = Audio::makeADPCMStream(vdbFP.readStream(size), DisposeAfterUse::YES, 0, Audio::kADPCMDVI, rate, 1); + switch (g_vm->_vdbCodec) { + case FPCODEC_ADPCM: { + uint32 size = vdbFP.readUint32LE(); + uint32 rate = vdbFP.readUint32LE(); + _rewindableStream = Audio::makeADPCMStream(vdbFP.readStream(size), DisposeAfterUse::YES, 0, Audio::kADPCMDVI, rate, 1); + } + break; + case FPCODEC_MP3 : { +#ifdef USE_MAD + uint32 size = vdbFP.readUint32LE(); + _rewindableStream = Audio::makeMP3Stream(vdbFP.readStream(size), DisposeAfterUse::YES); +#else + return false; +#endif + } + break; + case FPCODEC_OGG : { +#ifdef USE_VORBIS + uint32 size = vdbFP.readUint32LE(); + _rewindableStream = Audio::makeVorbisStream(vdbFP.readStream(size), DisposeAfterUse::YES); +#else + return false; +#endif + } + break; + case FPCODEC_FLAC : { +#ifdef USE_FLAC + uint32 size = vdbFP.readUint32LE(); + _rewindableStream = Audio::makeFLACStream(vdbFP.readStream(size), DisposeAfterUse::YES); +#else + return false; +#endif + } + break; + default: + return false; + } + _isVoice = true; _fileLoaded = true; setVolume(62); return true; diff --git a/engines/tony/tony.cpp b/engines/tony/tony.cpp index 67ffd36d57..6308cf6396 100644 --- a/engines/tony/tony.cpp +++ b/engines/tony/tony.cpp @@ -577,18 +577,49 @@ bool TonyEngine::openVoiceDatabase() { uint32 numfiles; // Open the voices database - if (!_vdbFP.open("voices.vdb")) + if (_vdbFP.open("voices.vdb")) + _vdbCodec = FPCODEC_ADPCM; + else if (_vdbFP.open("voices.mdb")) + _vdbCodec = FPCODEC_MP3; + else if (_vdbFP.open("voices.odb")) + _vdbCodec = FPCODEC_OGG; + else if (_vdbFP.open("voices.fdb")) + _vdbCodec = FPCODEC_FLAC; + else return false; _vdbFP.seek(-8, SEEK_END); numfiles = _vdbFP.readUint32LE(); _vdbFP.read(id, 4); - if (id[0] != 'V' || id[1] != 'D' || id[2] != 'B' || id[3] != '1') { - _vdbFP.close(); + switch (_vdbCodec) { + case FPCODEC_ADPCM: + if (id[0] != 'V' || id[1] != 'D' || id[2] != 'B' || id[3] != '1') { + _vdbFP.close(); + return false; + } + break; + case FPCODEC_MP3: + if (id[0] != 'M' || id[1] != 'D' || id[2] != 'B' || id[3] != '1') { + _vdbFP.close(); + return false; + } + break; + case FPCODEC_OGG: + if (id[0] != 'O' || id[1] != 'D' || id[2] != 'B' || id[3] != '1') { + _vdbFP.close(); + return false; + } + break; + case FPCODEC_FLAC: + if (id[0] != 'F' || id[1] != 'D' || id[2] != 'B' || id[3] != '1') { + _vdbFP.close(); + return false; + } + break; + default: return false; } - // Read in the index _vdbFP.seek(-8 - (numfiles * VOICE_HEADER_SIZE), SEEK_END); diff --git a/engines/tony/tony.h b/engines/tony/tony.h index 40a5184c31..40bace8db8 100644 --- a/engines/tony/tony.h +++ b/engines/tony/tony.h @@ -104,6 +104,7 @@ public: RMResUpdate _resUpdate; uint32 _hEndOfFrame; Common::File _vdbFP; + SoundCodecs _vdbCodec; Common::Array _voices; FPSound _theSound; Common::List _activeSfx; -- cgit v1.2.3 From 94809c4995ccd7a765ce86efdf24f2d3af175d4f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 4 Jan 2016 13:53:11 +0100 Subject: TONY: Reduce variable scope, use MKTAG to check file signature --- engines/tony/tony.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'engines/tony') diff --git a/engines/tony/tony.cpp b/engines/tony/tony.cpp index 6308cf6396..08e30cd409 100644 --- a/engines/tony/tony.cpp +++ b/engines/tony/tony.cpp @@ -573,9 +573,6 @@ void TonyEngine::loadState(CORO_PARAM, int n) { } bool TonyEngine::openVoiceDatabase() { - char id[4]; - uint32 numfiles; - // Open the voices database if (_vdbFP.open("voices.vdb")) _vdbCodec = FPCODEC_ADPCM; @@ -589,30 +586,29 @@ bool TonyEngine::openVoiceDatabase() { return false; _vdbFP.seek(-8, SEEK_END); - numfiles = _vdbFP.readUint32LE(); - _vdbFP.read(id, 4); + uint32 numfiles = _vdbFP.readUint32LE(); switch (_vdbCodec) { case FPCODEC_ADPCM: - if (id[0] != 'V' || id[1] != 'D' || id[2] != 'B' || id[3] != '1') { + if (_vdbFP.readUint32BE() != MKTAG('V', 'D', 'B', '1')) { _vdbFP.close(); return false; } break; case FPCODEC_MP3: - if (id[0] != 'M' || id[1] != 'D' || id[2] != 'B' || id[3] != '1') { + if (_vdbFP.readUint32BE() != MKTAG('M', 'D', 'B', '1')) { _vdbFP.close(); return false; } break; case FPCODEC_OGG: - if (id[0] != 'O' || id[1] != 'D' || id[2] != 'B' || id[3] != '1') { + if (_vdbFP.readUint32BE() != MKTAG('O', 'D', 'B', '1')) { _vdbFP.close(); return false; } break; case FPCODEC_FLAC: - if (id[0] != 'F' || id[1] != 'D' || id[2] != 'B' || id[3] != '1') { + if (_vdbFP.readUint32BE() != MKTAG('F', 'D', 'B', '1')) { _vdbFP.close(); return false; } -- cgit v1.2.3 From 1084fc023ccd94bec579db27115cc874b653cc24 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 4 Jan 2016 14:07:56 +0100 Subject: TONY: As suggested by LordHoto, determine codec based on container signature instead of filename --- engines/tony/tony.cpp | 53 +++++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 36 deletions(-) (limited to 'engines/tony') diff --git a/engines/tony/tony.cpp b/engines/tony/tony.cpp index 08e30cd409..47fd2e3ce3 100644 --- a/engines/tony/tony.cpp +++ b/engines/tony/tony.cpp @@ -574,48 +574,29 @@ void TonyEngine::loadState(CORO_PARAM, int n) { bool TonyEngine::openVoiceDatabase() { // Open the voices database - if (_vdbFP.open("voices.vdb")) - _vdbCodec = FPCODEC_ADPCM; - else if (_vdbFP.open("voices.mdb")) - _vdbCodec = FPCODEC_MP3; - else if (_vdbFP.open("voices.odb")) - _vdbCodec = FPCODEC_OGG; - else if (_vdbFP.open("voices.fdb")) - _vdbCodec = FPCODEC_FLAC; - else - return false; + if (!_vdbFP.open("voices.vdb")) + if (!_vdbFP.open("voices.mdb")) + if (!_vdbFP.open("voices.odb")) + if (!_vdbFP.open("voices.fdb")) + return false; _vdbFP.seek(-8, SEEK_END); uint32 numfiles = _vdbFP.readUint32LE(); + int32 id = _vdbFP.readUint32BE(); - switch (_vdbCodec) { - case FPCODEC_ADPCM: - if (_vdbFP.readUint32BE() != MKTAG('V', 'D', 'B', '1')) { - _vdbFP.close(); - return false; - } - break; - case FPCODEC_MP3: - if (_vdbFP.readUint32BE() != MKTAG('M', 'D', 'B', '1')) { - _vdbFP.close(); - return false; - } - break; - case FPCODEC_OGG: - if (_vdbFP.readUint32BE() != MKTAG('O', 'D', 'B', '1')) { - _vdbFP.close(); - return false; - } - break; - case FPCODEC_FLAC: - if (_vdbFP.readUint32BE() != MKTAG('F', 'D', 'B', '1')) { - _vdbFP.close(); - return false; - } - break; - default: + if (id == MKTAG('V', 'D', 'B', '1')) + _vdbCodec = FPCODEC_ADPCM; + else if (id == MKTAG('M', 'D', 'B', '1')) + _vdbCodec = FPCODEC_MP3; + else if (id == MKTAG('O', 'D', 'B', '1')) + _vdbCodec = FPCODEC_OGG; + else if (id == MKTAG('F', 'D', 'B', '1')) + _vdbCodec = FPCODEC_FLAC; + else { + _vdbFP.close(); return false; } + // Read in the index _vdbFP.seek(-8 - (numfiles * VOICE_HEADER_SIZE), SEEK_END); -- cgit v1.2.3 From d919c66e996647333b1ee66d0eb5522cb8491009 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 4 Jan 2016 14:10:24 +0100 Subject: TONY: Initialize _vdbCodec in contructor --- engines/tony/tony.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/tony') diff --git a/engines/tony/tony.cpp b/engines/tony/tony.cpp index 47fd2e3ce3..d8fa45cb5d 100644 --- a/engines/tony/tony.cpp +++ b/engines/tony/tony.cpp @@ -82,6 +82,7 @@ TonyEngine::TonyEngine(OSystem *syst, const TonyGameDescription *gameDesc) : Eng _bQuitNow = false; _bTimeFreezed = false; _nTimeFreezed = 0; + _vdbCodec = FPCODEC_UNKNOWN; } TonyEngine::~TonyEngine() { -- cgit v1.2.3