15 fl::u32 X = (fl::u32)
x << Q;
16 fl::u32
y = (1u << Q);
19 for (
int i = 0; i < 4; i++) {
20 y = (
y + (X /
y)) >> 1;
22 return static_cast<fl::i16
>(
y) >> 8;
80 for (u32 j = 0; j < mult; ++j) {
81 for (u32 i = 0; i < mult; ++i) {
82 u32 xx =
x * mult + i;
83 u32 yy =
y * mult + j;
84 i32 pt =
mSim->geti16(xx, yy);
94 i16 out =
static_cast<i16
>(sum / (mult * mult));
103 for (u32 j = 0; j < mult; ++j) {
104 for (u32 i = 0; i < mult; ++i) {
106 mSim->geti16Previous(
x * mult + i,
y * mult + j);
109 i16 out =
static_cast<i16
>(sum / (mult * mult));
114 i16 *prev, i16 *diff)
const {
119 *diff = *curr - *prev;
129 if (
mSim->getHalfDuplex()) {
130 u16 v2 =
static_cast<u16
>(value);
133 return half_duplex_blend_linear(v2);
135 return half_duplex_blend_sqrt_q15(v2);
138 return static_cast<u8>(((
static_cast<u16
>(value) + 32768)) >> 8);
152 int rad =
static_cast<int>(mult) / 2;
154 for (fl::size j = 0; j < mult; ++j) {
155 for (fl::size i = 0; i < mult; ++i) {
157 int dx =
static_cast<int>(i) - rad;
158 int dy =
static_cast<int>(j) - rad;
160 if (
ABS(dx) +
ABS(dy) > rad) {
163 fl::size xx =
x * mult + i;
164 fl::size yy =
y * mult + j;
165 if (
mSim->has(xx, yy)) {
171 const bool sign_matches = (pt >= 0) == (v16 >= 0);
178 u16 abs_pt =
static_cast<u16
>(
ABS(pt));
179 u16 abs_v16 =
static_cast<u16
>(
ABS(v16));
180 if (abs_v16 > abs_pt) {
201 const bool has_updates = min_max !=
vec2<i16>(0, 0);
207 for (u32
x = 0;
x < w; ++
x) {
208 for (u32
y = 0;
y < h; ++
y) {
259 for (u32 i = 0; i < mult; ++i) {
260 sum +=
mSim->getf(
x * mult + i);
262 return sum /
static_cast<float>(mult);
270 for (u32 i = 0; i < mult; ++i) {
271 sum +=
mSim->geti16(
x * mult + i);
273 return static_cast<i16
>(sum / mult);
281 for (u32 i = 0; i < mult; ++i) {
282 sum +=
mSim->geti16Previous(
x * mult + i);
284 return static_cast<i16
>(sum / mult);
293 *diff = *curr - *prev;
318 if (
mSim->getHalfDuplex()) {
319 u16 v2 =
static_cast<u16
>(value);
322 return half_duplex_blend_linear(v2);
324 return half_duplex_blend_sqrt_q15(v2);
327 return static_cast<u8>(((
static_cast<u16
>(value) + 32768)) >> 8);
337 for (u32 i = 0; i < mult; ++i) {
338 mSim->set(
x * mult + i, value);
float getf(fl::size x) const
fl::unique_ptr< WaveSimulation1D_Real > mSim
void setExtraFrames(u8 extra)
i16 geti16Previous(fl::size x) const
int getDampenening() const
void setSpeed(float speed)
void setDampening(int damp)
bool geti16All(fl::size x, i16 *curr, i16 *prev, i16 *diff) const
u8 getu8(fl::size x) const
void init(u32 length, SuperSample factor, float speed, int dampening)
WaveSimulation1D(u32 length, SuperSample factor=SuperSample::SUPER_SAMPLE_NONE, float speed=0.16f, int dampening=6)
i8 geti8(fl::size x) const
void setf(fl::size x, float value)
bool has(fl::size x) const
i16 geti16(fl::size x) const
i8 geti8(fl::size x, fl::size y) const
WaveSimulation2D(u32 W, u32 H, SuperSample factor=SuperSample::SUPER_SAMPLE_NONE, float speed=0.16f, float dampening=6.0f)
void seti16(fl::size x, fl::size y, i16 value)
i16 geti16(fl::size x, fl::size y) const
int getDampenening() const
fl::Grid< i16 > mChangeGrid
void setExtraFrames(u8 extra)
float getf(fl::size x, fl::size y) const
i16 geti16Previous(fl::size x, fl::size y) const
void setSpeed(float speed)
bool geti16All(fl::size x, fl::size y, i16 *curr, i16 *prev, i16 *diff) const
void setf(fl::size x, fl::size y, float value)
bool has(fl::size x, fl::size y) const
void setDampening(int damp)
u8 getu8(fl::size x, fl::size y) const
void init(u32 width, u32 height, SuperSample factor, float speed, int dampening)
fl::unique_ptr< WaveSimulation2D_Real > mSim
UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
UISlider dampening("Dampening", 6.0f, 0.0f, 10.0f, 0.1f)
Implements the FastLED namespace macros.
fl::u8 half_duplex_blend_sqrt_q15(fl::u16 x)
fl::u8 half_duplex_blend_linear(fl::u16 x)
i16 float_to_fixed(float f)
FASTLED_FORCE_INLINE T clamp(T value, T min, T max)