14 fl::u32 X = (fl::u32)
x << Q;
15 fl::u32
y = (1u << Q);
18 for (
int i = 0; i < 4; i++) {
19 y = (
y + (X /
y)) >> 1;
21 return static_cast<fl::i16
>(
y) >> 8;
91 for (u32 j = 0; j < mult; ++j) {
92 for (u32 i = 0; i < mult; ++i) {
93 u32 xx =
x * mult + i;
94 u32 yy =
y * mult + j;
95 i32 pt =
mSim->geti16(xx, yy);
109 i16 out =
static_cast<i16
>(sum / (mult * mult));
118 for (u32 j = 0; j < mult; ++j) {
119 for (u32 i = 0; i < mult; ++i) {
121 mSim->geti16Previous(
x * mult + i,
y * mult + j);
124 i16 out =
static_cast<i16
>(sum / (mult * mult));
129 i16 *prev, i16 *diff)
const {
134 *diff = *curr - *prev;
144 if (
mSim->getHalfDuplex()) {
145 u16 v2 =
static_cast<u16
>(
value);
148 return half_duplex_blend_linear(v2);
150 return half_duplex_blend_sqrt_q15(v2);
153 return static_cast<u8>(((
static_cast<u16
>(
value) + 32768)) >> 8);
167 int rad =
static_cast<int>(mult) / 2;
169 for (fl::size j = 0; j < mult; ++j) {
170 for (fl::size i = 0; i < mult; ++i) {
172 int dx =
static_cast<int>(i) - rad;
173 int dy =
static_cast<int>(j) - rad;
178 fl::size xx =
x * mult + i;
179 fl::size yy =
y * mult + j;
180 if (
mSim->has(xx, yy)) {
187 const bool sign_matches = (pt >= 0) == (v16 >= 0);
194 u16 abs_pt =
static_cast<u16
>(
fl::abs(pt));
195 u16 abs_v16 =
static_cast<u16
>(
fl::abs(v16));
196 if (abs_v16 > abs_pt) {
203 mSim->seti16(xx, yy, v16);
222 const bool has_updates = min_max !=
vec2<i16>(0, 0);
228 for (u32
x = 0;
x < w; ++
x) {
229 for (u32
y = 0;
y < h; ++
y) {
303 for (u32 i = 0; i < mult; ++i) {
304 sum +=
mSim->getf(
x * mult + i);
306 return sum /
static_cast<float>(mult);
314 for (u32 i = 0; i < mult; ++i) {
315 sum +=
mSim->geti16(
x * mult + i);
317 return static_cast<i16
>(sum / mult);
325 for (u32 i = 0; i < mult; ++i) {
326 sum +=
mSim->geti16Previous(
x * mult + i);
328 return static_cast<i16
>(sum / mult);
337 *diff = *curr - *prev;
362 if (
mSim->getHalfDuplex()) {
363 u16 v2 =
static_cast<u16
>(
value);
366 return half_duplex_blend_linear(v2);
368 return half_duplex_blend_sqrt_q15(v2);
371 return static_cast<u8>(((
static_cast<u16
>(
value) + 32768)) >> 8);
381 for (u32 i = 0; i < mult; ++i) {
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
void setUseChangeGrid(bool enabled)
fl::UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
fl::UISlider dampening("Dampening", 6.0f, 0.0f, 10.0f, 0.1f)
fl::u8 half_duplex_blend_linear(fl::u16 x)
fl::u8 half_duplex_blend_sqrt_q15(fl::u16 x)
i16 float_to_fixed(float f)
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
constexpr int type_rank< T >::value
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
fl::enable_if<!fl::is_array< T >::value, unique_ptr< T > >::type make_unique(Args &&... args) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type abs(T x) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NOEXCEPT
Base definition for an LED controller.