diff options
author | Paul Gilbert | 2012-12-02 17:16:00 +1100 |
---|---|---|
committer | Paul Gilbert | 2012-12-02 17:16:00 +1100 |
commit | 5cd2633b3bf4ce80517afc9de618278e4f004d85 (patch) | |
tree | aff48a60f3b6df834ababda7a18c46b7fe29cf56 | |
parent | d45b22f822187c2e23c9645986862c2edde2016b (diff) | |
download | scummvm-rg350-5cd2633b3bf4ce80517afc9de618278e4f004d85.tar.gz scummvm-rg350-5cd2633b3bf4ce80517afc9de618278e4f004d85.tar.bz2 scummvm-rg350-5cd2633b3bf4ce80517afc9de618278e4f004d85.zip |
HOPKINS: Initial implementation of new codec for Windows APC sound files
-rw-r--r-- | engines/hopkins/sound.cpp | 52 | ||||
-rw-r--r-- | engines/hopkins/sound.h | 4 |
2 files changed, 53 insertions, 3 deletions
diff --git a/engines/hopkins/sound.cpp b/engines/hopkins/sound.cpp index da3a3de747..6f9f17a937 100644 --- a/engines/hopkins/sound.cpp +++ b/engines/hopkins/sound.cpp @@ -20,6 +20,7 @@ * */ +#include "audio/decoders/adpcm_intern.h" #include "common/system.h" #include "common/config-manager.h" #include "common/file.h" @@ -28,6 +29,45 @@ #include "hopkins/globals.h" #include "hopkins/hopkins.h" +namespace Audio { + +class APC_ADPCMStream : public Audio::DVI_ADPCMStream { +public: + APC_ADPCMStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse, int rate, int channels) : DVI_ADPCMStream(stream, disposeAfterUse, stream->size(), rate, channels, 0) { + stream->seek(-12, SEEK_CUR); + _status.ima_ch[0].last = _startValue[0] = stream->readUint32LE(); + _status.ima_ch[1].last = _startValue[1] = stream->readUint32LE(); + stream->seek(4, SEEK_CUR); + } + + void reset() { + DVI_ADPCMStream::reset(); + _status.ima_ch[0].last = _startValue[0]; + _status.ima_ch[1].last = _startValue[1]; + } + +private: + int16 _startValue[2]; +}; + +Audio::RewindableAudioStream *makeAPCStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse) { + if (stream->readUint32BE() != MKTAG('C', 'R', 'Y', 'O')) + return 0; + if (stream->readUint32BE() != MKTAG('_', 'A', 'P', 'C')) + return 0; + stream->readUint32BE(); // version + stream->readUint32LE(); // out size + uint32 rate = stream->readUint32LE(); + stream->skip(8); // initial values, will be handled by the class + bool stereo = stream->readUint32LE() != 0; + + return new APC_ADPCMStream(stream, disposeAfterUse, rate, stereo ? 2 : 1); +} + +} + +/*------------------------------------------------------------------------*/ + namespace Hopkins { SoundManager::SoundManager() { @@ -388,7 +428,7 @@ void SoundManager::LOAD_MSAMPLE(int mwavIndex, const Common::String &file) { if (!f.open(file)) error("Could not open %s for reading", file.c_str()); - Mwav[mwavIndex]._audioStream = Audio::makeWAVStream(f.readStream(f.size()), DisposeAfterUse::YES); + Mwav[mwavIndex]._audioStream = makeSoundStream(f.readStream(f.size())); Mwav[mwavIndex]._active = true; f.close(); @@ -685,8 +725,7 @@ bool SoundManager::SDL_LoadVoice(const Common::String &filename, size_t fileOffs error("Could not open %s for reading", filename.c_str()); f.seek(fileOffset); - item._audioStream = Audio::makeWAVStream(f.readStream((entryLength == 0) ? f.size() : entryLength), - DisposeAfterUse::YES); + item._audioStream = makeSoundStream(f.readStream((entryLength == 0) ? f.size() : entryLength)); f.close(); return true; @@ -789,4 +828,11 @@ void SoundManager::updateScummVMSoundSettings() { ConfMan.flushToDisk(); } +Audio::RewindableAudioStream *SoundManager::makeSoundStream(Common::SeekableReadStream *stream) { + if (_vm->getPlatform() == Common::kPlatformWindows) + return Audio::makeAPCStream(stream, DisposeAfterUse::YES); + else + return Audio::makeWAVStream(stream, DisposeAfterUse::YES); +} + } // End of namespace Hopkins diff --git a/engines/hopkins/sound.h b/engines/hopkins/sound.h index fa0a5419a2..75cb29789c 100644 --- a/engines/hopkins/sound.h +++ b/engines/hopkins/sound.h @@ -107,6 +107,10 @@ private: */ void checkVoices(); + /** + * Creates an audio stream based on a passed raw stream + */ + Audio::RewindableAudioStream *makeSoundStream(Common::SeekableReadStream *stream); public: int SPECIAL_SOUND; int SOUNDVOL; |