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

◆ hexwave_generate_linesegs()

static void fl::third_party::hexwave::hexwave_generate_linesegs ( hexvert vert[9],
HexWave * hex,
float dt )
static

Definition at line 123 of file stb_hexwave.cpp.hpp.

124{
125 int32_t j;
126 float min_len = dt / 256.0f;
127
128 vert[0].t = 0;
129 vert[0].v = 0;
130 vert[1].t = hex->current.zero_wait*0.5f;
131 vert[1].v = 0;
132 vert[2].t = 0.5f*hex->current.peak_time + vert[1].t*(1-hex->current.peak_time);
133 vert[2].v = 1;
134 vert[3].t = 0.5f;
135 vert[3].v = hex->current.half_height;
136
137 if (hex->current.reflect) {
138 for (j=4; j <= 7; ++j) {
139 vert[j].t = 1 - vert[7-j].t;
140 vert[j].v = - vert[7-j].v;
141 }
142 } else {
143 for (j=4; j <= 7; ++j) {
144 vert[j].t = 0.5f + vert[j-4].t;
145 vert[j].v = - vert[j-4].v;
146 }
147 }
148 vert[8].t = 1;
149 vert[8].v = 0;
150
151 for (j=0; j < 8; ++j) {
152 if (vert[j+1].t <= vert[j].t + min_len) {
153 // if change takes place over less than a fraction of a sample treat as discontinuity
154 //
155 // otherwise the slope computation can blow up to arbitrarily large and we
156 // try to generate a huge BLAMP and the result is wrong.
157 //
158 // why does this happen if the math is right? i believe if done perfectly,
159 // the two BLAMPs on either side of the slope would cancel out, but our
160 // BLAMPs have only limited sub-sample precision and limited integration
161 // accuracy. or maybe it's just the math blowing up w/ floating point precision
162 // limits as we try to make x * (1/x) cancel out
163 //
164 // min_len verified artifact-free even near nyquist with only oversample=4
165 vert[j+1].t = vert[j].t;
166 }
167 }
168
169 if (vert[8].t != 1.0f) {
170 // if the above fixup moved the endpoint away from 1.0, move it back,
171 // along with any other vertices that got moved to the same time
172 float t = vert[8].t;
173 for (j=5; j <= 8; ++j)
174 if (vert[j].t == t)
175 vert[j].t = 1.0f;
176 }
177
178 // compute the exact slopes from the final fixed-up positions
179 for (j=0; j < 8; ++j)
180 if (vert[j+1].t == vert[j].t)
181 vert[j].s = 0;
182 else
183 vert[j].s = (vert[j+1].v - vert[j].v) / (vert[j+1].t - vert[j].t);
184
185 // wraparound at end
186 vert[8].t = 1;
187 vert[8].v = vert[0].v;
188 vert[8].s = vert[0].s;
189}
fl::i32 int32_t
Definition coder.h:220
const hex_t hex
Definition ios.cpp.hpp:6

References FL_NOEXCEPT, fl::hex, and fl::t.

Referenced by hexwave_generate_samples().

+ Here is the caller graph for this function: