audio.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:zignal 作者: ronnyandersson 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号