FastLED 3.9.15
Loading...
Searching...
No Matches

◆ sin8_C()

LIB8STATIC uint8_t sin8_C ( uint8_t theta)

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;
int x
Definition Audio.ino:71
Parameters
thetainput angle from 0-255
Returns
sin of theta, value between 0 and 255

Definition at line 231 of file trig8.h.

231 {
232 uint8_t offset = theta;
233 if (theta & 0x40) {
234 offset = (uint8_t)255 - offset;
235 }
236 offset &= 0x3F; // 0..63
237
238 uint8_t secoffset = offset & 0x0F; // 0..15
239 if (theta & 0x40)
240 ++secoffset;
241
242 uint8_t section = offset >> 4; // 0..3
243 uint8_t s2 = section * 2;
244 const uint8_t *p = b_m16_interleave;
245 p += s2;
246 uint8_t b = *p;
247 ++p;
248 uint8_t m16 = *p;
249
250 uint8_t mx = (m16 * secoffset) >> 4;
251
252 int8_t y = mx + b;
253 if (theta & 0x80)
254 y = -y;
255
256 y += 128;
257
258 return y;
259}
int y
Definition Audio.ino:72
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.
Definition trig8.h:156
static FASTLED_NAMESPACE_BEGIN uint8_t const p[]
Definition noise.cpp:30

References b_m16_interleave, LIB8STATIC, offset(), p, and y.

+ Here is the call graph for this function: