From 7c311057c10f876cbe5053fac1943917766ae0f0 Mon Sep 17 00:00:00 2001 From: Robert Špalek Date: Tue, 13 Oct 2009 04:44:22 +0000 Subject: Dubbing is played. I haven't implemented switching dubbing and subtitles on/off according to the config manager nor the speed of the subtitles, yet. svn-id: r45001 --- engines/draci/game.cpp | 12 +++--------- engines/draci/game.h | 3 ++- engines/draci/script.cpp | 24 +++++++++++++++++++++++- engines/draci/sound.cpp | 2 +- engines/draci/sound.h | 2 +- 5 files changed, 30 insertions(+), 13 deletions(-) (limited to 'engines') diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index ff15483cc7..a9cf42c73b 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -414,18 +414,11 @@ void Game::loop() { // Handle character talking (if there is any) if (_loopSubstatus == kSubstatusTalk) { - Animation *speechAnim = _vm->_anims->getAnimation(kSpeechText); - Text *speechFrame = reinterpret_cast(speechAnim->getFrame()); - - uint speechDuration = kBaseSpeechDuration + - speechFrame->getLength() * kSpeechTimeUnit / - (128 / 16 + 1); - // If the current speech text has expired or the user clicked a mouse button, // advance to the next line of text if (_vm->_mouse->lButtonPressed() || _vm->_mouse->rButtonPressed() || - (_vm->_system->getMillis() - _speechTick) >= speechDuration) { + (_vm->_system->getMillis() - _speechTick) >= _speechDuration) { _shouldExitLoop = true; _vm->_mouse->lButtonSet(false); @@ -1508,8 +1501,9 @@ const Person *Game::getPerson(int personID) const { return &_persons[personID]; } -void Game::setSpeechTick(uint tick) { +void Game::setSpeechTiming(uint tick, uint duration) { _speechTick = tick; + _speechDuration = duration; } int Game::getEscRoom() const { diff --git a/engines/draci/game.h b/engines/draci/game.h index 826f5599f2..0fca5972cb 100644 --- a/engines/draci/game.h +++ b/engines/draci/game.h @@ -324,7 +324,7 @@ public: int shouldExitLoop() const { return _shouldExitLoop; } void setExitLoop(int exit) { _shouldExitLoop = exit; } - void setSpeechTick(uint tick); + void setSpeechTiming(uint tick, uint duration); void updateTitle(); void updateCursor(); @@ -408,6 +408,7 @@ private: int _shouldExitLoop; // 0=false and 1=true are normal, 2=immediate exit after loading uint _speechTick; + uint _speechDuration; int _objUnderCursor; int _oldObjUnderCursor; diff --git a/engines/draci/script.cpp b/engines/draci/script.cpp index 4ab75f1291..fdc6774e25 100644 --- a/engines/draci/script.cpp +++ b/engines/draci/script.cpp @@ -713,8 +713,23 @@ void Script::talk(Common::Queue ¶ms) { // Set the loop substatus to an appropriate value _vm->_game->setLoopSubstatus(kSubstatusTalk); + // Speak the dubbing if possible + SoundSample *sample = _vm->_dubbingArchive->getSample(sentenceID, 0); + uint dubbingDuration = 0; + if (sample) { + dubbingDuration = (uint) (1000.0 * sample->_length / sample->_frequency + 500.0); + debugC(3, kDraciSoundDebugLevel, "Playing sentence %d: %d+%d with duration %dms", + sentenceID, sample->_offset, sample->_length, dubbingDuration); + _vm->_sound->playVoice(sample); + } + // Record time - _vm->_game->setSpeechTick(_vm->_system->getMillis()); + const uint subtitleDuration = kBaseSpeechDuration + + speechFrame->getLength() * kSpeechTimeUnit / + (128 / 16 + 1); + const uint duration = subtitleDuration >= dubbingDuration ? + subtitleDuration : dubbingDuration; + _vm->_game->setSpeechTiming(_vm->_system->getMillis(), duration); // TODO: Implement inventory part @@ -737,6 +752,13 @@ void Script::talk(Common::Queue ¶ms) { _vm->_screen->getSurface()->markDirtyRect(speechFrame->getRect()); speechFrame->setText(""); + // Stop the playing sample and deallocate it. Stopping should only be + // necessary if the user interrupts the playback. + if (sample) { + _vm->_sound->stopVoice(); + sample->close(); + } + // Revert to "normal" loop status _vm->_game->setLoopSubstatus(kSubstatusOrdinary); _vm->_game->setExitLoop(false); diff --git a/engines/draci/sound.cpp b/engines/draci/sound.cpp index 2d2cbcf74d..1324d8e992 100644 --- a/engines/draci/sound.cpp +++ b/engines/draci/sound.cpp @@ -133,7 +133,7 @@ void SoundArchive::clearCache() { * * Loads individual samples from an archive to memory on demand. */ -const SoundSample *SoundArchive::getSample(int i, uint freq) { +SoundSample *SoundArchive::getSample(int i, uint freq) { // Check whether requested file exists if (i < 0 || i >= (int) _sampleCount) { return NULL; diff --git a/engines/draci/sound.h b/engines/draci/sound.h index 86d92f1bf7..6d63b066eb 100644 --- a/engines/draci/sound.h +++ b/engines/draci/sound.h @@ -68,7 +68,7 @@ public: void clearCache(); - const SoundSample *getSample(int i, uint freq); + SoundSample *getSample(int i, uint freq); private: Common::String _path; ///< Path to file -- cgit v1.2.3