# HG changeset patch # User John Tsiombikas # Date 1402700218 -10800 # Node ID 8e9225853d7518c09fe529099e7cd43ffe1fd384 # Parent 5143908d0220a9b89abde9157bd82937188ba256 added sincos luts diff -r 5143908d0220 -r 8e9225853d75 src/sincos.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sincos.c Sat Jun 14 01:56:58 2014 +0300 @@ -0,0 +1,42 @@ +#include +#include "sincos.h" +#include "logger.h" + +void sincos_init(void) +{ + int i; + + logmsg(LOG_ALL, "calculating sin/cos lut...\n"); + + for(i=0; i> 8) * (SINLUT_SIZE << 8)); +} + +int32_t cos_x16(int32_t radians) +{ + int32_t na = (radians << 16) / (M_PI_X16 * 2); + return cos_int((na >> 8) * (SINLUT_SIZE << 8)); +} diff -r 5143908d0220 -r 8e9225853d75 src/sincos.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sincos.h Sat Jun 14 01:56:58 2014 +0300 @@ -0,0 +1,27 @@ +#ifndef SINCOS_H_ +#define SINCOS_H_ + +#include + +#define M_PI_X16 (int32_t)(M_PI * 65536.0) +/*#define M_PI_X16 (int32_t)((31416 << 16) / 10000)*/ + +#define SINLUT_SCALE 512 +#define SINLUT_SIZE 512 +int16_t sinlut[SINLUT_SIZE]; + +void sincos_init(void); + +/* takes angle in [0, SINLUT_SIZE] and returns: + * sin(2 * angle / SINLUT_SIZE / pi) * SINLUT_SCALE + */ +int16_t sin_int(int16_t norm_angle); +int16_t cos_int(int16_t norm_angle); + +/* takes angle in fixed point 16.16 radians [0, 2pi << 16] + * and returns 16.16 fixed point in [-1 << 16, 1 << 16] + */ +int32_t sin_x16(int32_t radians); +int32_t cos_x16(int32_t radians); + +#endif /* SINCOS_H_ */