summaryrefslogtreecommitdiff
path: root/apps/plugins/plasma.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/plasma.c')
-rw-r--r--apps/plugins/plasma.c57
1 files changed, 2 insertions, 55 deletions
diff --git a/apps/plugins/plasma.c b/apps/plugins/plasma.c
index df22444b81..64d73a3757 100644
--- a/apps/plugins/plasma.c
+++ b/apps/plugins/plasma.c
@@ -29,6 +29,7 @@
29#ifndef HAVE_LCD_COLOR 29#ifndef HAVE_LCD_COLOR
30#include "gray.h" 30#include "gray.h"
31#endif 31#endif
32#include "fixedpoint.h"
32 33
33PLUGIN_HEADER 34PLUGIN_HEADER
34 35
@@ -101,60 +102,6 @@ static int plasma_frequency;
101 102
102#define WAV_AMP 90 103#define WAV_AMP 90
103 104
104
105/* Precalculated sine * 16384 (fixed point 18.14) */
106static const short sin_table[91] =
107{
108 0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563,
109 2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334,
110 5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943,
111 8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310,
112 10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365,
113 12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043,
114 14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295,
115 15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082,
116 16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381,
117 16384
118};
119
120static short sin(int val)
121{
122 /* value should be between 0 and 360 degree for correct lookup*/
123 val%=360;
124 if(val<0)
125 val+=360;
126
127 /* Speed improvement through successive lookup */
128 if (val < 181)
129 {
130 if (val < 91)
131 {
132 /* phase 0-90 degree */
133 return (short)sin_table[val];
134 }
135 else
136 {
137 /* phase 91-180 degree */
138 return (short)sin_table[180-val];
139 }
140 }
141 else
142 {
143 if (val < 271)
144 {
145 /* phase 181-270 degree */
146 return -(short)sin_table[val-180];
147 }
148 else
149 {
150 /* phase 270-359 degree */
151 return -(short)sin_table[360-val];
152 }
153 }
154 return 0;
155}
156
157
158/* 105/*
159 * Main wave function so we don't have to re-calc the sine 106 * Main wave function so we don't have to re-calc the sine
160 * curve every time. Mess around WAV_AMP and FREQ to make slighlty 107 * curve every time. Mess around WAV_AMP and FREQ to make slighlty
@@ -167,7 +114,7 @@ static void wave_table_generate(void)
167 for (i=0;i<256;++i) 114 for (i=0;i<256;++i)
168 { 115 {
169 wave_array[i] = (unsigned char)((WAV_AMP 116 wave_array[i] = (unsigned char)((WAV_AMP
170 * (sin((i * 360 * plasma_frequency) / 256))) / 16384); 117 * (sin_int((i * 360 * plasma_frequency) / 256))) / 16384);
171 } 118 }
172} 119}
173 120