Don't add slope finder if slope strength is disabled

This makes triggering slightly faster in the usual case where slope
triggering is disabled.
pull/403/head
nyanpasu64 2022-03-09 23:00:49 -08:00
rodzic 7b4910fd1e
commit 9d2a55e6d1
1 zmienionych plików z 13 dodań i 9 usunięć

Wyświetl plik

@ -409,20 +409,23 @@ class CorrelationTrigger(MainTrigger):
step *= windows.gaussian(self.A + self.B, std=self.A / 3)
return step
def _calc_slope_finder(self, period: float) -> np.ndarray:
def _calc_slope_finder(self, period: float) -> Optional[np.ndarray]:
"""Called whenever period changes substantially.
Returns a kernel to be correlated with input data to find positive slopes,
with length A+B."""
slope_finder = np.zeros(self.A + self.B)
cfg = self.cfg
slope_width = max(iround(cfg.slope_width * period), 1)
slope_strength = cfg.slope_strength * cfg.buffer_falloff
if cfg.slope_strength:
slope_finder = np.zeros(self.A + self.B)
slope_finder[self.A - slope_width : self.A] = -slope_strength
slope_finder[self.A : self.A + slope_width] = slope_strength
return slope_finder
slope_width = max(iround(cfg.slope_width * period), 1)
slope_strength = cfg.slope_strength * cfg.buffer_falloff
slope_finder[self.A - slope_width : self.A] = -slope_strength
slope_finder[self.A : self.A + slope_width] = slope_strength
return slope_finder
else:
return None
# end setup
@ -482,7 +485,8 @@ class CorrelationTrigger(MainTrigger):
# array[A+B] Amplitude
corr_kernel: np.ndarray = self._corr_buffer * self.cfg.buffer_strength
corr_kernel += self._edge_finder
corr_kernel += slope_finder
if slope_finder is not None:
corr_kernel += slope_finder
# Don't pick peaks more than `period * trigger_radius_periods` away from the
# center.