/* 16to12--float to short for 12-bit DAC
 * 16to12 < infile > outfile
 */
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#define  DAC12 2047 /* 2^12 / 2 - 1 */
#define  DAC16 32767 /* 2^16 / 2 - 1 */

main()
{
    short x;
    short y;
    setmode(fileno(stdin), O_BINARY);
    setmode(fileno(stdout), O_BINARY);

    while (fread((char *)&x, sizeof(short), 1, stdin))
    {     y = (float)x / DAC16 * DAC12;
          fwrite((char *)&y, sizeof(short), 1, stdout);
    }
}
