2010-08-09 13:28:56 +00:00
|
|
|
//counter_rate = number of samples per counter event
|
|
|
|
//all rates are evenly divisible by counter_range (0x7800, 30720, or 2048 * 5 * 3)
|
|
|
|
//note that rate[0] is a special case, which never triggers
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
const uint16 DSP::CounterRate[32] = {
|
2010-08-09 13:28:56 +00:00
|
|
|
0, 2048, 1536,
|
|
|
|
1280, 1024, 768,
|
|
|
|
640, 512, 384,
|
|
|
|
320, 256, 192,
|
|
|
|
160, 128, 96,
|
|
|
|
80, 64, 48,
|
|
|
|
40, 32, 24,
|
|
|
|
20, 16, 12,
|
|
|
|
10, 8, 6,
|
|
|
|
5, 4, 3,
|
|
|
|
2,
|
|
|
|
1,
|
|
|
|
};
|
|
|
|
|
|
|
|
//counter_offset = counter offset from zero
|
|
|
|
//counters do not appear to be aligned at zero for all rates
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
const uint16 DSP::CounterOffset[32] = {
|
2010-08-09 13:28:56 +00:00
|
|
|
0, 0, 1040,
|
|
|
|
536, 0, 1040,
|
|
|
|
536, 0, 1040,
|
|
|
|
536, 0, 1040,
|
|
|
|
536, 0, 1040,
|
|
|
|
536, 0, 1040,
|
|
|
|
536, 0, 1040,
|
|
|
|
536, 0, 1040,
|
|
|
|
536, 0, 1040,
|
|
|
|
536, 0, 1040,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
inline auto DSP::counterTick() -> void {
|
2010-08-09 13:28:56 +00:00
|
|
|
state.counter--;
|
2015-10-10 02:16:12 +00:00
|
|
|
if(state.counter < 0) state.counter = CounterRange - 1;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//return true if counter event should trigger
|
|
|
|
|
2016-03-29 09:15:01 +00:00
|
|
|
inline auto DSP::counterPoll(uint rate) -> bool {
|
2010-08-09 13:28:56 +00:00
|
|
|
if(rate == 0) return false;
|
2016-03-29 09:15:01 +00:00
|
|
|
return (((uint)state.counter + CounterOffset[rate]) % CounterRate[rate]) == 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|