use core::hint::unreachable_unchecked;
#[derive(Copy, Clone)]
pub struct SamplingRate {
divisor: u32,
counter: u32,
}
impl SamplingRate {
pub const fn new(divisor: u32) -> Self {
assert!(divisor > 0);
Self {
divisor,
counter: 0,
}
}
pub fn step(&mut self) -> bool {
if self.divisor == 0 {
unsafe { unreachable_unchecked() };
}
self.counter += 1;
self.counter %= self.divisor;
self.counter == 0
}
pub fn div(&mut self, ratio: u32) {
assert!(ratio > 0);
self.divisor *= ratio;
}
pub fn divisor(&self) -> u32 {
self.divisor
}
}