当前位置: 首页>>代码示例>>Python>>正文


Python BitstreamReader.read_huffman_code方法代码示例

本文整理汇总了Python中audiotools.bitstream.BitstreamReader.read_huffman_code方法的典型用法代码示例。如果您正苦于以下问题:Python BitstreamReader.read_huffman_code方法的具体用法?Python BitstreamReader.read_huffman_code怎么用?Python BitstreamReader.read_huffman_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在audiotools.bitstream.BitstreamReader的用法示例。


在下文中一共展示了BitstreamReader.read_huffman_code方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ALACDecoder

# 需要导入模块: from audiotools.bitstream import BitstreamReader [as 别名]
# 或者: from audiotools.bitstream.BitstreamReader import read_huffman_code [as 别名]

#.........这里部分代码省略.........
                residuals.append(-((unsigned + 1) // 2))
            else:
                residuals.append(unsigned // 2)

            # update history based on unsigned residual
            if unsigned <= 0xFFFF:
                history += ((unsigned * self.history_multiplier) -
                            ((history * self.history_multiplier) >> 9))
            else:
                history = 0xFFFF

            # 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.read_huffman_code(RESIDUAL)
        if msb == -1:
            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 range(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):],
开发者ID:brigittebigi,项目名称:sppas,代码行数:70,代码来源:alac.py


注:本文中的audiotools.bitstream.BitstreamReader.read_huffman_code方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。