def peak(self):
"""Calculate peak sample value (with sign)"""
if len(self.samples) != 0:
if np.issubdtype(self.samples.dtype, float):
idx = np.absolute(self.samples).argmax(axis=0)
else:
# We have to be careful when checking two's complement since the absolute value
# of the smallest possible value can't be represented without overflowing. For
# example: signed 16bit has range [-32768, 32767] so abs(-32768) cannot be
# represented in signed 16 bits --> use a bigger datatype
bigger = np.asarray(self.samples, dtype=np.int64)
idx = np.absolute(bigger).argmax(axis=0)
peak = np.array([self.samples[row,col] for col, row in enumerate(idx)])
else:
# no samples are set but channels are configured
idx = np.zeros(self.ch, dtype=np.int64)
peak = np.zeros(self.ch)
peak[:] = float('nan')
return peak, idx
评论列表
文章目录