diff options
-rw-r--r-- | engines/prince/prince.cpp | 51 | ||||
-rw-r--r-- | engines/prince/prince.h | 7 | ||||
-rw-r--r-- | engines/prince/script.cpp | 54 | ||||
-rw-r--r-- | engines/prince/script.h | 2 |
4 files changed, 68 insertions, 46 deletions
diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index 2d1f6ce880..2b4390c755 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -73,7 +73,7 @@ PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc) Engine(syst), _gameDescription(gameDesc), _graph(NULL), _script(NULL), _locationNr(0), _debugger(NULL), _objectList(NULL), _mobList(NULL), _midiPlayer(NULL), _cameraX(0), _newCameraX(0), _frameNr(0), _cursor1(NULL), _cursor2(NULL), _font(NULL), - _walizkaBmp(NULL), _roomBmp(NULL) { + _walizkaBmp(NULL), _roomBmp(NULL), _voiceStream(NULL) { // Debug/console setup DebugMan.addDebugChannel(DebugChannel::kScript, "script", "Prince Script debug channel"); @@ -304,6 +304,55 @@ bool PrinceEngine::playNextFrame() { return true; } +void PrinceEngine::playSample(uint16 sampleId, uint16 loopType) { + if (_voiceStream) { + + Audio::RewindableAudioStream *audioStream = Audio::makeWAVStream(_voiceStream, DisposeAfterUse::YES); + _mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, audioStream, sampleId); + } +} + +void PrinceEngine::stopSample(uint16 sampleId) { + _mixer->stopID(sampleId); + _voiceStream = NULL; +} + +bool PrinceEngine::loadVoice(uint32 slot, const Common::String &streamName) { + debugEngine("Loading wav %s slot %d", streamName.c_str(), slot); + + _voiceStream = SearchMan.createReadStreamForMember(streamName); + if (!_voiceStream) { + error("Can't open %s", streamName.c_str()); + return false; + } + + uint32 id = _voiceStream->readUint32LE(); + if (id != 0x46464952) { + error("It's not RIFF file %s", streamName.c_str()); + return false; + } + + _voiceStream->skip(0x20); + id = _voiceStream->readUint32LE(); + if (id != 0x61746164) { + error("No data section in %s id %04x", streamName.c_str(), id); + return false; + } + + id = _voiceStream->readUint32LE(); + debugEngine("SetVoice slot %d time %04x", slot, id); + id <<= 3; + id /= 22050; + id += 2; + + _textSlots[slot]._time = id; + + debugEngine("SetVoice slot %d time %04x", slot, id); + _voiceStream->seek(0); + + return true; +} + bool PrinceEngine::loadAnim(uint16 animNr, bool loop) { Common::String streamName = Common::String::format("AN%02d", animNr); Common::SeekableReadStream * flicStream = SearchMan.createReadStreamForMember(streamName); diff --git a/engines/prince/prince.h b/engines/prince/prince.h index c97a9022a6..4f2ddf827a 100644 --- a/engines/prince/prince.h +++ b/engines/prince/prince.h @@ -101,6 +101,10 @@ public: bool loadLocation(uint16 locationNr); bool loadAnim(uint16 animNr, bool loop); + bool loadVoice(uint32 slot, const Common::String &name); + + void playSample(uint16 sampleId, uint16 loopType); + void stopSample(uint16 sampleId); virtual GUI::Debugger *getDebugger(); @@ -139,6 +143,9 @@ private: MobList *_mobList; MusicPlayer *_midiPlayer; + Audio::SoundHandle _soundHandle; + Common::SeekableReadStream *_voiceStream; + uint16 _cameraX; uint16 _newCameraX; uint16 _sceneWidth; diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp index 1c09ddb50f..fd0dc73264 100644 --- a/engines/prince/script.cpp +++ b/engines/prince/script.cpp @@ -40,7 +40,7 @@ static const uint16 NUM_OPCODES = 144; Script::Script(PrinceEngine *vm) : _code(NULL), _stacktop(0), _vm(vm), _opcodeNF(false), - _waitFlag(0), _voiceStream(NULL), _result(true) { + _waitFlag(0), _result(true) { } Script::~Script() { @@ -200,12 +200,7 @@ void Script::O_PLAYSAMPLE() { uint16 sampleId = readScript16bits(); uint16 loopType = readScript16bits(); debugScript("O_PLAYSAMPLE sampleId %d loopType %d", sampleId, loopType); - - if (_voiceStream) { - - Audio::RewindableAudioStream *audioStream = Audio::makeWAVStream(_voiceStream, DisposeAfterUse::YES); - _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, audioStream, sampleId); - } + _vm->playSample(sampleId, loopType); } void Script::O_PUTOBJECT() { @@ -875,9 +870,7 @@ void Script::O_SHOWDIALOGBOX() { void Script::O_STOPSAMPLE() { uint16 slot = readScript16bits(); debugScript("O_STOPSAMPLE slot %d", slot); - - _vm->_mixer->stopID(slot); - _voiceStream = NULL; + _vm->stopSample(slot); } void Script::O_BACKANIMRANGE() { @@ -1065,39 +1058,14 @@ void Script::O_SKIPTEXT() { } void Script::SetVoice(uint32 slot) { - - const uint16 VOICE_H_LINE = getFlagValue(Flags::VOICE_H_LINE); - - const Common::String streamName = Common::String::format("%03d-%02d.WAV", _currentString, VOICE_H_LINE); - debugScript("Loading wav %s slot %d", streamName.c_str(), slot); - - _voiceStream = SearchMan.createReadStreamForMember(streamName); - if (!_voiceStream) { - error("Can't open %s", streamName.c_str()); - } - uint32 id = _voiceStream->readUint32LE(); - if (id != 0x46464952) { - error("It's not RIFF file %s", streamName.c_str()); - return; - } - - _voiceStream->skip(0x20); - id = _voiceStream->readUint32LE(); - if (id != 0x61746164) { - error("No data section in %s id %04x", streamName.c_str(), id); - return; - } - - id = _voiceStream->readUint32LE(); - debugScript("SetVoice slot %d time %04x", slot, id); - id <<= 3; - id /= 22050; - id += 2; - - _vm->_textSlots[slot]._time = id; - - debugScript("SetVoice slot %d time %04x", slot, id); - _voiceStream->seek(0); + _vm->loadVoice( + slot, + Common::String::format( + "%03d-%02d.WAV", + _currentString, + getFlagValue(Flags::VOICE_H_LINE) + ) + ); } void Script::O_SETVOICEH() { diff --git a/engines/prince/script.h b/engines/prince/script.h index a323c1784d..86b998829f 100644 --- a/engines/prince/script.h +++ b/engines/prince/script.h @@ -74,11 +74,9 @@ private: uint8 _stacktop; uint8 _savedStacktop; uint32 _waitFlag; - Audio::SoundHandle _soundHandle; const byte *_string; uint32 _currentString; - Common::SeekableReadStream *_voiceStream; const char *_mode; // Helper functions |