/****************************************************************************
 * 
 * twiddlify.c : generate twiddle factor table in .dat format
 * Dan R. K. Ports  <drkp@mit.edu>
 * 6.111 final project, 2003/12/04
 *
 **************************************************************************/

#define pi 3.141592653589793

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char **argv)
{
	int i;
	double theta;
	double s,c;
	int N;
	int gensin = 0;

	N = strtol(argv[1], NULL, 0);
	if (argv[2][0] == 's') gensin = 1;

	for (i = 0; i < N; i++)
	{
		theta = ((double)-2) * pi * ((double) i) / ((double)N);
		s = sin(theta) * 128;
		c = cos(theta) * 128;
		if (s >= 127) s = 127;
		if (c >= 127) c = 127;
		if ((s < 0) && (s > -1)) s = 0;
		if ((c < 0) && (c > -1)) c = 0;
		if (s < 0) s = 0xFF + s + 1;
		if (c < 0) c = 0xFF + c + 1;
		if (gensin)
		 printf("%02X\n", (int)s);
		else
	  	 printf("%02X\n", (int)c);
	}
}
		

