aboutsummaryrefslogtreecommitdiff
path: root/engines/made/pmvplayer.cpp
diff options
context:
space:
mode:
authorBenjamin Haisch2008-05-08 11:17:38 +0000
committerBenjamin Haisch2008-05-08 11:17:38 +0000
commitb63ae7dee4ae461f204f23641360a6aef1c2c304 (patch)
tree9483bc2d983a02a19f38f908b2550ef0ee2e94c7 /engines/made/pmvplayer.cpp
parentb75f844a723269161031f7d9b0899bf18fcfcea6 (diff)
downloadscummvm-rg350-b63ae7dee4ae461f204f23641360a6aef1c2c304.tar.gz
scummvm-rg350-b63ae7dee4ae461f204f23641360a6aef1c2c304.tar.bz2
scummvm-rg350-b63ae7dee4ae461f204f23641360a6aef1c2c304.zip
Possibly fixed the sound stuttering in the PMV videos and added frame skipping based on the Gob engine's IMD/VMD player.
svn-id: r31944
Diffstat (limited to 'engines/made/pmvplayer.cpp')
-rw-r--r--engines/made/pmvplayer.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/engines/made/pmvplayer.cpp b/engines/made/pmvplayer.cpp
index b3f9915b92..6058854354 100644
--- a/engines/made/pmvplayer.cpp
+++ b/engines/made/pmvplayer.cpp
@@ -54,8 +54,8 @@ void PmvPlayer::play(const char *filename) {
_fd->skip(10);
uint soundFreq = _fd->readUint16LE();
// FIXME: weird frequencies... (11127 or 22254)
- //if (soundFreq == 11127) soundFreq = 11025;
- //if (soundFreq == 22254) soundFreq = 22050;
+ if (soundFreq == 11127) soundFreq = 11025;
+ if (soundFreq == 22254) soundFreq = 22050;
int unk;
@@ -78,6 +78,8 @@ void PmvPlayer::play(const char *filename) {
uint32 palSize = 0;
byte *frameData, *audioData, *soundData, *palData, *imageData;
bool firstTime = true;
+
+ uint32 soundStartTime, skipFrames;
uint32 frameNum;
uint16 width, height, cmdOffs, pixelOffs, maskOffs, lineSize;
@@ -89,6 +91,8 @@ void PmvPlayer::play(const char *filename) {
while (!_abort && !_fd->eof()) {
+ int32 frameTime = _vm->_system->getMillis();
+
readChunk(chunkType, chunkSize);
if (_fd->eof())
@@ -104,7 +108,7 @@ void PmvPlayer::play(const char *filename) {
if (chunkCount > 50) break; // FIXME: this is a hack
- debug(2, "chunkCount = %d; chunkSize = %d\n", chunkCount, chunkSize);
+ debug(1, "chunkCount = %d; chunkSize = %d; total = %d\n", chunkCount, chunkSize, chunkCount * chunkSize);
soundSize = chunkCount * chunkSize;
soundData = new byte[soundSize];
@@ -117,6 +121,7 @@ void PmvPlayer::play(const char *filename) {
palData = frameData + palChunkOfs - 8;
palSize = READ_LE_UINT32(palData + 4);
decompressPalette(palData + 8, _paletteRGB, palSize);
+ _vm->_screen->setRGBPalette(_paletteRGB);
}
// Handle video
@@ -142,20 +147,30 @@ void PmvPlayer::play(const char *filename) {
if (firstTime) {
_mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_audioStreamHandle, _audioStream);
+ soundStartTime = g_system->getMillis();
+ skipFrames = 0;
firstTime = false;
}
- _vm->_screen->setRGBPalette(_paletteRGB);
handleEvents();
updateScreen();
- frameCount++;
-
delete[] frameData;
- while (_mixer->getSoundElapsedTime(_audioStreamHandle) < frameCount * frameDelay) {
- _vm->_system->delayMillis(10);
- }
+ if (skipFrames == 0) {
+ int32 waitTime = (frameCount * frameDelay) -
+ (g_system->getMillis() - soundStartTime) - (_vm->_system->getMillis() - frameTime);
+
+ if (waitTime < 0) {
+ skipFrames = -waitTime / frameDelay;
+ warning("Video A/V sync broken, skipping %d frame(s)", skipFrames + 1);
+ } else if (waitTime > 0)
+ g_system->delayMillis(waitTime);
+
+ } else
+ skipFrames--;
+
+ frameCount++;
}