ScummVM API documentation
native_sound_timer.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef MADS_CORE_NATIVE_SOUND_TIMER_H
23 #define MADS_CORE_NATIVE_SOUND_TIMER_H
24 
25 #include "common/scummsys.h"
26 
27 namespace MADS {
28 
34 public:
35  enum {
36  kPitClockHz = 1193182,
37  kHostTimerDivisor = 0x07a8,
38  kHostServiceDivider = 2,
39  kSequenceServiceDivider = 5
40  };
41 
42  NativeSoundTimer() : _accumulator(0), _pollCountdown(1) {
43  }
44 
49  uint32 advance(uint64 elapsedUnits, uint64 unitsPerSecond) {
50  const uint64 serviceThreshold = unitsPerSecond *
51  kHostTimerDivisor * kHostServiceDivider;
52 
53  _accumulator += elapsedUnits * kPitClockHz;
54  const uint32 serviceTicks = _accumulator / serviceThreshold;
55  _accumulator %= serviceThreshold;
56  return serviceTicks;
57  }
58 
62  bool pollDue() {
63  if (--_pollCountdown)
64  return false;
65 
66  _pollCountdown = kSequenceServiceDivider;
67  return true;
68  }
69 
70 private:
71  uint64 _accumulator;
72  byte _pollCountdown;
73 };
74 
75 } // namespace MADS
76 
77 #endif
uint32 advance(uint64 elapsedUnits, uint64 unitsPerSecond)
Definition: native_sound_timer.h:49
Definition: native_sound_timer.h:33
bool pollDue()
Definition: native_sound_timer.h:62
Definition: anim_timer.h:27