具有“奇数”数据长度的24位样本

2024-04-20 10:52:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用pythonscipy.io.wavfile读取24位wav文件。我知道wavfile有关于24位的问题,我手动集成了Warren在问题中建议的解决方案。实际上,代码中的更新包括将字节3乘3分组并计算24位整数(下面的代码改编自Warren Weckesser):

if bit_depth not in (8, 16, 32, 64, 96, 128):
    # first read byte per byte

    data = numpy.fromfile(fid, dtype='u1')
    for i in range(len(data) % 3):
        data = numpy.delete(data, len(data) - 1)
        # or data = numpy.delete(data, 0)?
    a = numpy.empty((int(len(data)/3), 4), dtype='u1')
    #print(data.shape)
    a[:, :3] = data.reshape((-1, 3))
    a[:, 3:] = (a[:, 3 - 1:3] >> 7) * 255
    data = a.view('<i4').reshape(a.shape[:-1])

一些wav样本报告24位深度,但实际数据不是3的倍数(例如2138890字节)。这让我困惑:有没有wavfile不跳过的元数据?我应该从数组中删除一些字节吗?从开始到结束?有人遇到同样的问题吗?你知道吗

提前谢谢!你知道吗


Tags: 代码innumpydatalen字节bytedelete