Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/dsp/counter.cpp
2 views
1
#ifdef DSP_CPP
2
3
//counter_rate = number of samples per counter event
4
//all rates are evenly divisible by counter_range (0x7800, 30720, or 2048 * 5 * 3)
5
//note that rate[0] is a special case, which never triggers
6
7
const uint16 DSP::counter_rate[32] = {
8
0, 2048, 1536,
9
1280, 1024, 768,
10
640, 512, 384,
11
320, 256, 192,
12
160, 128, 96,
13
80, 64, 48,
14
40, 32, 24,
15
20, 16, 12,
16
10, 8, 6,
17
5, 4, 3,
18
2,
19
1,
20
};
21
22
//counter_offset = counter offset from zero
23
//counters do not appear to be aligned at zero for all rates
24
25
const uint16 DSP::counter_offset[32] = {
26
0, 0, 1040,
27
536, 0, 1040,
28
536, 0, 1040,
29
536, 0, 1040,
30
536, 0, 1040,
31
536, 0, 1040,
32
536, 0, 1040,
33
536, 0, 1040,
34
536, 0, 1040,
35
536, 0, 1040,
36
0,
37
0,
38
};
39
40
inline void DSP::counter_tick() {
41
state.counter--;
42
if(state.counter < 0) state.counter = counter_range - 1;
43
}
44
45
//return true if counter event should trigger
46
47
inline bool DSP::counter_poll(unsigned rate) {
48
if(rate == 0) return false;
49
return (((unsigned)state.counter + counter_offset[rate]) % counter_rate[rate]) == 0;
50
}
51
52
#endif
53
54