Convert 16-bit wav file to 12-bit raw audio file I want to convert a 16-bit wav file to 12 bit raw audio samples (to simulate the output of an ADC). 

I'm trying to run 

$ sox file.wav --bits 12 --encoding signed-integer --endian little 12_bit_signed_le/file.raw


And I get the error 

sox WARN formats: raw can't encode Signed Integer PCM to 12-bit

Output File    : '12_bit_signed_le/file.raw'
Channels       : 1
Sample Rate    : 4410
Precision      : 16-bit
Duration       : 00:59:53.47 = 15847219 samples ~ 269511 CDDA sectors
Sample Encoding: 16-bit Signed Integer PCM
Endian Type    : little
Reverse Nibbles: no
Reverse Bits   : no
Comment        : 'Processed by SoX'

sox INFO sox: effects chain: input         4410Hz  1 channels
sox INFO sox: effects chain: output        4410Hz  1 channels


As you can see, the command resulted in 16-bit output. How do I force it to truncate to 12 bits? 

Also, do I need to be worried about clipping (as this post suggests?)
Sox will not support bit widths for wav files other than multiples of bytes. If you really need such unusual binary format then I suggest to write a short Python program that packs values in arbitrary format. Just please keep in mind that the maximum amplitude will be 2047 (instead of 32767 as for 16 bits).