gba-x3dtest

view src/sincos.c @ 4:78d1664c2443

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