Speed up mean calculation (?)

pull/357/head
nyanpasu64 2019-03-13 23:53:08 -07:00
rodzic 08458c8906
commit c8a598fe68
1 zmienionych plików z 5 dodań i 3 usunięć

Wyświetl plik

@ -140,7 +140,7 @@ class PostTrigger(_Trigger, ABC):
pass
@attr.dataclass
@attr.dataclass(slots=True)
class PerFrameCache:
"""
The estimated period of a wave region (Wave.get_around())
@ -154,6 +154,7 @@ class PerFrameCache:
# NOTE: period is a *non-subsampled* period.
# The period of subsampled data must be multiplied by stride.
period: Optional[int] = None
sum: Optional[float] = None # Only used in branch 'rewrite-area-trigger'
mean: Optional[float] = None
@ -343,10 +344,11 @@ class CorrelationTrigger(MainTrigger):
N = self._buffer_nsamp
cfg = self.cfg
# Get data
# Get data (1D, downmixed to mono)
stride = self._stride
data = self._wave.get_around(index, N, stride)
cache.mean = np.mean(data)
cache.sum = np.add.reduce(data)
cache.mean = cache.sum / N
data -= cache.mean
# Window data