diff -ur --exclude=CVS ScummVM/scummvm/sword2/driver/animation.cpp ScummVM+hack/scummvm/sword2/driver/animation.cpp
old
|
new
|
|
128 | 128 | |
129 | 129 | info = mpeg2_info(decoder); |
130 | 130 | framenum = 0; |
131 | | ticks = _vm->_system->get_msecs(); |
132 | 131 | |
133 | 132 | // Play audio |
134 | 133 | |
… |
… |
|
140 | 139 | if (sndfile->open(tempFile)) { |
141 | 140 | bgSoundStream = makeVorbisStream(sndfile, sndfile->size()); |
142 | 141 | _vm->_mixer->playInputStream(&bgSound, bgSoundStream, false, 255, 0, -1); |
| 142 | |
143 | 143 | } |
144 | | |
145 | 144 | #endif |
146 | 145 | |
| 146 | ticks = _vm->_system->get_msecs(); |
| 147 | |
147 | 148 | return true; |
148 | 149 | #else /* USE_MPEG2 */ |
149 | 150 | return false; |
… |
… |
|
337 | 338 | case STATE_SLICE: |
338 | 339 | case STATE_END: |
339 | 340 | if (info->display_fbuf) { |
340 | | /* simple audio video sync code: |
341 | | * we calculate the actual frame by taking the delivered audio samples |
342 | | * we add 2 frames as the number of samples delivered is higher than the |
343 | | * number actually played due to buffering |
| 341 | /* Audio/video sync is extremely simple. We |
| 342 | * just keep track of how long it's been since |
| 343 | * the audio track was started to calculate an |
| 344 | * approximate frame number. We try not to lag |
| 345 | * more than one frame behind this. |
344 | 346 | * |
345 | | * we then try to stay inside +- 1 frame of this calculated frame number by |
346 | | * dropping frames if we run behind and delaying if we are too fast |
| 347 | * We do it this way since there is no way of |
| 348 | * asking the mixer how many samples have |
| 349 | * actually been played. |
347 | 350 | */ |
348 | 351 | |
349 | 352 | #ifdef BACKEND_8BIT |
350 | | if (checkPaletteSwitch() || (bgSoundStream == NULL) || |
351 | | (bgSoundStream->getSamplesPlayed() * 12 / bgSoundStream->getRate()) < (framenum + 3)){ |
352 | 353 | |
353 | | _vm->_graphics->plotYUV(lut, sequence_i->width, sequence_i->height, info->display_fbuf->buf); |
354 | | |
355 | | if (bgSoundStream) { |
356 | | while ((bgSoundStream->getSamplesPlayed() * 12 / bgSoundStream->getRate()) < framenum + 1) |
357 | | _vm->_system->delay_msecs(10); |
358 | | } else { |
359 | | ticks += 83; |
360 | | _vm->sleepUntil(ticks); |
361 | | } |
| 354 | (1000 * (framenum + 1)) / 12 + ticks |
362 | 355 | |
| 356 | if (checkPaletteSwitch() || _vm->_system->get_msecs() < (1000 * (framenum + 1)) / 12 + ticks) { |
| 357 | _vm->_graphics->plotYUV(lut, sequence_i->width, sequence_i->height, info->display_fbuf->buf); |
| 358 | _vm->sleepUntil(ticks + (1000 * framenum) / 12); |
363 | 359 | _vm->_graphics->setNeedFullRedraw(); |
364 | | |
365 | 360 | } else |
366 | 361 | warning("dropped frame %i", framenum); |
367 | 362 | |
… |
… |
|
369 | 364 | |
370 | 365 | #else |
371 | 366 | |
372 | | if ((bgSoundStream == NULL) || |
373 | | (bgSoundStream->getSamplesPlayed()*12/bgSoundStream->getRate()) < (framenum+3)){ |
374 | | |
| 367 | if (((_vm->_system->get_msecs() - ticks) * 12) / 1000 < framenum + 1) { |
375 | 368 | plotYUV(lookup2, sequence_i->width, sequence_i->height, info->display_fbuf->buf); |
376 | | |
377 | | if (bgSoundStream) { |
378 | | while ((bgSoundStream->getSamplesPlayed()*12/bgSoundStream->getRate()) < framenum + 1) |
379 | | _vm->_system->delay_msecs(10); |
380 | | } else { |
381 | | ticks += 83; |
382 | | _vm->sleepUntil(ticks); |
383 | | } |
384 | | |
| 369 | _vm->sleepUntil(ticks + (1000 * framenum) / 12); |
385 | 370 | } else |
386 | 371 | warning("dropped frame %i", framenum); |
387 | 372 | |
… |
… |
|
389 | 374 | |
390 | 375 | framenum++; |
391 | 376 | return true; |
392 | | |
393 | 377 | } |
394 | 378 | break; |
395 | 379 | |
diff -ur --exclude=CVS ScummVM/scummvm/sword2/driver/animation.h ScummVM+hack/scummvm/sword2/driver/animation.h
old
|
new
|
|
69 | 69 | private: |
70 | 70 | Sword2Engine *_vm; |
71 | 71 | |
72 | | int framenum; |
73 | | int ticks; |
| 72 | uint framenum; |
| 73 | uint32 ticks; |
74 | 74 | |
75 | 75 | #ifdef USE_MPEG2 |
76 | 76 | mpeg2dec_t *decoder; |
… |
… |
|
100 | 100 | |
101 | 101 | struct { |
102 | 102 | int cnt; |
103 | | int end; |
| 103 | uint end; |
104 | 104 | byte pal[4 * 256]; |
105 | 105 | } palettes[50]; |
106 | 106 | #else |