diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/tucker/resource.cpp | 93 | ||||
-rw-r--r-- | engines/tucker/sequences.cpp | 25 | ||||
-rw-r--r-- | engines/tucker/tucker.cpp | 5 | ||||
-rw-r--r-- | engines/tucker/tucker.h | 33 |
4 files changed, 102 insertions, 54 deletions
diff --git a/engines/tucker/resource.cpp b/engines/tucker/resource.cpp index 9b8304e9fd..8b08613ac7 100644 --- a/engines/tucker/resource.cpp +++ b/engines/tucker/resource.cpp @@ -211,13 +211,14 @@ uint8 *TuckerEngine::loadFile(const char *fname, uint8 *p) { return p; } -void TuckerEngine::openCompressedSoundFile() { +void CompressedSound::openFile() { _compressedSoundType = -1; for (int i = 0; compressedSoundFilesTable[i].filename; ++i) { if (_fCompressedSound.open(compressedSoundFilesTable[i].filename)) { int version = _fCompressedSound.readUint16LE(); if (version == kCurrentCompressedSoundDataVersion) { _compressedSoundType = i; + _compressedSoundFlags = _fCompressedSound.readUint16LE(); debug(1, "Using compressed sound file '%s'", compressedSoundFilesTable[i].filename); return; } @@ -226,10 +227,52 @@ void TuckerEngine::openCompressedSoundFile() { } } -void TuckerEngine::closeCompressedSoundFile() { +void CompressedSound::closeFile() { _fCompressedSound.close(); } +Audio::AudioStream *CompressedSound::load(CompressedSoundType type, int num, bool loop) { + if (_compressedSoundType < 0) { + return 0; + } + int offset = 0; + switch (type) { + case kSoundTypeFx: + offset = kCompressedSoundDataFileHeaderSize; + break; + case kSoundTypeMusic: + offset = kCompressedSoundDataFileHeaderSize + 8; + break; + case kSoundTypeSpeech: + offset = kCompressedSoundDataFileHeaderSize + 16; + break; + case kSoundTypeIntro: + if (_compressedSoundFlags & 1) { + offset = kCompressedSoundDataFileHeaderSize + 24; + } + break; + } + Audio::AudioStream *stream = 0; + _fCompressedSound.seek(offset); + int dirOffset = _fCompressedSound.readUint32LE(); + int dirSize = _fCompressedSound.readUint32LE(); + if (num < dirSize) { + const int dirHeaderSize = (_compressedSoundFlags & 1) ? 4 * 8 : 3 * 8; + dirOffset += kCompressedSoundDataFileHeaderSize + dirHeaderSize; + _fCompressedSound.seek(dirOffset + num * 8); + int soundOffset = _fCompressedSound.readUint32LE(); + int soundSize = _fCompressedSound.readUint32LE(); + if (soundSize != 0) { + _fCompressedSound.seek(dirOffset + dirSize * 8 + soundOffset); + Common::MemoryReadStream *tmp = _fCompressedSound.readStream(soundSize); + if (tmp) { + stream = (compressedSoundFilesTable[_compressedSoundType].makeStream)(tmp, true, 0, 0, loop ? 0 : 1); + } + } + } + return stream; +} + void TuckerEngine::loadImage(const char *fname, uint8 *dst, int type) { char filename[80]; strcpy(filename, fname); @@ -866,7 +909,20 @@ void TuckerEngine::loadFx() { void TuckerEngine::loadSound(Audio::Mixer::SoundType type, int num, int volume, bool loop, Audio::SoundHandle *handle) { Audio::AudioStream *stream = 0; - if (_compressedSoundType < 0) { + switch (type) { + case Audio::Mixer::kSFXSoundType: + stream = _compressedSound.load(kSoundTypeFx, num, loop); + break; + case Audio::Mixer::kMusicSoundType: + stream = _compressedSound.load(kSoundTypeMusic, num, loop); + break; + case Audio::Mixer::kSpeechSoundType: + stream = _compressedSound.load(kSoundTypeSpeech, num, loop); + break; + default: + return; + } + if (!stream) { const char *fmt = 0; switch (type) { case Audio::Mixer::kSFXSoundType: @@ -899,37 +955,6 @@ void TuckerEngine::loadSound(Audio::Mixer::SoundType type, int num, int volume, } } } - } else { - int offset = 0; - switch (type) { - case Audio::Mixer::kSFXSoundType: - offset = kCompressedSoundDataFileHeaderSize; - break; - case Audio::Mixer::kMusicSoundType: - offset = kCompressedSoundDataFileHeaderSize + 8; - break; - case Audio::Mixer::kSpeechSoundType: - offset = kCompressedSoundDataFileHeaderSize + 16; - break; - default: - return; - } - _fCompressedSound.seek(offset); - int dirOffset = _fCompressedSound.readUint32LE(); - int dirSize = _fCompressedSound.readUint32LE(); - if (num < dirSize) { - dirOffset += kCompressedSoundDataFileHeaderSize + 3 * 8; - _fCompressedSound.seek(dirOffset + num * 8); - int soundOffset = _fCompressedSound.readUint32LE(); - int soundSize = _fCompressedSound.readUint32LE(); - if (soundSize != 0) { - _fCompressedSound.seek(dirOffset + dirSize * 8 + soundOffset); - Common::MemoryReadStream *tmp = _fCompressedSound.readStream(soundSize); - if (tmp) { - stream = (compressedSoundFilesTable[_compressedSoundType].makeStream)(tmp, true, 0, 0, loop ? 0 : 1); - } - } - } } if (stream) { _mixer->stopHandle(*handle); diff --git a/engines/tucker/sequences.cpp b/engines/tucker/sequences.cpp index 8041b95414..e8280c3038 100644 --- a/engines/tucker/sequences.cpp +++ b/engines/tucker/sequences.cpp @@ -35,7 +35,7 @@ namespace Tucker { void TuckerEngine::handleIntroSequence() { const int firstSequence = (_gameFlags & kGameFlagDemo) != 0 ? kFirstAnimationSequenceDemo : kFirstAnimationSequenceGame; - _player = new AnimationSequencePlayer(_system, _mixer, _eventMan, firstSequence); + _player = new AnimationSequencePlayer(_system, _mixer, _eventMan, &_compressedSound, firstSequence); _player->mainLoop(); delete _player; _player = 0; @@ -492,8 +492,8 @@ int TuckerEngine::handleSpecialObjectSelectionSequence() { return 1; } -AnimationSequencePlayer::AnimationSequencePlayer(OSystem *system, Audio::Mixer *mixer, Common::EventManager *event, int num) - : _system(system), _mixer(mixer), _event(event), _seqNum(num) { +AnimationSequencePlayer::AnimationSequencePlayer(OSystem *system, Audio::Mixer *mixer, Common::EventManager *event, CompressedSound *sound, int num) + : _system(system), _mixer(mixer), _event(event), _compressedSound(sound), _seqNum(num) { memset(_animationPalette, 0, sizeof(_animationPalette)); _soundSeqDataCount = 0; _soundSeqDataIndex = 0; @@ -585,8 +585,11 @@ void AnimationSequencePlayer::syncTime() { } while (_lastFrameTime <= end); } -Audio::AudioStream *AnimationSequencePlayer::loadSoundFileAsStream(int index, AnimationSoundType type) { - Audio::AudioStream *stream = 0; +Audio::AudioStream *AnimationSequencePlayer::loadSound(int index, AnimationSoundType type) { + Audio::AudioStream *stream = _compressedSound->load(kSoundTypeIntro, index, type == kAnimationSoundTypeLoopingWAV); + if (stream) { + return stream; + } char fileName[64]; snprintf(fileName, sizeof(fileName), "audio/%s", _audioFileNamesTable[index]); Common::File f; @@ -626,7 +629,7 @@ Audio::AudioStream *AnimationSequencePlayer::loadSoundFileAsStream(int index, An void AnimationSequencePlayer::loadSounds(int num) { if (_soundSeqDataList[num].musicVolume != 0) { Audio::AudioStream *s; - if ((s = loadSoundFileAsStream(_soundSeqDataList[num].musicIndex, kAnimationSoundType8BitsRAW)) != 0) { + if ((s = loadSound(_soundSeqDataList[num].musicIndex, kAnimationSoundType8BitsRAW)) != 0) { _mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, s, -1, scaleMixerVolume(_soundSeqDataList[num].musicVolume)); } } @@ -641,12 +644,12 @@ void AnimationSequencePlayer::updateSounds() { while (_soundSeqDataIndex < _soundSeqDataCount && p->timestamp <= _frameCounter) { switch (p->opcode) { case 0: - if ((s = loadSoundFileAsStream(p->num, kAnimationSoundTypeWAV)) != 0) { + if ((s = loadSound(p->num, kAnimationSoundTypeWAV)) != 0) { _mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_soundsHandle[p->index], s, -1, scaleMixerVolume(p->volume)); } break; case 1: - if ((s = loadSoundFileAsStream(p->num, kAnimationSoundTypeLoopingWAV)) != 0) { + if ((s = loadSound(p->num, kAnimationSoundTypeLoopingWAV)) != 0) { _mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_soundsHandle[p->index], s, -1, scaleMixerVolume(p->volume)); } break; @@ -658,18 +661,18 @@ void AnimationSequencePlayer::updateSounds() { break; case 4: _mixer->stopHandle(_musicHandle); - if ((s = loadSoundFileAsStream(p->num, kAnimationSoundType8BitsRAW)) != 0) { + if ((s = loadSound(p->num, kAnimationSoundType8BitsRAW)) != 0) { _mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, s, -1, scaleMixerVolume(p->volume)); } break; case 5: - if ((s = loadSoundFileAsStream(p->num, kAnimationSoundTypeWAV)) != 0) { + if ((s = loadSound(p->num, kAnimationSoundTypeWAV)) != 0) { _mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, s, -1, scaleMixerVolume(p->volume)); } break; case 6: _mixer->stopHandle(_musicHandle); - if ((s = loadSoundFileAsStream(p->num, kAnimationSoundType16BitsRAW)) != 0) { + if ((s = loadSound(p->num, kAnimationSoundType16BitsRAW)) != 0) { _mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, s, -1, scaleMixerVolume(p->volume)); } break; diff --git a/engines/tucker/tucker.cpp b/engines/tucker/tucker.cpp index c5981230bf..6cf0a7cdc2 100644 --- a/engines/tucker/tucker.cpp +++ b/engines/tucker/tucker.cpp @@ -55,11 +55,12 @@ bool TuckerEngine::hasFeature(EngineFeature f) const { Common::Error TuckerEngine::run() { initGraphics(kScreenWidth, kScreenHeight, false); syncSoundSettings(); - + _compressedSound.openFile(); handleIntroSequence(); if ((_gameFlags & kGameFlagIntroOnly) == 0 && !shouldQuit()) { mainLoop(); } + _compressedSound.closeFile(); return Common::kNoError; } @@ -332,7 +333,6 @@ void TuckerEngine::mainLoop() { allocateBuffers(); restart(); - openCompressedSoundFile(); loadCharSizeDta(); if ((_gameFlags & kGameFlagDemo) != 0) { addObjectToInventory(30); @@ -586,7 +586,6 @@ void TuckerEngine::mainLoop() { if (_flagsTable[100] == 1) { handleCongratulationsSequence(); } - closeCompressedSoundFile(); unloadSprA02_01(); unloadSprC02_01(); freeBuffers(); diff --git a/engines/tucker/tucker.h b/engines/tucker/tucker.h index ce43fa66a1..1b2462a9e3 100644 --- a/engines/tucker/tucker.h +++ b/engines/tucker/tucker.h @@ -210,6 +210,29 @@ enum GameFlag { kGameFlagIntroOnly = 1 << 3 }; +enum CompressedSoundType { + kSoundTypeFx, + kSoundTypeMusic, + kSoundTypeSpeech, + kSoundTypeIntro +}; + +class CompressedSound { +public: + + CompressedSound() : _compressedSoundType(-1) {} + + void openFile(); + void closeFile(); + Audio::AudioStream *load(CompressedSoundType type, int num, bool loop); + +private: + + int _compressedSoundType; + int _compressedSoundFlags; + Common::File _fCompressedSound; +}; + inline int scaleMixerVolume(int volume, int max = 100) { return volume * Audio::Mixer::kMaxChannelVolume / max; } @@ -542,8 +565,6 @@ protected: void copyMapRect(int x, int y, int w, int h); int handleSpecialObjectSelectionSequence(); - void openCompressedSoundFile(); - void closeCompressedSoundFile(); uint8 *loadFile(const char *filename, uint8 *p); void loadImage(const char *filename, uint8 *dst, int a); void loadCursor(); @@ -574,6 +595,7 @@ protected: Common::RandomSource _rnd; AnimationSequencePlayer *_player; + CompressedSound _compressedSound; Common::Language _gameLang; uint32 _gameFlags; @@ -603,8 +625,6 @@ protected: int _gameHintsStringNum; int _fileLoadSize; - int _compressedSoundType; - Common::File _fCompressedSound; uint8 *_loadTempBuf; uint8 *_cursorGfxBuf; uint8 *_charsetGfxBuf; @@ -890,7 +910,7 @@ public: void (AnimationSequencePlayer::*play)(); }; - AnimationSequencePlayer(OSystem *system, Audio::Mixer *mixer, Common::EventManager *event, int num); + AnimationSequencePlayer(OSystem *system, Audio::Mixer *mixer, Common::EventManager *event, CompressedSound *sound, int num); ~AnimationSequencePlayer(); void mainLoop(); @@ -899,7 +919,7 @@ private: void syncTime(); void loadSounds(int num); - Audio::AudioStream *loadSoundFileAsStream(int index, AnimationSoundType type); + Audio::AudioStream *loadSound(int index, AnimationSoundType type); void updateSounds(); void fadeInPalette(); void fadeOutPalette(); @@ -933,6 +953,7 @@ private: OSystem *_system; Audio::Mixer *_mixer; Common::EventManager *_event; + CompressedSound *_compressedSound; int _seqNum; bool _changeToNextSequence; |