def rms(self):
"""Calculate the RMS (Root Mean Square) value of the audio
data. Returns the RMS value for each individual channel
"""
if not (self.samples == 0).all():
if np.issubdtype(self.samples.dtype, float):
rms = np.sqrt(np.mean(np.power(self.samples, 2), axis=0))
else:
# use a bigger datatype for ints since we most likely will
# overflow when calculating to the power of 2
bigger = np.asarray(self.samples, dtype=np.int64)
rms = np.sqrt(np.mean(np.power(bigger, 2), axis=0))
elif len(self.samples) == 0:
# no samples are set but channels are configured
rms = np.zeros(self.ch)
rms[:] = float('nan')
else:
rms = np.zeros(self.ch)
return rms
评论列表
文章目录