From a1f5bddaa8644630d71dd6a497d653c677a35351 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sun, 21 May 2006 20:25:22 +0000 Subject: If possible, sync the frame to getSoundElapsedTime(). svn-id: r22566 --- engines/kyra/vqa.cpp | 29 +++++++++++++++++------------ engines/kyra/vqa.h | 4 ++-- 2 files changed, 19 insertions(+), 14 deletions(-) (limited to 'engines') diff --git a/engines/kyra/vqa.cpp b/engines/kyra/vqa.cpp index c10a28f930..83eedea694 100644 --- a/engines/kyra/vqa.cpp +++ b/engines/kyra/vqa.cpp @@ -341,9 +341,7 @@ void VQAMovie::open(const char *filename) { if (_header.flags & 1) { // A 2-second buffer ought to be enough _stream = Audio::makeAppendableAudioStream(_header.freq, Audio::Mixer::FLAG_UNSIGNED, 2 * _header.freq * _header.channels); - _sound = new Audio::SoundHandle; } else { - _sound = NULL; _stream = NULL; } @@ -422,11 +420,8 @@ void VQAMovie::close() { delete [] _partialCodeBook; delete [] _vectorPointers; - if (_sound) { - _vm->_mixer->stopHandle(*_sound); - delete _sound; - _stream = NULL; - _sound = NULL; + if (_vm->_mixer->isSoundHandleActive(_sound)) { + _vm->_mixer->stopHandle(_sound); } _frameInfo = NULL; @@ -445,7 +440,7 @@ void VQAMovie::close() { } } -void VQAMovie::displayFrame(int frameNum) { +void VQAMovie::displayFrame(uint frameNum) { debugC(9, kDebugLevelMovie, "VQAMovie::displayFrame(%d)", frameNum); if (frameNum >= _header.numFrames || !_opened) return; @@ -717,15 +712,25 @@ void VQAMovie::play() { } } - _vm->_mixer->playInputStream(Audio::Mixer::kSFXSoundType, _sound, _stream); + _vm->_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_sound, _stream); - for (int i = 0; i < _header.numFrames; i++) { + for (uint i = 0; i < _header.numFrames; i++) { displayFrame(i); - // TODO: We ought to sync this to how much sound we've played. // TODO: Implement frame skipping? - while (_system->getMillis() < startTick + (i * 1000) / _header.frameRate) { + while (1) { + uint32 elapsedTime; + + if (_vm->_mixer->isSoundHandleActive(_sound)) { + elapsedTime = _vm->_mixer->getSoundElapsedTime(_sound); + } else { + elapsedTime = _system->getMillis() - startTick; + } + + if (elapsedTime >= (i * 1000) / _header.frameRate) + break; + OSystem::Event event; while (_system->pollEvent(event)) { diff --git a/engines/kyra/vqa.h b/engines/kyra/vqa.h index 05371d4869..f5d7cc5399 100644 --- a/engines/kyra/vqa.h +++ b/engines/kyra/vqa.h @@ -94,7 +94,7 @@ protected: int decodeFormat80(byte *inbuf, byte *outbuf); void decodeSND1(byte *inbuf, uint32 insize, byte *outbuf, uint32 outsize); - void displayFrame(int frameNum); + void displayFrame(uint frameNum); Common::File _file; @@ -112,7 +112,7 @@ protected: byte *_frame; Audio::AppendableAudioStream *_stream; - Audio::SoundHandle *_sound; + Audio::SoundHandle _sound; uint32 readTag(); }; -- cgit v1.2.3