rotation
[voxscape] / src / lut.c
diff --git a/src/lut.c b/src/lut.c
new file mode 100644 (file)
index 0000000..895d84f
--- /dev/null
+++ b/src/lut.c
@@ -0,0 +1,58 @@
+#include <stdio.h>
+#include <math.h>
+#include "lut.h"
+
+/*#include "sintab.h"*/
+
+#undef WRITE_C
+
+#ifndef SINTAB_DATA_H_
+int32_t sintab[SINTAB_SIZE];
+#endif
+
+void init_lut(void)
+{
+#ifndef SINTAB_DATA_H_
+       int i;
+       float t, theta;
+
+#ifdef WRITE_C
+       int col = 4;
+       FILE *fp = fopen("sintab.h", "wb");
+       if(fp) {
+               fprintf(fp, "#ifndef SINTAB_DATA_H_\n");
+               fprintf(fp, "#define SINTAB_DATA_H_\n\n");
+               fprintf(fp, "int32_t sintab[] = {\n\t");
+       }
+#endif
+
+       for(i=0; i<SINTAB_SIZE; i++) {
+               t = (float)i / SINTAB_SIZE;
+               theta = t * (M_PI * 2);
+               sintab[i] = (int32_t)(sin(theta) * 65536.0f);
+#ifdef WRITE_C
+               if(fp) {
+                       col += fprintf(fp, "%ld", (long)sintab[i]);
+                       if(i < SINTAB_SIZE - 1) {
+                               if(col >= 72) {
+                                       fprintf(fp, ",\n\t");
+                                       col = 4;
+                               } else {
+                                       col += fprintf(fp, ", ");
+                               }
+                       } else {
+                               fprintf(fp, "\n");
+                       }
+               }
+#endif
+       }
+
+#ifdef WRITE_C
+       if(fp) {
+               fprintf(fp, "};\n\n");
+               fprintf(fp, "#endif\t/* SINTAB_DATA_H_ */\n");
+               fclose(fp);
+       }
+#endif
+#endif /* !defined SINTAB_DATA_H_ */
+}