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

◆ sin16_C()

LIB8STATIC int16_t sin16_C ( uint16_t theta)

Fast 16-bit approximation of sin(x).

This approximation never varies more than 0.69% from the floating point value you'd get by doing

float s = sin(x) * 32767.0;
int x
Definition Audio.ino:71
Parameters
thetainput angle from 0-65535
Returns
sin of theta, value between -32767 to 32767.

Definition at line 113 of file trig8.h.

113 {
114 static const uint16_t base[] = {0, 6393, 12539, 18204,
115 23170, 27245, 30273, 32137};
116 static const uint8_t slope[] = {49, 48, 44, 38, 31, 23, 14, 4};
117
118 uint16_t offset = (theta & 0x3FFF) >> 3; // 0..2047
119 if (theta & 0x4000)
120 offset = 2047 - offset;
121
122 uint8_t section = offset / 256; // 0..7
123 uint16_t b = base[section];
124 uint8_t m = slope[section];
125
126 uint8_t secoffset8 = (uint8_t)(offset) / 2;
127
128 uint16_t mx = m * secoffset8;
129 int16_t y = mx + b;
130
131 if (theta & 0x8000)
132 y = -y;
133
134 return y;
135}
int y
Definition Audio.ino:72
UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)

References LIB8STATIC, offset(), and y.

+ Here is the call graph for this function: