From 0430bb9b3a1189cada3edd3cf18061e06dcad17c Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Sat, 3 Jan 2009 13:31:23 +0000 Subject: Proper lag calculation even if the SMK has no audio svn-id: r35698 --- graphics/video/smk_player.cpp | 17 +++++++++++++++-- graphics/video/smk_player.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'graphics/video') diff --git a/graphics/video/smk_player.cpp b/graphics/video/smk_player.cpp index 2ea9fe7e44..5ad7044c5f 100644 --- a/graphics/video/smk_player.cpp +++ b/graphics/video/smk_player.cpp @@ -370,12 +370,22 @@ int32 SMKPlayer::getFrameDelay() { } int32 SMKPlayer::getAudioLag() { - if (!_fileStream || !_audioStream) + if (!_fileStream) return 0; int32 frameDelay = getFrameDelay(); int32 videoTime = _currentSMKFrame * frameDelay; - int32 audioTime = (((int32) _mixer->getSoundElapsedTime(_audioHandle)) * 100); + int32 audioTime; + + if (!_audioStream) { + /* No audio. + Calculate the lag by how much time has gone by since the first frame + and how much time *should* have passed. + */ + + audioTime = (g_system->getMillis() - _startTime) * 100; + } else + audioTime = (((int32) _mixer->getSoundElapsedTime(_audioHandle)) * 100); return videoTime - audioTime; } @@ -546,6 +556,9 @@ bool SMKPlayer::decodeNextFrame() { uint32 startPos = _fileStream->pos(); + if (_currentSMKFrame == 0) + _startTime = g_system->getMillis(); + // Check if we got a frame with palette data, and // call back the virtual setPalette function to set // the current palette diff --git a/graphics/video/smk_player.h b/graphics/video/smk_player.h index e07412b2a5..c1b118b13e 100644 --- a/graphics/video/smk_player.h +++ b/graphics/video/smk_player.h @@ -184,6 +184,7 @@ private: Audio::SoundHandle _audioHandle; uint32 _currentSMKFrame; + uint32 _startTime; BigHuffmanTree *_MMapTree; BigHuffmanTree *_MClrTree; -- cgit v1.2.3