Ticket #2637: av_sync.patch

File av_sync.patch, 10.5 KB (added by lordhoto, 16 years ago)

patch against SVN, relying on patch #1970427

  • script_lok.cpp

     
    3535#include "kyra/animator_lok.h"
    3636#include "kyra/text.h"
    3737#include "kyra/timer.h"
     38#include "kyra/sound.h"
    3839
    3940namespace Kyra {
    4041int KyraEngine_LoK::o1_magicInMouseItem(EMCState *script) {
     
    320321}
    321322
    322323int 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
    326338        _skipFlag = false;
    327339        return 0;
    328340}
     
    700712}
    701713
    702714int 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));
    704719        int startFrame = stackPos(0);
    705720        int endFrame = stackPos(1);
    706721        int xpos = stackPos(2);
     
    708723        int waitTime = stackPos(4);
    709724        int wsaIndex = stackPos(5);
    710725        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
    711763        if (maxTime - 1 <= 0)
    712764                maxTime = 1;
    713765
     
    734786                        while (endFrame >= frame) {
    735787                                uint32 continueTime = waitTime * _tickLength + _system->getMillis();
    736788                                _movieObjects[wsaIndex]->displayFrame(frame);
    737                                 _animator->_updateScreen = true;
     789                                if (waitTime)
     790                                        _animator->_updateScreen = true;
    738791                                while (_system->getMillis() < continueTime) {
    739792                                        _sprites->updateSceneAnims();
    740793                                        _animator->updateAllObjectShapes();
     
    751804                        while (endFrame <= frame) {
    752805                                uint32 continueTime = waitTime * _tickLength + _system->getMillis();
    753806                                _movieObjects[wsaIndex]->displayFrame(frame);
    754                                 _animator->_updateScreen = true;
     807                                if (waitTime)
     808                                        _animator->_updateScreen = true;
    755809                                while (_system->getMillis() < continueTime) {
    756810                                        _sprites->updateSceneAnims();
    757811                                        _animator->updateAllObjectShapes();
     
    16911745        debugC(3, kDebugLevelScriptFuncs, "KyraEngine_LoK::o1_pauseMusicSeconds(%p) ()", (const void *)script);
    16921746        // if music disabled
    16931747        //     return
    1694         o1_delaySecs(script);
     1748        delay(stackPos(0)*1000, true);
    16951749        return 0;
    16961750}
    16971751
  • sound_towns.cpp

     
    14321432        //_driver->reset();
    14331433}
    14341434
    1435 bool SoundTowns_v2::voicePlay(const char *file, bool) {
     1435uint32 SoundTowns_v2::voicePlay(const char *file, bool) {
    14361436        static const uint16 rates[] =   { 0x10E1, 0x0CA9, 0x0870, 0x0654, 0x0438, 0x032A, 0x021C, 0x0194 };
    14371437
    14381438        int h = 0;
     
    14401440                while (_mixer->isSoundHandleActive(_soundChannels[h].channelHandle) && h < kNumChannelHandles)
    14411441                        h++;
    14421442                if (h >= kNumChannelHandles)
    1443                         return false;
     1443                        return 0;
    14441444        }
    14451445
    14461446        char filename [13];
     
    14971497        _mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_soundChannels[h].channelHandle, _currentSFX);
    14981498
    14991499        delete[] data;
    1500         return true;
     1500        return 1;
    15011501}
    15021502
    15031503void SoundTowns_v2::beginFadeOut() {
  • text_lok.cpp

     
    6262        if (chatDuration != -1)
    6363                chatDuration *= _tickLength;
    6464
    65         if (vocFile != -1) {
    66                 snd_voiceWaitForFinish();
     65        if (vocFile != -1)
    6766                snd_playVoiceFile(vocFile);
    68         }
    6967
    7068        _timer->disable(14);
    7169        _timer->disable(18);
     
    269267        if (_currentCharacter->sceneId == 210)
    270268                return;
    271269
     270        snd_voiceWaitForFinish(true);
     271
    272272        convoInitialized = initCharacterChat(charNum);
    273273        chatPartnerNum = getChatPartnerNum();
    274274
  • debugger.cpp

     
    192192
    193193Debugger_LoK::Debugger_LoK(KyraEngine_LoK *vm)
    194194        : Debugger(vm), _vm(vm) {
     195        DCmd_Register("enter",                          WRAP_METHOD(Debugger_LoK, cmd_enterRoom));
    195196        DCmd_Register("rooms",                          WRAP_METHOD(Debugger_LoK, cmd_listRooms));
    196197        DCmd_Register("give",                           WRAP_METHOD(Debugger_LoK, cmd_giveItem));
    197198        DCmd_Register("birthstones",            WRAP_METHOD(Debugger_LoK, cmd_listBirthstones));
  • sound.cpp

     
    6666        return false;
    6767}
    6868
    69 bool Sound::voicePlay(const char *file, bool isSfx) {
     69uint32 Sound::voicePlay(const char *file, bool isSfx) {
     70        uint32 playTime = 0;
    7071        char filenamebuffer[25];
    7172
    7273        int h = 0;
    7374        while (_mixer->isSoundHandleActive(_soundChannels[h].channelHandle) && h < kNumChannelHandles)
    7475                h++;
    7576        if (h >= kNumChannelHandles)
    76                 return false;
     77                return 0;
    7778
    7879        Audio::AudioStream *audioStream = 0;
    7980
     
    8586                if (!stream)
    8687                        continue;
    8788                audioStream = _supportedCodes[i].streamFunc(stream, true, 0, 0, 1);
     89                // HACK: implement proper playTime setup
     90                playTime = 1;
    8891                break;
    8992        }
    9093
     
    98101                        return false;
    99102
    100103                Common::MemoryReadStream vocStream(fileData, fileSize);
    101                 audioStream = Audio::makeVOCStream(vocStream);
     104                Audio::FixedLengthAudioStream *aStream = Audio::makeVOCStream(vocStream);
     105                playTime = aStream->getPlayTime();
     106                audioStream = aStream;
    102107
    103108                delete[] fileData;
    104109                fileSize = 0;
     
    107112        _soundChannels[h].file = file;
    108113        _mixer->playInputStream(isSfx ? Audio::Mixer::kSFXSoundType : Audio::Mixer::kSpeechSoundType, &_soundChannels[h].channelHandle, audioStream);
    109114
    110         return true;
     115        return playTime;
    111116}
    112117
    113118void Sound::voiceStop(const char *file) {
     
    140145        return res;
    141146}
    142147
     148uint32 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
    143160#pragma mark -
    144161
    145162SoundMidiPC::SoundMidiPC(KyraEngine_v1 *vm, Audio::Mixer *mixer, MidiDriver *driver) : Sound(vm, mixer) {
  • kyra_lok.h

     
    207207        void snd_voiceWaitForFinish(bool ingame = true);
    208208
    209209protected:
     210        uint32 _speechPlayTime;
     211
    210212        void saveGame(const char *fileName, const char *saveName);
    211213        void loadGame(const char *fileName);
    212214
  • sound.h

     
    176176         * @param isSfx marks file as sfx instead of voice
    177177         * @return channel the voice file is played on
    178178         */
    179         virtual bool voicePlay(const char *file, bool isSfx = false);
     179        virtual uint32 voicePlay(const char *file, bool isSfx = false);
    180180
    181181        /**
    182182         * Checks if a voice is being played.
     
    186186        bool voiceIsPlaying(const char *file = 0);
    187187
    188188        /**
     189         * Checks how long a voice has been playing
     190         *
     191         * @return time in milliseconds
     192         */
     193        uint32 voicePlayedTime(const char *file);
     194
     195        /**
    189196         * Stops playback of the current voice.
    190197         */
    191198        void voiceStop(const char *file = 0);
     
    449456        void haltTrack();
    450457        void beginFadeOut();
    451458
    452         bool voicePlay(const char *file, bool isSfx = false);
     459        uint32 voicePlay(const char *file, bool isSfx = false);
    453460        void playSoundEffect(uint8) {}
    454461
    455462private:
  • sound_lok.cpp

     
    6767        assert(id >= 0 && id < 9999);
    6868        sprintf(vocFile, "%03d", id);
    6969        _speechFile = vocFile;
    70         _sound->voicePlay(vocFile);
     70        _speechPlayTime = _sound->voicePlay(vocFile);
    7171}
    7272
    7373void KyraEngine_LoK::snd_voiceWaitForFinish(bool ingame) {
  • kyra_lok.cpp

     
    9191        memset(_panPagesTable, 0, sizeof(_panPagesTable));
    9292        memset(_sceneAnimTable, 0, sizeof(_sceneAnimTable));
    9393        _currHeadShape = 0;
     94        _speechPlayTime = 0;
    9495
    9596        memset(&_itemBkgBackUp, 0, sizeof(_itemBkgBackUp));
    9697}
  • text.cpp

     
    210210        calcWidestLineBounds(x1, x2, w, x);
    211211        _talkCoords.x = x1;
    212212        _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);
    214214        int curPage = _screen->_curPage;
    215215        _screen->_curPage = srcPage;
    216216        for (int i = 0; i < lineCount; ++i) {