Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Peter Heitzer" Newsgroups: comp.lang.python Subject: Fast 12 bit to 16 bit sample conversion? Date: 20 Jul 2015 13:10:10 GMT Lines: 37 Message-ID: X-Trace: individual.net OFddNDv4F2ZkphtnJhe9sAo+gonyVn3tFVaTRX4wHc9BxOkJXJZtBiWUpC X-Orig-Path: not-for-mail Cancel-Lock: sha1:Jogo+hZ9PRTAdlxO/0rgYWXllVA= User-Agent: tin/2.2.1-20140504 ("Tober an Righ") (UNIX) (Linux/3.16.0-4-amd64 (x86_64)) Xref: csiph.com comp.lang.python:94233 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 sample0=(data[0]<<4)|(data[1]>>4) sample1=(data[2]<<4)|(data[1] & 0x0f) I use this code for the conversion (using the struct module) import struct from array import array def getWaveData(diskBuffer): offset=0 words=array('H') for i in range(len(diskBuffer)/3): h0=struct.unpack_from('>h',diskBuffer,offset) h1=struct.unpack_from('hxhxhxhx' for 4 even samples and '