Ticket #2637: av_sync.patch
File av_sync.patch, 10.5 KB (added by , 15 years ago) |
---|
-
script_lok.cpp
35 35 #include "kyra/animator_lok.h" 36 36 #include "kyra/text.h" 37 37 #include "kyra/timer.h" 38 #include "kyra/sound.h" 38 39 39 40 namespace Kyra { 40 41 int KyraEngine_LoK::o1_magicInMouseItem(EMCState *script) { … … 320 321 } 321 322 322 323 int KyraEngine_LoK::o1_delaySecs(EMCState *script) { 323 debugC(3, kDebugLevelScriptFuncs, "KyraEngine_LoK::o1_delaySecs(%p) (%d)", (const void *)script, stackPos(0)); 324 if (stackPos(0) > 0 && !_skipFlag) 325 delay(stackPos(0)*1000, true); 324 if (_flags.isTalkie && speechEnabled()) { 325 debugC(3, kDebugLevelScriptFuncs, "KyraEngine_LoK::o1_voiceDelay(%p) (%d)", (const void *)script, stackPos(0)); 326 if (stackPos(0) == 0) { 327 snd_voiceWaitForFinish(true); 328 } else if (stackPos(0) < 0) { 329 uint32 time = ABS(stackPos(0)) * _tickLength; 330 delay(time, true); 331 } 332 } else { 333 debugC(3, kDebugLevelScriptFuncs, "KyraEngine_LoK::o1_delaySecs(%p) (%d)", (const void *)script, stackPos(0)); 334 if (stackPos(0) >= 0 && !_skipFlag) 335 delay(stackPos(0)*1000, true); 336 } 337 326 338 _skipFlag = false; 327 339 return 0; 328 340 } … … 700 712 } 701 713 702 714 int KyraEngine_LoK::o1_displayWSASequentialFrames(EMCState *script) { 703 debugC(3, kDebugLevelScriptFuncs, "KyraEngine_LoK::o1_displayWSASequentialFrames(%p) (%d, %d, %d, %d, %d, %d, %d)", (const void *)script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5), stackPos(6)); 715 if (_flags.isTalkie) 716 debugC(3, kDebugLevelScriptFuncs, "KyraEngine_LoK::o1_displayWSASequentialFrames(%p) (%d, %d, %d, %d, %d, %d, %d, %d)", (const void *)script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5), stackPos(6), stackPos(7)); 717 else 718 debugC(3, kDebugLevelScriptFuncs, "KyraEngine_LoK::o1_displayWSASequentialFrames(%p) (%d, %d, %d, %d, %d, %d, %d)", (const void *)script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5), stackPos(6)); 704 719 int startFrame = stackPos(0); 705 720 int endFrame = stackPos(1); 706 721 int xpos = stackPos(2); … … 708 723 int waitTime = stackPos(4); 709 724 int wsaIndex = stackPos(5); 710 725 int maxTime = stackPos(6); 726 727 if (_flags.isTalkie) { 728 int specialTime = stackPos(7); 729 if (specialTime) { 730 uint32 voiceTime = _speechPlayTime; 731 if (voiceTime) { 732 int displayFrames = ABS(endFrame-startFrame)+1; 733 displayFrames *= maxTime; 734 assert(displayFrames != 0); 735 736 bool voiceSync = false; 737 738 if (specialTime < 0) { 739 voiceSync = true; 740 specialTime = ABS(specialTime); 741 } 742 743 voiceTime *= specialTime; 744 voiceTime /= 100; 745 746 if (voiceSync) { 747 uint32 voicePlayedTime = _sound->voicePlayedTime(_speechFile.c_str()); 748 if (voicePlayedTime >= voiceTime) 749 voiceTime = 0; 750 else 751 voiceTime -= voicePlayedTime; 752 753 if (!snd_voiceIsPlaying()) 754 voiceTime = 0; 755 } 756 757 waitTime = voiceTime / displayFrames; 758 waitTime /= _tickLength; 759 } 760 } 761 } 762 711 763 if (maxTime - 1 <= 0) 712 764 maxTime = 1; 713 765 … … 734 786 while (endFrame >= frame) { 735 787 uint32 continueTime = waitTime * _tickLength + _system->getMillis(); 736 788 _movieObjects[wsaIndex]->displayFrame(frame); 737 _animator->_updateScreen = true; 789 if (waitTime) 790 _animator->_updateScreen = true; 738 791 while (_system->getMillis() < continueTime) { 739 792 _sprites->updateSceneAnims(); 740 793 _animator->updateAllObjectShapes(); … … 751 804 while (endFrame <= frame) { 752 805 uint32 continueTime = waitTime * _tickLength + _system->getMillis(); 753 806 _movieObjects[wsaIndex]->displayFrame(frame); 754 _animator->_updateScreen = true; 807 if (waitTime) 808 _animator->_updateScreen = true; 755 809 while (_system->getMillis() < continueTime) { 756 810 _sprites->updateSceneAnims(); 757 811 _animator->updateAllObjectShapes(); … … 1691 1745 debugC(3, kDebugLevelScriptFuncs, "KyraEngine_LoK::o1_pauseMusicSeconds(%p) ()", (const void *)script); 1692 1746 // if music disabled 1693 1747 // return 1694 o1_delaySecs(script);1748 delay(stackPos(0)*1000, true); 1695 1749 return 0; 1696 1750 } 1697 1751 -
sound_towns.cpp
1432 1432 //_driver->reset(); 1433 1433 } 1434 1434 1435 boolSoundTowns_v2::voicePlay(const char *file, bool) {1435 uint32 SoundTowns_v2::voicePlay(const char *file, bool) { 1436 1436 static const uint16 rates[] = { 0x10E1, 0x0CA9, 0x0870, 0x0654, 0x0438, 0x032A, 0x021C, 0x0194 }; 1437 1437 1438 1438 int h = 0; … … 1440 1440 while (_mixer->isSoundHandleActive(_soundChannels[h].channelHandle) && h < kNumChannelHandles) 1441 1441 h++; 1442 1442 if (h >= kNumChannelHandles) 1443 return false;1443 return 0; 1444 1444 } 1445 1445 1446 1446 char filename [13]; … … 1497 1497 _mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_soundChannels[h].channelHandle, _currentSFX); 1498 1498 1499 1499 delete[] data; 1500 return true;1500 return 1; 1501 1501 } 1502 1502 1503 1503 void SoundTowns_v2::beginFadeOut() { -
text_lok.cpp
62 62 if (chatDuration != -1) 63 63 chatDuration *= _tickLength; 64 64 65 if (vocFile != -1) { 66 snd_voiceWaitForFinish(); 65 if (vocFile != -1) 67 66 snd_playVoiceFile(vocFile); 68 }69 67 70 68 _timer->disable(14); 71 69 _timer->disable(18); … … 269 267 if (_currentCharacter->sceneId == 210) 270 268 return; 271 269 270 snd_voiceWaitForFinish(true); 271 272 272 convoInitialized = initCharacterChat(charNum); 273 273 chatPartnerNum = getChatPartnerNum(); 274 274 -
debugger.cpp
192 192 193 193 Debugger_LoK::Debugger_LoK(KyraEngine_LoK *vm) 194 194 : Debugger(vm), _vm(vm) { 195 DCmd_Register("enter", WRAP_METHOD(Debugger_LoK, cmd_enterRoom)); 195 196 DCmd_Register("rooms", WRAP_METHOD(Debugger_LoK, cmd_listRooms)); 196 197 DCmd_Register("give", WRAP_METHOD(Debugger_LoK, cmd_giveItem)); 197 198 DCmd_Register("birthstones", WRAP_METHOD(Debugger_LoK, cmd_listBirthstones)); -
sound.cpp
66 66 return false; 67 67 } 68 68 69 bool Sound::voicePlay(const char *file, bool isSfx) { 69 uint32 Sound::voicePlay(const char *file, bool isSfx) { 70 uint32 playTime = 0; 70 71 char filenamebuffer[25]; 71 72 72 73 int h = 0; 73 74 while (_mixer->isSoundHandleActive(_soundChannels[h].channelHandle) && h < kNumChannelHandles) 74 75 h++; 75 76 if (h >= kNumChannelHandles) 76 return false;77 return 0; 77 78 78 79 Audio::AudioStream *audioStream = 0; 79 80 … … 85 86 if (!stream) 86 87 continue; 87 88 audioStream = _supportedCodes[i].streamFunc(stream, true, 0, 0, 1); 89 // HACK: implement proper playTime setup 90 playTime = 1; 88 91 break; 89 92 } 90 93 … … 98 101 return false; 99 102 100 103 Common::MemoryReadStream vocStream(fileData, fileSize); 101 audioStream = Audio::makeVOCStream(vocStream); 104 Audio::FixedLengthAudioStream *aStream = Audio::makeVOCStream(vocStream); 105 playTime = aStream->getPlayTime(); 106 audioStream = aStream; 102 107 103 108 delete[] fileData; 104 109 fileSize = 0; … … 107 112 _soundChannels[h].file = file; 108 113 _mixer->playInputStream(isSfx ? Audio::Mixer::kSFXSoundType : Audio::Mixer::kSpeechSoundType, &_soundChannels[h].channelHandle, audioStream); 109 114 110 return true;115 return playTime; 111 116 } 112 117 113 118 void Sound::voiceStop(const char *file) { … … 140 145 return res; 141 146 } 142 147 148 uint32 Sound::voicePlayedTime(const char *file) { 149 if (!file) 150 return 0; 151 152 for (int i = 0; i < kNumChannelHandles; ++i) { 153 if (_soundChannels[i].file == file) 154 return _mixer->getSoundElapsedTime(_soundChannels[i].channelHandle); 155 } 156 157 return 0; 158 } 159 143 160 #pragma mark - 144 161 145 162 SoundMidiPC::SoundMidiPC(KyraEngine_v1 *vm, Audio::Mixer *mixer, MidiDriver *driver) : Sound(vm, mixer) { -
kyra_lok.h
207 207 void snd_voiceWaitForFinish(bool ingame = true); 208 208 209 209 protected: 210 uint32 _speechPlayTime; 211 210 212 void saveGame(const char *fileName, const char *saveName); 211 213 void loadGame(const char *fileName); 212 214 -
sound.h
176 176 * @param isSfx marks file as sfx instead of voice 177 177 * @return channel the voice file is played on 178 178 */ 179 virtual boolvoicePlay(const char *file, bool isSfx = false);179 virtual uint32 voicePlay(const char *file, bool isSfx = false); 180 180 181 181 /** 182 182 * Checks if a voice is being played. … … 186 186 bool voiceIsPlaying(const char *file = 0); 187 187 188 188 /** 189 * Checks how long a voice has been playing 190 * 191 * @return time in milliseconds 192 */ 193 uint32 voicePlayedTime(const char *file); 194 195 /** 189 196 * Stops playback of the current voice. 190 197 */ 191 198 void voiceStop(const char *file = 0); … … 449 456 void haltTrack(); 450 457 void beginFadeOut(); 451 458 452 boolvoicePlay(const char *file, bool isSfx = false);459 uint32 voicePlay(const char *file, bool isSfx = false); 453 460 void playSoundEffect(uint8) {} 454 461 455 462 private: -
sound_lok.cpp
67 67 assert(id >= 0 && id < 9999); 68 68 sprintf(vocFile, "%03d", id); 69 69 _speechFile = vocFile; 70 _s ound->voicePlay(vocFile);70 _speechPlayTime = _sound->voicePlay(vocFile); 71 71 } 72 72 73 73 void KyraEngine_LoK::snd_voiceWaitForFinish(bool ingame) { -
kyra_lok.cpp
91 91 memset(_panPagesTable, 0, sizeof(_panPagesTable)); 92 92 memset(_sceneAnimTable, 0, sizeof(_sceneAnimTable)); 93 93 _currHeadShape = 0; 94 _speechPlayTime = 0; 94 95 95 96 memset(&_itemBkgBackUp, 0, sizeof(_itemBkgBackUp)); 96 97 } -
text.cpp
210 210 calcWidestLineBounds(x1, x2, w, x); 211 211 _talkCoords.x = x1; 212 212 _talkCoords.w = w + 2; 213 _screen->copyRegion(_talkCoords.x, _talkMessageY, _talkCoords.x, _talkCoords.y, _talkCoords.w, _talkMessageH, srcPage, dstPage );213 _screen->copyRegion(_talkCoords.x, _talkMessageY, _talkCoords.x, _talkCoords.y, _talkCoords.w, _talkMessageH, srcPage, dstPage, Screen::CR_NO_P_CHECK); 214 214 int curPage = _screen->_curPage; 215 215 _screen->_curPage = srcPage; 216 216 for (int i = 0; i < lineCount; ++i) {