From 5722e047c488529bfa50fa63ff02672aa3ca3088 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 20 Dec 2018 16:08:44 +0100 Subject: Adjust the trigger thresholds, and require rising edge. Instead of just relying on the value of the average to be high, this algorithm requires that the current sample amplitude is significantly higher than the average. While an extremely naive algorithm, it seems to work well on my sample basdrum track from one of my bands songs. All beats were detected, no false beats, and quite minimal lag. I should probably make the trigger thresholds configurable. --- src/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 063db5f..e60ee45 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,13 +42,20 @@ impl Trigger { let mut res = 0i16; let abs = sample.abs() as u32; + let div = if (abs > self.acc) { + abs - self.acc + } + else { + 0 + }; + self.acc = (self.acc + abs) / 2; - if !self.trigged && self.acc > 1000 { + if !self.trigged && div > 5000 { self.trigged = true; self.playing = true; self.sample_pos = 0; } - else if self.trigged && self.acc < 50 { + else if self.trigged && self.acc < 250 { self.trigged = false; } -- cgit v1.2.3