gba-trycatch

view src/sincos.c @ 3:8e9225853d75

added sincos luts
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Jun 2014 01:56:58 +0300
parents
children 78d1664c2443
line source
1 #include <math.h>
2 #include "sincos.h"
3 #include "logger.h"
5 void sincos_init(void)
6 {
7 int i;
9 logmsg(LOG_ALL, "calculating sin/cos lut...\n");
11 for(i=0; i<SINLUT_SIZE; i++) {
12 float angle = 2.0 * M_PI * ((float)i / (float)SINLUT_SIZE);
13 float val = sin(angle);
14 sinlut[i] = (int16_t)(val * SINLUT_SCALE);
15 }
16 }
18 int16_t sin_int(int16_t norm_angle)
19 {
20 norm_angle %= SINLUT_SIZE;
21 if(norm_angle < 0) {
22 norm_angle += SINLUT_SIZE;
23 }
24 return sinlut[norm_angle];
25 }
27 int16_t cos_int(int16_t norm_angle)
28 {
29 return sin_int(norm_angle + SINLUT_SIZE / 4);
30 }
32 int32_t sin_x16(int32_t radians)
33 {
34 int32_t na = (radians << 16) / (M_PI_X16 * 2);
35 return sin_int((na >> 8) * (SINLUT_SIZE << 8));
36 }
38 int32_t cos_x16(int32_t radians)
39 {
40 int32_t na = (radians << 16) / (M_PI_X16 * 2);
41 return cos_int((na >> 8) * (SINLUT_SIZE << 8));
42 }