rotation
[voxscape] / src / lut.c
1 #include <stdio.h>
2 #include <math.h>
3 #include "lut.h"
4
5 /*#include "sintab.h"*/
6
7 #undef WRITE_C
8
9 #ifndef SINTAB_DATA_H_
10 int32_t sintab[SINTAB_SIZE];
11 #endif
12
13 void init_lut(void)
14 {
15 #ifndef SINTAB_DATA_H_
16         int i;
17         float t, theta;
18
19 #ifdef WRITE_C
20         int col = 4;
21         FILE *fp = fopen("sintab.h", "wb");
22         if(fp) {
23                 fprintf(fp, "#ifndef SINTAB_DATA_H_\n");
24                 fprintf(fp, "#define SINTAB_DATA_H_\n\n");
25                 fprintf(fp, "int32_t sintab[] = {\n\t");
26         }
27 #endif
28
29         for(i=0; i<SINTAB_SIZE; i++) {
30                 t = (float)i / SINTAB_SIZE;
31                 theta = t * (M_PI * 2);
32                 sintab[i] = (int32_t)(sin(theta) * 65536.0f);
33 #ifdef WRITE_C
34                 if(fp) {
35                         col += fprintf(fp, "%ld", (long)sintab[i]);
36                         if(i < SINTAB_SIZE - 1) {
37                                 if(col >= 72) {
38                                         fprintf(fp, ",\n\t");
39                                         col = 4;
40                                 } else {
41                                         col += fprintf(fp, ", ");
42                                 }
43                         } else {
44                                 fprintf(fp, "\n");
45                         }
46                 }
47 #endif
48         }
49
50 #ifdef WRITE_C
51         if(fp) {
52                 fprintf(fp, "};\n\n");
53                 fprintf(fp, "#endif\t/* SINTAB_DATA_H_ */\n");
54                 fclose(fp);
55         }
56 #endif
57 #endif  /* !defined SINTAB_DATA_H_ */
58 }