Fast 12 bit to 16 bit sample conversion?
peter.heitzer at rz.uni-regensburg.de
Mon Jul 20 17:23:21 CEST 2015
MRAB <python at mrabarnett.plus.com> wrote:
>On 2015-07-20 14:10, Peter Heitzer wrote:
>> I am currently writing a python script to extract samples from old Roland 12 bit sample
>> disks and save them as 16 bit wav files.
>> The samples are layouted as follows
>> 0 [S0 bit 11..4] [S0 bit 3..0|S1 bit 3..0] [S1 bit 11..4]
>> 3 [S2 bit 11..4] [S2 bit 3..0|S3 bit 3..0] [S3 bit 11..4]
>> In other words
>> sample1=(data<<4)|(data & 0x0f)
>> I use this code for the conversion (using the struct module)
>> import struct
>> from array import array
>> def getWaveData(diskBuffer):
>> for i in range(len(diskBuffer)/3):
>If the 2 12-bit values are [0xABC, 0xDEF], the bytes will be [0xAB,
>This gives 0xABCF, which is ANDed to give 0xABC0. Good.
>This gives 0xDECF, which is ANDed to give 0xDEC0. Not what you want.
You are right! It looked to me as if it was little endian, but only for the MSB.
More information about the Python-list