diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-12-20 16:08:44 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-12-20 16:08:44 +0100 |
commit | 5722e047c488529bfa50fa63ff02672aa3ca3088 (patch) | |
tree | dd18ed5000d1010617e5310b751eb7980f11094c /src | |
parent | 004005688eff68d12043cc388146af30819f4b00 (diff) | |
download | trriggy-5722e047c488529bfa50fa63ff02672aa3ca3088.tar.gz trriggy-5722e047c488529bfa50fa63ff02672aa3ca3088.tar.bz2 trriggy-5722e047c488529bfa50fa63ff02672aa3ca3088.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 11 |
1 files 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; } |