/*
 * Float2fix.c -- read floating-point values from stdin and write integers
 * onto stdout
 */

#include <stdio.h>

main(argc, argv) int argc; char *argv[]; {
	short  s;
	float  f;

	if (isatty(1) == 1) {
		fprintf(stderr, "%s\n\t%s\n",
			"float2fix usage: float2fix < binary_floats > 16-bit_fixed",
			"(input samples outside range -1.0 to +1.0 are clipped)");
		exit(-1);
	}
	while (fread(&f, sizeof(float), 1, stdin) != 0) {
		if (f > 1.0)
			f = 1.0;
		else if (f < -1.0)
			f = -1.0;
		s = f * 32767.0;
		fwrite(&s, sizeof(short), 1, stdout);
	}
}
