plugins code cleanup : moved the duplicated fixed point table loockup based sinus/cosinus functions to fixedpoint.c, removed the bmp size definition in the clock.c|-(useless as the size is already defined in a .h generated with every bitmaps ...)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14087 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
4e8b171fc4
commit
df4f56b2b0
6 changed files with 118 additions and 378 deletions
|
@ -20,11 +20,13 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "plugin.h"
|
||||
#include "xlcd.h"
|
||||
#include "pluginlib_actions.h"
|
||||
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
|
||||
#include "xlcd.h"
|
||||
#include "pluginlib_actions.h"
|
||||
#include "fixedpoint.h"
|
||||
|
||||
PLUGIN_HEADER
|
||||
|
||||
/* files */
|
||||
|
@ -1278,71 +1280,6 @@ struct game_context {
|
|||
struct tile playboard[BB_HEIGHT][BB_WIDTH];
|
||||
};
|
||||
|
||||
/*
|
||||
* Precalculated sine and cosine * 16384 (fixed point 18.14)
|
||||
* Borrowed from cube.c plugin
|
||||
*/
|
||||
static const short sin_table[91] = {
|
||||
0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563,
|
||||
2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334,
|
||||
5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943,
|
||||
8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310,
|
||||
10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365,
|
||||
12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043,
|
||||
14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295,
|
||||
15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082,
|
||||
16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381,
|
||||
16384
|
||||
};
|
||||
|
||||
static long sin(int val) {
|
||||
val = (val+360)%360;
|
||||
|
||||
if(val < 181) {
|
||||
if(val < 91) {
|
||||
/* phase 0-90 degree */
|
||||
return (long)sin_table[val];
|
||||
} else {
|
||||
/* phase 91-180 degree */
|
||||
return (long)sin_table[180-val];
|
||||
}
|
||||
} else {
|
||||
if(val < 271) {
|
||||
/* phase 181-270 degree */
|
||||
return -(long)sin_table[val-180];
|
||||
} else {
|
||||
/* phase 270-359 degree */
|
||||
return -(long)sin_table[360-val];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long cos(int val) {
|
||||
val = (val+360)%360;
|
||||
|
||||
if(val < 181) {
|
||||
if(val < 91) {
|
||||
/* phase 0-90 degree */
|
||||
return (long)sin_table[90-val];
|
||||
} else {
|
||||
/* phase 91-180 degree */
|
||||
return -(long)sin_table[val-90];
|
||||
}
|
||||
} else {
|
||||
if(val < 271) {
|
||||
/* phase 181-270 degree */
|
||||
return -(long)sin_table[270-val];
|
||||
} else {
|
||||
/* phase 270-359 degree */
|
||||
return (long)sin_table[val-270];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void bubbles_init(struct game_context* bb);
|
||||
static bool bubbles_nextlevel(struct game_context* bb);
|
||||
static void bubbles_getonboard(struct game_context* bb);
|
||||
|
@ -1553,17 +1490,17 @@ static void bubbles_drawboard(struct game_context* bb) {
|
|||
ROW_HEIGHT*(BB_HEIGHT-2)+BUBBLE_HEIGHT);
|
||||
|
||||
/* draw arrow */
|
||||
tipx = SHOTX+BUBBLE_WIDTH/2+(((sin(bb->angle)>>4)*BUBBLE_WIDTH*3/2)>>10);
|
||||
tipy = SHOTY+BUBBLE_HEIGHT/2-(((cos(bb->angle)>>4)*BUBBLE_HEIGHT*3/2)>>10);
|
||||
tipx = SHOTX+BUBBLE_WIDTH/2+(((sin_int(bb->angle)>>4)*BUBBLE_WIDTH*3/2)>>10);
|
||||
tipy = SHOTY+BUBBLE_HEIGHT/2-(((cos_int(bb->angle)>>4)*BUBBLE_HEIGHT*3/2)>>10);
|
||||
|
||||
rb->lcd_drawline(SHOTX+BUBBLE_WIDTH/2+(((sin(bb->angle)>>4)*BUBBLE_WIDTH/2)>>10),
|
||||
SHOTY+BUBBLE_HEIGHT/2-(((cos(bb->angle)>>4)*BUBBLE_HEIGHT/2)>>10),
|
||||
rb->lcd_drawline(SHOTX+BUBBLE_WIDTH/2+(((sin_int(bb->angle)>>4)*BUBBLE_WIDTH/2)>>10),
|
||||
SHOTY+BUBBLE_HEIGHT/2-(((cos_int(bb->angle)>>4)*BUBBLE_HEIGHT/2)>>10),
|
||||
tipx, tipy);
|
||||
xlcd_filltriangle(tipx, tipy,
|
||||
tipx+(((sin(bb->angle-135)>>4)*BUBBLE_WIDTH/3)>>10),
|
||||
tipy-(((cos(bb->angle-135)>>4)*BUBBLE_HEIGHT/3)>>10),
|
||||
tipx+(((sin(bb->angle+135)>>4)*BUBBLE_WIDTH/3)>>10),
|
||||
tipy-(((cos(bb->angle+135)>>4)*BUBBLE_HEIGHT/3)>>10));
|
||||
tipx+(((sin_int(bb->angle-135)>>4)*BUBBLE_WIDTH/3)>>10),
|
||||
tipy-(((cos_int(bb->angle-135)>>4)*BUBBLE_HEIGHT/3)>>10),
|
||||
tipx+(((sin_int(bb->angle+135)>>4)*BUBBLE_WIDTH/3)>>10),
|
||||
tipy-(((cos_int(bb->angle+135)>>4)*BUBBLE_HEIGHT/3)>>10));
|
||||
|
||||
/* draw text */
|
||||
rb->lcd_getstringsize(level, &w, &h);
|
||||
|
@ -1608,8 +1545,8 @@ static int bubbles_fire(struct game_context* bb) {
|
|||
|
||||
/* get current bubble */
|
||||
bubblecur = bb->queue[bb->nextinq];
|
||||
shotxinc = ((sin(bb->angle)>>4)*BUBBLE_WIDTH)/3;
|
||||
shotyinc = ((-1*(cos(bb->angle)>>4))*BUBBLE_HEIGHT)/3;
|
||||
shotxinc = ((sin_int(bb->angle)>>4)*BUBBLE_WIDTH)/3;
|
||||
shotyinc = ((-1*(cos_int(bb->angle)>>4))*BUBBLE_HEIGHT)/3;
|
||||
shotxofs = shotyofs = 0;
|
||||
|
||||
/* advance the queue */
|
||||
|
|
|
@ -93,125 +93,38 @@ Original release, featuring analog/digital modes and a few options.
|
|||
#include "checkbox.h"
|
||||
#include "xlcd.h"
|
||||
#include "oldmenuapi.h"
|
||||
#include "fixedpoint.h"
|
||||
|
||||
PLUGIN_HEADER
|
||||
|
||||
/* External bitmap references */
|
||||
extern const fb_data clock_digits[];
|
||||
extern const fb_data clock_smalldigits[];
|
||||
extern const fb_data clock_segments[];
|
||||
extern const fb_data clock_smallsegments[];
|
||||
extern const fb_data clock_logo[];
|
||||
extern const fb_data clock_messages[];
|
||||
extern const fb_data clock_timesup[];
|
||||
#include "clock_digits.h"
|
||||
#include "clock_smalldigits.h"
|
||||
#include "clock_smallsegments.h"
|
||||
#include "clock_messages.h"
|
||||
#include "clock_logo.h"
|
||||
#include "clock_segments.h"
|
||||
|
||||
/* Bitmap sizes/positions/deltas, per LCD size */
|
||||
#if (LCD_WIDTH >= 320) && (LCD_HEIGHT >=240) && (LCD_DEPTH >= 16) /* iPod 5G */
|
||||
#define DIGIT_WIDTH 50
|
||||
#define DIGIT_HEIGHT 70
|
||||
#define SMALLDIGIT_WIDTH 15
|
||||
#define SMALLDIGIT_HEIGHT 21
|
||||
#define SMALLSEG_WIDTH 15
|
||||
#define SMALLSEG_HEIGHT 21
|
||||
#define MESSAGE_HEIGHT 40
|
||||
#define MESSAGE_WIDTH 320
|
||||
#define LOGO_WIDTH 320
|
||||
#define LOGO_HEIGHT 160
|
||||
#define LCD_OFFSET 1.5
|
||||
#define HAND_W 3
|
||||
#elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) && (LCD_DEPTH >= 16) /* H300 */
|
||||
#define DIGIT_WIDTH 35
|
||||
#define DIGIT_HEIGHT 49
|
||||
#define SMALLDIGIT_WIDTH 10
|
||||
#define SMALLDIGIT_HEIGHT 14
|
||||
#define SMALLSEG_WIDTH 10
|
||||
#define SMALLSEG_HEIGHT 14
|
||||
#define MESSAGE_HEIGHT 27
|
||||
#define MESSAGE_WIDTH 220
|
||||
#define LOGO_WIDTH 220
|
||||
#define LOGO_HEIGHT 110
|
||||
#define LCD_OFFSET 1.5
|
||||
#define HAND_W 3
|
||||
#elif (LCD_WIDTH >= 176) && (LCD_HEIGHT >= 132) && (LCD_DEPTH >=16) /* Nano */
|
||||
#define DIGIT_WIDTH 25
|
||||
#define DIGIT_HEIGHT 35
|
||||
#define SMALLDIGIT_WIDTH 10
|
||||
#define SMALLDIGIT_HEIGHT 14
|
||||
#define SMALLSEG_WIDTH 10
|
||||
#define SMALLSEG_HEIGHT 14
|
||||
#define MESSAGE_HEIGHT 22
|
||||
#define MESSAGE_WIDTH 176
|
||||
#define LOGO_WIDTH 176
|
||||
#define LOGO_HEIGHT 88
|
||||
#define LCD_OFFSET 1.5
|
||||
#define HAND_W 3
|
||||
#elif (LCD_WIDTH >= 160) && (LCD_HEIGHT >= 128) && (LCD_DEPTH >=16) /* iAudio, H10 */
|
||||
#define DIGIT_WIDTH 25
|
||||
#define DIGIT_HEIGHT 35
|
||||
#define SMALLDIGIT_WIDTH 10
|
||||
#define SMALLDIGIT_HEIGHT 14
|
||||
#define SMALLSEG_WIDTH 10
|
||||
#define SMALLSEG_HEIGHT 14
|
||||
#define MESSAGE_HEIGHT 20
|
||||
#define MESSAGE_WIDTH 160
|
||||
#define LOGO_WIDTH 160
|
||||
#define LOGO_HEIGHT 80
|
||||
#define LCD_OFFSET 1.5
|
||||
#define HAND_W 3
|
||||
#elif (LCD_WIDTH >= 128) && (LCD_HEIGHT >= 128) && (LCD_DEPTH >=16) /* H10 5/6GB */
|
||||
#define DIGIT_WIDTH 20
|
||||
#define DIGIT_HEIGHT 28
|
||||
#define SMALLDIGIT_WIDTH 10
|
||||
#define SMALLDIGIT_HEIGHT 14
|
||||
#define SMALLSEG_WIDTH 10
|
||||
#define SMALLSEG_HEIGHT 14
|
||||
#define MESSAGE_HEIGHT 16
|
||||
#define MESSAGE_WIDTH 128
|
||||
#define LOGO_WIDTH 128
|
||||
#define LOGO_HEIGHT 64
|
||||
#define LCD_OFFSET 1.5
|
||||
#define HAND_W 3
|
||||
#elif (LCD_WIDTH >= 160) && (LCD_HEIGHT >= 128) && (LCD_DEPTH >=2) /* iPod 3G, 4G */
|
||||
#define DIGIT_WIDTH 25
|
||||
#define DIGIT_HEIGHT 35
|
||||
#define SMALLDIGIT_WIDTH 10
|
||||
#define SMALLDIGIT_HEIGHT 14
|
||||
#define SMALLSEG_WIDTH 10
|
||||
#define SMALLSEG_HEIGHT 14
|
||||
#define MESSAGE_HEIGHT 20
|
||||
#define MESSAGE_WIDTH 160
|
||||
#define LOGO_WIDTH 160
|
||||
#define LOGO_HEIGHT 80
|
||||
#define LCD_OFFSET 1.5
|
||||
#define HAND_W 3
|
||||
#elif (LCD_WIDTH >= 138) && (LCD_HEIGHT >= 110) && (LCD_DEPTH >=2) /* iPod mini */
|
||||
#define DIGIT_WIDTH 23
|
||||
#define DIGIT_HEIGHT 32
|
||||
#define SMALLDIGIT_WIDTH 10
|
||||
#define SMALLDIGIT_HEIGHT 14
|
||||
#define SMALLSEG_WIDTH 10
|
||||
#define SMALLSEG_HEIGHT 14
|
||||
#define MESSAGE_HEIGHT 17
|
||||
#define MESSAGE_WIDTH 138
|
||||
#define LOGO_WIDTH 138
|
||||
#define LOGO_HEIGHT 69
|
||||
#define LCD_OFFSET 1.5
|
||||
#define HAND_W 3
|
||||
#elif (LCD_WIDTH >= 112) && (LCD_HEIGHT >= 64) && (LCD_DEPTH >= 1) /* Archos */
|
||||
#define DIGIT_WIDTH 16
|
||||
#define DIGIT_HEIGHT 20
|
||||
#define SMALLDIGIT_WIDTH 8
|
||||
#define SMALLDIGIT_HEIGHT 10
|
||||
#define SMALLSEG_WIDTH 10
|
||||
#define SMALLSEG_HEIGHT 12
|
||||
#define MESSAGE_HEIGHT 14
|
||||
#define MESSAGE_WIDTH 112
|
||||
#define LOGO_WIDTH 112
|
||||
#define LOGO_HEIGHT 50
|
||||
/* Bitmap positions/deltas, per LCD size */
|
||||
#if (LCD_WIDTH >= 112) && (LCD_HEIGHT >= 64) && (LCD_DEPTH >= 1) /* Archos */
|
||||
#define LCD_OFFSET 1
|
||||
#define HAND_W 2
|
||||
#else
|
||||
#define LCD_OFFSET 1.5
|
||||
#define HAND_W 3
|
||||
#endif
|
||||
|
||||
#define DIGIT_WIDTH BMPWIDTH_clock_digits
|
||||
#define DIGIT_HEIGHT (BMPHEIGHT_clock_digits/15)
|
||||
#define SMALLDIGIT_WIDTH BMPWIDTH_clock_smalldigits
|
||||
#define SMALLDIGIT_HEIGHT (BMPHEIGHT_clock_smalldigits/13)
|
||||
#define SMALLSEG_WIDTH BMPWIDTH_clock_smallsegments
|
||||
#define SMALLSEG_HEIGHT (BMPHEIGHT_clock_smallsegments/13)
|
||||
#define MESSAGE_WIDTH BMPWIDTH_clock_messages
|
||||
#define MESSAGE_HEIGHT (BMPHEIGHT_clock_messages/6)
|
||||
#define LOGO_WIDTH BMPWIDTH_clock_logo
|
||||
#define LOGO_HEIGHT BMPHEIGHT_clock_logo
|
||||
|
||||
/* Parts of larger bitmaps */
|
||||
#define COLON 10
|
||||
#define DOT_FILLED 11
|
||||
|
@ -556,51 +469,6 @@ void reset_settings(void)
|
|||
settings.plain[plain_blinkcolon] = false;
|
||||
}
|
||||
|
||||
/************************************************
|
||||
* Precalculated sine * 16384 (fixed point 18.14)
|
||||
***********************************************/
|
||||
static const short sin_table[91] =
|
||||
{
|
||||
0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563,
|
||||
2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334,
|
||||
5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943,
|
||||
8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310,
|
||||
10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365,
|
||||
12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043,
|
||||
14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295,
|
||||
15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082,
|
||||
16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381,
|
||||
16384
|
||||
};
|
||||
|
||||
/*******************************
|
||||
* Sine function (from plasma.c)
|
||||
******************************/
|
||||
static short sin(int val)
|
||||
{
|
||||
/* value should be between 0 and 360 degree for correct lookup*/
|
||||
val%=360;
|
||||
if(val<0)
|
||||
val+=360;
|
||||
|
||||
/* Speed improvement through successive lookup */
|
||||
if (val < 181)
|
||||
{
|
||||
if (val < 91)
|
||||
return (short)sin_table[val]; /* phase 0-90 degree */
|
||||
else
|
||||
return (short)sin_table[180-val]; /* phase 91-180 degree */
|
||||
}
|
||||
else
|
||||
{
|
||||
if (val < 271)
|
||||
return -(short)sin_table[val-180]; /* phase 181-270 degree */
|
||||
else
|
||||
return -(short)sin_table[360-val]; /* phase 270-359 degree */
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**************************************************************
|
||||
* Simple function to check if we're switching to digital mode,
|
||||
* and if so, set bg/fg colors appropriately.
|
||||
|
@ -812,13 +680,13 @@ void init_clock(void)
|
|||
|
||||
for(i=0; i<ANALOG_VALUES; i++)
|
||||
{
|
||||
xminute[i] = ((sin(360 * i / ANALOG_VALUES)
|
||||
xminute[i] = ((sin_int(360 * i / ANALOG_VALUES)
|
||||
* ANALOG_MIN_RADIUS) >> 14) + ANALOG_XCENTER;
|
||||
yminute[i] = ((sin(360*i/ ANALOG_VALUES-90)
|
||||
yminute[i] = ((sin_int(360*i/ ANALOG_VALUES-90)
|
||||
* ANALOG_MIN_RADIUS) >> 14) + ANALOG_YCENTER;
|
||||
xhour[i] = ((sin(360 * i / ANALOG_VALUES)
|
||||
xhour[i] = ((sin_int(360 * i / ANALOG_VALUES)
|
||||
* ANALOG_HR_RADIUS) >> 14) + ANALOG_XCENTER;
|
||||
yhour[i] = ((sin(360 * i / ANALOG_VALUES-90)
|
||||
yhour[i] = ((sin_int(360 * i / ANALOG_VALUES-90)
|
||||
* ANALOG_HR_RADIUS) >> 14) + ANALOG_YCENTER;
|
||||
|
||||
/* Fullscreen initialization */
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "gray.h"
|
||||
#include "playergfx.h"
|
||||
#include "xlcd.h"
|
||||
#include "fixedpoint.h"
|
||||
|
||||
PLUGIN_HEADER
|
||||
|
||||
|
@ -312,100 +313,20 @@ static long matrice[3][3];
|
|||
static const int nb_points = 8;
|
||||
static long z_off = 600;
|
||||
|
||||
/* Precalculated sine and cosine * 16384 (fixed point 18.14) */
|
||||
static const short sin_table[91] =
|
||||
{
|
||||
0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563,
|
||||
2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334,
|
||||
5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943,
|
||||
8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310,
|
||||
10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365,
|
||||
12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043,
|
||||
14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295,
|
||||
15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082,
|
||||
16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381,
|
||||
16384
|
||||
};
|
||||
|
||||
static struct plugin_api* rb;
|
||||
|
||||
static long sin(int val)
|
||||
{
|
||||
/* Speed improvement through sukzessive lookup */
|
||||
if (val < 181)
|
||||
{
|
||||
if (val < 91)
|
||||
{
|
||||
/* phase 0-90 degree */
|
||||
return (long)sin_table[val];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* phase 91-180 degree */
|
||||
return (long)sin_table[180-val];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (val < 271)
|
||||
{
|
||||
/* phase 181-270 degree */
|
||||
return -(long)sin_table[val-180];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* phase 270-359 degree */
|
||||
return -(long)sin_table[360-val];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long cos(int val)
|
||||
{
|
||||
/* Speed improvement through sukzessive lookup */
|
||||
if (val < 181)
|
||||
{
|
||||
if (val < 91)
|
||||
{
|
||||
/* phase 0-90 degree */
|
||||
return (long)sin_table[90-val];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* phase 91-180 degree */
|
||||
return -(long)sin_table[val-90];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (val < 271)
|
||||
{
|
||||
/* phase 181-270 degree */
|
||||
return -(long)sin_table[270-val];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* phase 270-359 degree */
|
||||
return (long)sin_table[val-270];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void cube_rotate(int xa, int ya, int za)
|
||||
{
|
||||
int i;
|
||||
/* Just to prevent unnecessary lookups */
|
||||
long sxa, cxa, sya, cya, sza, cza;
|
||||
|
||||
sxa = sin(xa);
|
||||
cxa = cos(xa);
|
||||
sya = sin(ya);
|
||||
cya = cos(ya);
|
||||
sza = sin(za);
|
||||
cza = cos(za);
|
||||
sxa = sin_int(xa);
|
||||
cxa = cos_int(xa);
|
||||
sya = sin_int(ya);
|
||||
cya = cos_int(ya);
|
||||
sza = sin_int(za);
|
||||
cza = cos_int(za);
|
||||
|
||||
/* calculate overall translation matrix */
|
||||
matrice[0][0] = (cza * cya) >> 14;
|
||||
|
|
|
@ -60,6 +60,21 @@ static const unsigned long atan_table[] = {
|
|||
0x00000000, /* +0.000000000 */
|
||||
};
|
||||
|
||||
/* Precalculated sine and cosine * 16384 (2^14) (fixed point 18.14) */
|
||||
static const short sin_table[91] =
|
||||
{
|
||||
0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563,
|
||||
2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334,
|
||||
5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943,
|
||||
8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310,
|
||||
10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365,
|
||||
12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043,
|
||||
14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295,
|
||||
15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082,
|
||||
16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381,
|
||||
16384
|
||||
};
|
||||
|
||||
/**
|
||||
* Implements sin and cos using CORDIC rotation.
|
||||
*
|
||||
|
@ -136,3 +151,54 @@ long fsqrt(long a, unsigned int fracbits)
|
|||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed point sinus using a lookup table
|
||||
* don't forget to divide the result by 16384 to get the actual sinus value
|
||||
* @param val sinus argument in degree
|
||||
* @return sin(val)*16384
|
||||
*/
|
||||
long sin_int(int val)
|
||||
{
|
||||
val = (val+360)%360;
|
||||
if (val < 181)
|
||||
{
|
||||
if (val < 91)/* phase 0-90 degree */
|
||||
return (long)sin_table[val];
|
||||
else/* phase 91-180 degree */
|
||||
return (long)sin_table[180-val];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (val < 271)/* phase 181-270 degree */
|
||||
return -(long)sin_table[val-180];
|
||||
else/* phase 270-359 degree */
|
||||
return -(long)sin_table[360-val];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed point cosinus using a lookup table
|
||||
* don't forget to divide the result by 16384 to get the actual cosinus value
|
||||
* @param val sinus argument in degree
|
||||
* @return cos(val)*16384
|
||||
*/
|
||||
long cos_int(int val)
|
||||
{
|
||||
val = (val+360)%360;
|
||||
if (val < 181)
|
||||
{
|
||||
if (val < 91)/* phase 0-90 degree */
|
||||
return (long)sin_table[90-val];
|
||||
else/* phase 91-180 degree */
|
||||
return -(long)sin_table[val-90];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (val < 271)/* phase 181-270 degree */
|
||||
return -(long)sin_table[270-val];
|
||||
else/* phase 270-359 degree */
|
||||
return (long)sin_table[val-270];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,4 +21,5 @@
|
|||
|
||||
long fsincos(unsigned long phase, long *cos);
|
||||
long fsqrt(long a, unsigned int fracbits);
|
||||
|
||||
long cos_int(int val);
|
||||
long sin_int(int val);
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#ifndef HAVE_LCD_COLOR
|
||||
#include "gray.h"
|
||||
#endif
|
||||
#include "fixedpoint.h"
|
||||
|
||||
PLUGIN_HEADER
|
||||
|
||||
|
@ -101,60 +102,6 @@ static int plasma_frequency;
|
|||
|
||||
#define WAV_AMP 90
|
||||
|
||||
|
||||
/* Precalculated sine * 16384 (fixed point 18.14) */
|
||||
static const short sin_table[91] =
|
||||
{
|
||||
0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563,
|
||||
2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334,
|
||||
5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943,
|
||||
8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310,
|
||||
10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365,
|
||||
12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043,
|
||||
14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295,
|
||||
15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082,
|
||||
16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381,
|
||||
16384
|
||||
};
|
||||
|
||||
static short sin(int val)
|
||||
{
|
||||
/* value should be between 0 and 360 degree for correct lookup*/
|
||||
val%=360;
|
||||
if(val<0)
|
||||
val+=360;
|
||||
|
||||
/* Speed improvement through successive lookup */
|
||||
if (val < 181)
|
||||
{
|
||||
if (val < 91)
|
||||
{
|
||||
/* phase 0-90 degree */
|
||||
return (short)sin_table[val];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* phase 91-180 degree */
|
||||
return (short)sin_table[180-val];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (val < 271)
|
||||
{
|
||||
/* phase 181-270 degree */
|
||||
return -(short)sin_table[val-180];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* phase 270-359 degree */
|
||||
return -(short)sin_table[360-val];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Main wave function so we don't have to re-calc the sine
|
||||
* curve every time. Mess around WAV_AMP and FREQ to make slighlty
|
||||
|
@ -167,7 +114,7 @@ static void wave_table_generate(void)
|
|||
for (i=0;i<256;++i)
|
||||
{
|
||||
wave_array[i] = (unsigned char)((WAV_AMP
|
||||
* (sin((i * 360 * plasma_frequency) / 256))) / 16384);
|
||||
* (sin_int((i * 360 * plasma_frequency) / 256))) / 16384);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue