diff options
author | Strangerke | 2016-01-03 00:16:52 +0100 |
---|---|---|
committer | Strangerke | 2016-01-03 00:17:43 +0100 |
commit | 35f08ca0fbcead4f18b65baba35f83c3e9f2a914 (patch) | |
tree | 55f4c04286a7b1fc56a17fab049fc521e65b0902 | |
parent | 30b554d69407abe82ba92bc956b4b82dd81f8e33 (diff) | |
download | scummvm-rg350-35f08ca0fbcead4f18b65baba35f83c3e9f2a914.tar.gz scummvm-rg350-35f08ca0fbcead4f18b65baba35f83c3e9f2a914.tar.bz2 scummvm-rg350-35f08ca0fbcead4f18b65baba35f83c3e9f2a914.zip |
TONY: Add support for compressed music and sfx
-rw-r--r-- | engines/tony/sound.cpp | 140 | ||||
-rw-r--r-- | engines/tony/sound.h | 7 |
2 files changed, 128 insertions, 19 deletions
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 }; /** |