decoder.py 文件源码

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

项目:goldmine 作者: Armored-Dragon 项目源码 文件源码
def decode(decoder, data, length, frame_size, decode_fec, channels=2):
    """Decode an Opus frame

    Unlike the `opus_decode` function , this function takes an additional
    parameter `channels`, which indicates the number of channels in the frame
    """

    pcm_size = frame_size * channels * ctypes.sizeof(ctypes.c_int16)
    pcm = (ctypes.c_int16 * pcm_size)()
    pcm_pointer = ctypes.cast(pcm, opuslib.api.c_int16_pointer)

    # Converting from a boolean to int
    decode_fec = int(bool(decode_fec))

    try:
        result = _decode(
            decoder, data, length, pcm_pointer, frame_size, decode_fec)
    except ctypes.ArgumentError:
        result = _decode(
            decoder, bytes(data.encode('latin-1')), length, pcm_pointer,
            frame_size, decode_fec)
    if result < 0:
        raise opuslib.exceptions.OpusError(result)

    return array.array('h', pcm[:result * channels]).tostring()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号