Fast 8-bit approximation of sin(x).
This approximation never varies more than 2% from the floating point value you'd get by doing
float s = (sin(
x) * 128.0) + 128;
- Parameters
-
theta | input angle from 0-255 |
- Returns
- sin of theta, value between 0 and 255
Definition at line 240 of file trig8.h.
240 {
242 if (theta & 0x40) {
244 }
246
247 uint8_t secoffset =
offset & 0x0F;
248 if (theta & 0x40)
249 ++secoffset;
250
251 uint8_t section =
offset >> 4;
252 uint8_t s2 = section * 2;
254 p += s2;
255 uint8_t b = *p;
256 ++p;
257 uint8_t m16 = *p;
258
259 uint8_t mx = (m16 * secoffset) >> 4;
260
262 if (theta & 0x80)
264
266
268}
UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
const uint8_t b_m16_interleave[]
Pre-calculated lookup table used in sin8() and cos8() functions.
References b_m16_interleave, LIB8STATIC, offset(), and y.