Ticket #1399: sword-animation.diff
File sword-animation.diff, 8.0 KB (added by , 21 years ago) |
---|
-
scummvm/sword1/animation.cpp
diff -ur --exclude=CVS ScummVM/scummvm/sword1/animation.cpp ScummVM+hack/scummvm/sword1/animation.cpp
old new 125 125 126 126 info = mpeg2_info(decoder); 127 127 framenum = 0; 128 ticks = _sys->get_msecs();129 128 130 / * Play audio - TODO: Sync with video?*/129 // Play audio 131 130 132 131 #ifdef USE_VORBIS 133 132 // Another TODO: There is no reason that this only allows OGG, and not … … 139 138 bgSoundStream = makeVorbisStream(sndfile, sndfile->size()); 140 139 _snd->playInputStream(&bgSound, bgSoundStream, false, 255, 0, -1); 141 140 } 142 143 141 #endif 144 142 143 startTime = _sys->get_msecs(); 144 145 145 return true; 146 146 #else /* USE_MPEG2 */ 147 147 return false; … … 298 298 case STATE_SLICE: 299 299 case STATE_END: 300 300 if (info->display_fbuf) { 301 /* simple audio video sync code: 302 * we calculate the actual frame by taking the delivered audio samples 303 * we add 2 frames as the number of samples delivered is higher than the 304 * number actually played due to buffering 305 * 306 * we then try to stay inside +- 1 frame of this calculated frame number by 307 * dropping frames if we run behind and delaying if we are too fast 308 */ 309 310 #ifdef BACKEND_8BIT 311 if (checkPaletteSwitch() || (bgSoundStream == NULL) || 312 (bgSoundStream->getSamplesPlayed()*12/bgSoundStream->getRate()) < (framenum+3)){ 313 _scr->plotYUV(lut, sequence_i->width, sequence_i->height, info->display_fbuf->buf); 314 315 if (bgSoundStream) { 316 while ((bgSoundStream->getSamplesPlayed()*12/bgSoundStream->getRate()) < framenum+1) 317 _sys->delay_msecs(10); 318 } else { 319 ticks += 83; 320 while (_sys->get_msecs() < ticks) 321 _sys->delay_msecs(10); 322 } 301 // Audio/video sync is extremely simple. We 302 // just keep track of how long it's been since 303 // the audio track was started to calculate an 304 // approximate frame number. We try not to lag 305 // more than one frame behind this. 306 // 307 // We do it this way since there is no way of 308 // asking the mixer how many samples have 309 // actually been played. 310 311 // FIXME: We shouldn't use delay_msecs() here. 312 // We should use something like the delay() 313 // function in SwordEngine, so that events are 314 // handled properly. For now, at least call the 315 // backend's event handler so that redraw 316 // events are processed. 323 317 318 OSystem::Event event; 324 319 320 #ifdef BACKEND_8BIT 325 321 322 if (checkPaletteSwitch() || _sys->get_msecs() < startTime + (1000 * (framenum + 1)) / 12) { 323 _scr->plotYUV(lut, sequence_i->width, sequence_i->height, info->display_fbuf->buf); 324 if (startTime + (1000 * framenum) / 12 > _sys->get_msecs()) 325 _sys->delay_msecs(startTime + (1000 * framenum) / 12 - _sys->get_msecs()); 326 _sys->poll_event(&event); 326 327 } else 327 328 warning("dropped frame %i", framenum); 328 329 … … 330 331 331 332 #else 332 333 333 if ( (bgSoundStream == NULL) || (bgSoundStream->getSamplesPlayed()*12/bgSoundStream->getRate()) < (framenum+3)){334 if (_sys->get_msecs() < startTime + (1000 * (framenum + 1)) / 12) { 334 335 plotYUV(lookup2, sequence_i->width, sequence_i->height, info->display_fbuf->buf); 335 336 if (bgSoundStream) { 337 while ((bgSoundStream->getSamplesPlayed()*12/bgSoundStream->getRate()) < framenum+1) 338 _sys->delay_msecs(10); 339 } else { 340 ticks += 83; 341 while (_sys->get_msecs() < ticks) 342 _sys->delay_msecs(10); 343 } 344 336 if (startTime + (1000 * framenum) / 12 > _sys->get_msecs()) 337 _sys->delay_msecs(startTime + (1000 * framenum) / 12 - _sys->get_msecs()); 338 _sys->poll_event(&event); 345 339 } else 346 340 warning("dropped frame %i", framenum); 347 341 … … 349 343 350 344 framenum++; 351 345 return true; 352 353 346 } 354 347 break; 355 348 -
scummvm/sword1/animation.h
diff -ur --exclude=CVS ScummVM/scummvm/sword1/animation.h ScummVM+hack/scummvm/sword1/animation.h
old new 76 76 SoundMixer *_snd; 77 77 OSystem *_sys; 78 78 79 int framenum;80 uint32 ticks;79 uint framenum; 80 uint32 startTime; 81 81 82 82 #ifdef USE_MPEG2 83 83 mpeg2dec_t *decoder; … … 107 107 108 108 struct { 109 109 int cnt; 110 int end;110 uint end; 111 111 byte pal[4 * 256]; 112 112 } palettes[50]; 113 113 #else -
scummvm/sword2/driver/animation.cpp
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 startTime = _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 344 * 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 */ 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. 346 // 347 // We do it this way since there is no way of 348 // asking the mixer how many samples have 349 // actually been played. 348 350 349 351 #ifdef BACKEND_8BIT 350 if (checkPaletteSwitch() || (bgSoundStream == NULL) ||351 (bgSoundStream->getSamplesPlayed() * 12 / bgSoundStream->getRate()) < (framenum + 3)){352 352 353 if (checkPaletteSwitch() || _vm->_system->get_msecs() < startTime + (1000 * (framenum + 1)) / 12) { 353 354 _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 } 362 355 _vm->sleepUntil(startTime + (1000 * framenum) / 12); 363 356 _vm->_graphics->setNeedFullRedraw(); 364 365 357 } else 366 358 warning("dropped frame %i", framenum); 367 359 … … 369 361 370 362 #else 371 363 372 if ((bgSoundStream == NULL) || 373 (bgSoundStream->getSamplesPlayed() * 12 / bgSoundStream->getRate()) < (framenum+3)){ 374 364 if (_vm->_system->get_msecs() < startTime + (1000 * (framenum + 1)) / 12) { 375 365 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 366 _vm->sleepUntil(startTime + (1000 * framenum) / 12); 385 367 } else 386 368 warning("dropped frame %i", framenum); 387 369 … … 389 371 390 372 framenum++; 391 373 return true; 392 393 374 } 394 375 break; 395 376 -
scummvm/sword2/driver/animation.h
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 startTime; 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