Ticket #8058: cd-timer.diff

File cd-timer.diff, 4.5 KB (added by eriktorbjorn, 17 years ago)

Patch against a September 19 CVS snapshot

  • scummvm/scumm/saveload.cpp

    diff -ur ScummVM-cvs20020919/scummvm/scumm/saveload.cpp ScummVM-cvs20020919+hack/scummvm/scumm/saveload.cpp
    old new  
    159159
    160160        initBGBuffers(_scrHeight);
    161161
     162        _sound->resumeCDTimer();
     163
    162164        CHECK_HEAP debug(1, "State loaded from '%s'", filename);
    163165
    164166
  • scummvm/scumm/scummvm.cpp

    diff -ur ScummVM-cvs20020919/scummvm/scumm/scummvm.cpp ScummVM-cvs20020919+hack/scummvm/scumm/scummvm.cpp
    old new  
    331331
    332332int Scumm::scummLoop(int delta)
    333333{
    334         static int counter = 0;
    335 
    336334#ifndef _WIN32_WCE
    337335        if (_debugger)
    338336                _debugger->on_frame();
     
    371369        _vars[VAR_MOUSE_Y] = mouse.y;
    372370        _vars[VAR_DEBUGMODE] = _debugMode;
    373371
    374         if (_features & GF_AUDIOTRACKS) {               
    375                 if (delta) {
    376                         if (delta == 1) {
    377                                 // Better sync with the Loom CD intro
    378                                 _vars[VAR_MI1_TIMER]++;
    379                         } else if (++counter != 2)
    380                                 _vars[VAR_MI1_TIMER] += 5;
    381                         else {
    382                                 counter = 0;
    383                                 _vars[VAR_MI1_TIMER] += 6;
    384                         }                               
    385                 }
     372        if (_features & GF_AUDIOTRACKS) {
     373                _vars[VAR_MI1_TIMER] = _sound->readCDTimer();
    386374        } else if (_features & GF_OLD256) {
    387375
    388376                if(tempMusic == 3) {
  • scummvm/scumm/sound.cpp

    diff -ur ScummVM-cvs20020919/scummvm/scumm/sound.cpp ScummVM-cvs20020919+hack/scummvm/scumm/sound.cpp
    old new  
    10281028        return -1;
    10291029}
    10301030
     1031// We use a real timer in an attempt to get better sync with CD tracks. This is
     1032// necessary for games like Loom CD.
     1033
     1034static void cd_timer_handler(void *ptr)
     1035{
     1036        Scumm *scumm = (Scumm *) ptr;
     1037        scumm->_sound->_cd_timer_value += 5;
     1038}
     1039
     1040int Sound::readCDTimer()
     1041{
     1042        return _cd_timer_value;
     1043}
     1044
     1045void Sound::startCDTimer()
     1046{
     1047        int timer_interval;
     1048
     1049        // The timer interval has been tuned for Loom CD and the Monkey 1
     1050        // intro. I have to use 83 for Loom, or there will be a nasty stutter
     1051        // when Chaos first appears, and I have to use 84 for Monkey 1 or the
     1052        // intro music will be cut short.
     1053
     1054        if (_scumm->_gameId == GID_LOOM256)
     1055                timer_interval = 83;
     1056        else
     1057                timer_interval = 84;
     1058
     1059        _scumm->_timer->installProcedure(&cd_timer_handler, timer_interval);
     1060}
     1061
     1062void Sound::stopCDTimer()
     1063{
     1064        _cd_timer_value = 0;
     1065        _scumm->_timer->releaseProcedure(&cd_timer_handler);
     1066        if (_scumm->_features & GF_AUDIOTRACKS) {
     1067                _scumm->_vars[_scumm->VAR_MI1_TIMER] = 0;
     1068        }
     1069}
     1070
     1071void Sound::restartCDTimer()
     1072{
     1073        stopCDTimer();
     1074        startCDTimer();
     1075}
     1076
     1077void Sound::resumeCDTimer()
     1078{
     1079        // This function will be called after a savegame has been reloaded,
     1080        // in case we have to get the timer running again.
     1081
     1082        if ((_scumm->_features & GF_AUDIOTRACKS) && _scumm->_vars[_scumm->VAR_MI1_TIMER] > 0) {
     1083                _cd_timer_value = _scumm->_vars[_scumm->VAR_MI1_TIMER];
     1084                startCDTimer();
     1085        }
     1086}
     1087
    10311088void Sound::playCDTrack(int track, int num_loops, int start, int delay)
    10321089{
    10331090#ifdef COMPRESSED_SOUND_FILE
    10341091        if (playMP3CDTrack(track, num_loops, start, delay) == -1)
    10351092#endif
    10361093                _scumm->_system->play_cdrom(track, num_loops, start, delay);
     1094
     1095        // Start the timer after starting the track. Starting an MP3 track is
     1096        // almost instantaneous, but a CD player may take some time. Hopefully
     1097        // play_cdrom() will block during that delay.
     1098
     1099        restartCDTimer();
    10371100}
    10381101
    10391102void Sound::stopCD()
    10401103{
     1104        stopCDTimer();
    10411105#ifdef COMPRESSED_SOUND_FILE
    10421106        if (stopMP3CD() == -1)
    10431107#endif
  • scummvm/scumm/sound.h

    diff -ur ScummVM-cvs20020919/scummvm/scumm/sound.h ScummVM-cvs20020919+hack/scummvm/scumm/sound.h
    old new  
    2323
    2424#include "scummsys.h"
    2525#include "sound/mixer.h"
     26#include "common/timer.h"
    2627
    2728class Scumm;
    2829class File;
     
    8889
    8990#endif
    9091
     92        int _cd_timer_value;
    9193        bool _soundsPaused;
    9294        int16 _sound_volume_master, _sound_volume_music, _sound_volume_sfx;
    9395        byte _sfxMode;
     
    124126        int playSfxSound(void *sound, uint32 size, uint rate, bool isUnsigned);
    125127        int playSfxSound_MP3(void *sound, uint32 size);
    126128
     129        int readCDTimer();
     130        void startCDTimer();
     131        void stopCDTimer();
     132        void restartCDTimer();
     133        void resumeCDTimer();
     134
    127135        void playCDTrack(int track, int num_loops, int start, int delay);
    128136        void stopCD();
    129137        int pollCD();