This commit is contained in:
2021-11-13 00:22:24 +01:00
parent bf62ceb98f
commit 6df8a7344d
4 changed files with 55 additions and 9 deletions

View File

@@ -188,11 +188,11 @@ impl BeatTracker {
let mut prev = now - Duration::from_millis(dt as u64);
let period_millis = (period_length * MILLIS_PER_POINT) as u64;
let period = Duration::from_millis(period_millis);
let mut next = prev + period;
if let Some((_, old_next)) = self.current_beats {
while next < old_next + Duration::from_millis(period_millis / 2) {
prev += period;
@@ -209,12 +209,16 @@ impl BeatTracker {
let (prev, next) = self.current_beats.unwrap();
let fractional = if prev < now {
(now - prev).as_millis() as f64 / (next - prev).as_millis() as f64
let mut relative_millis = if prev < now {
(now - prev).as_millis() as f64
} else {
-1.0 * (prev - now).as_millis() as f64 / (next - prev).as_millis() as f64
-1.0 * (prev - now).as_millis() as f64
};
relative_millis += self.config.zero_crossing_beat_delay as f64;
let fractional = relative_millis / (next - prev).as_millis() as f64;
Some(self.beat_count as f64 + fractional)
}