本文整理汇总了Python中audiotools.bitstream.BitstreamReader.unread方法的典型用法代码示例。如果您正苦于以下问题:Python BitstreamReader.unread方法的具体用法?Python BitstreamReader.unread怎么用?Python BitstreamReader.unread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类audiotools.bitstream.BitstreamReader
的用法示例。
在下文中一共展示了BitstreamReader.unread方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from audiotools.bitstream import BitstreamReader [as 别名]
# 或者: from audiotools.bitstream.BitstreamReader import unread [as 别名]
#.........这里部分代码省略.........
#if history gets too small, we may have a block of 0 samples
#which can be compressed more efficiently
if ((history < 128) and ((i + 1) < sample_count)):
zeroes_k = min(7 -
log2(history) +
((history + 16) / 64),
self.maximum_k)
zero_residuals = self.read_residual(zeroes_k, 16)
if (zero_residuals > 0):
residuals.extend([0] * zero_residuals)
i += zero_residuals
history = 0
if (zero_residuals <= 0xFFFF):
sign_modifier = 1
i += 1
return residuals
def read_residual(self, k, sample_size):
msb = self.reader.limited_unary(0, 9)
if (msb is None):
return self.reader.read(sample_size)
elif (k == 0):
return msb
else:
lsb = self.reader.read(k)
if (lsb > 1):
return msb * ((1 << k) - 1) + (lsb - 1)
elif (lsb == 1):
self.reader.unread(1)
return msb * ((1 << k) - 1)
else:
self.reader.unread(0)
return msb * ((1 << k) - 1)
def decode_subframe(self, qlp_shift_needed, qlp_coefficients,
sample_size, residuals):
#first sample is always copied verbatim
samples = [residuals.pop(0)]
if (len(qlp_coefficients) < 31):
#the next "coefficient count" samples
#are applied as differences to the previous
for i in xrange(len(qlp_coefficients)):
samples.append(truncate_bits(samples[-1] + residuals.pop(0),
sample_size))
#remaining samples are processed much like LPC
for residual in residuals:
base_sample = samples[-len(qlp_coefficients) - 1]
lpc_sum = sum([(s - base_sample) * c for (s, c) in
zip(samples[-len(qlp_coefficients):],
reversed(qlp_coefficients))])
outval = (1 << (qlp_shift_needed - 1)) + lpc_sum
outval >>= qlp_shift_needed
samples.append(truncate_bits(outval + residual + base_sample,
sample_size))
buf = samples[-len(qlp_coefficients) - 2:-1]
#error value then adjusts the coefficients table
if (residual > 0):