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
122 {
123 static const uint16_t base[] = {0, 6393, 12539, 18204,
124 23170, 27245, 30273, 32137};
125 static const uint8_t slope[] = {49, 48, 44, 38, 31, 23, 14, 4};
126
127 uint16_t
offset = (theta & 0x3FFF) >> 3;
128 if (theta & 0x4000)
130
131 uint8_t section =
offset / 256;
132 uint16_t b = base[section];
133 uint8_t m = slope[section];
134
135 uint8_t secoffset8 = (uint8_t)(
offset) / 2;
136
137 uint16_t mx = m * secoffset8;
139
140 if (theta & 0x8000)
142
144}
UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)