13#define INT16_POS (32767)
14#define INT16_NEG (-32768)
23 return static_cast<i16
>(f * 32768.0f);
33 return static_cast<float>(f) / 32768.0f;
54 const float decay = 1.0f - 1.0f /
static_cast<float>(u32(1) << damp);
123 FL_WARN(
"warning X value too high");
138 i32 mCourantSq32 =
static_cast<i32
>(
mCourantSq);
146 for (fl::size i = 1; i <
length + 1; i++) {
150 (i32)curr[i + 1] - (i32)curr[i] * 2 + curr[i - 1];
159 i32 term =
static_cast<i32
>(
160 (
static_cast<i64>(mCourantSq32) * lap) >> 15);
164 i32 f = -(i32)next[i] + (i32)curr[i] * 2 + term;
172 f =
static_cast<i32
>(
178 next[i] =
static_cast<i16
>(
fl::clamp(f, q15_min,
static_cast<i32
>(32767)));
213 grid1.resize((
W + 2) * (
H + 2));
214 grid2.resize((
W + 2) * (
H + 2));
235 FL_WARN(
"Out of range: " <<
x <<
", " <<
y);
244 FL_WARN(
"Out of range: " <<
x <<
", " <<
y);
248 return curr[(
y + 1) *
stride + (
x + 1)];
253 FL_WARN(
"Out of range: " <<
x <<
", " <<
y);
257 return prev[(
y + 1) *
stride + (
x + 1)];
271 FL_WARN(
"Out of range: " <<
x <<
", " <<
y);
283 for (fl::size j = 0; j <
height + 2; ++j) {
294 for (fl::size i = 0; i <
width + 2; ++i) {
299 i32 mCourantSq32 =
static_cast<i32
>(
mCourantSq);
319 for (fl::size j = 1; j <=
height; ++j) {
320 const fl::size row = j *
stride;
325 for (fl::size i = 1; i <=
width; ++i) {
326 const i32 c = row_curr[i];
334 const i32 diag = (i32)row_above[i - 1] + row_above[i + 1] +
335 row_below[i - 1] + row_below[i + 1];
336 const i32 nbr = (i32)row_above[i] + row_below[i] +
337 row_curr[i - 1] + row_curr[i + 1];
338 laplacian = diag + nbr * 4 - 20 * c;
341 laplacian = (i32)row_curr[i + 1] + row_curr[i - 1] +
342 row_above[i] + row_below[i] - c * 4;
349 i64 product =
static_cast<i64>(mCourantSq32) * laplacian;
357 term =
static_cast<i32
>((product >> 15) / 6);
359 term =
static_cast<i32
>(product >> 15);
362 i32 f = -(i32)row_next[i] + c * 2 + term;
366 f =
static_cast<i32
>(
371 row_next[i] =
static_cast<i16
>(
fl::clamp(f, q15_min,
static_cast<i32
>(32767)));
bool has(fl::size x) const FL_NO_EXCEPT
int getDampenening() const FL_NO_EXCEPT
void setSpeed(float something) FL_NO_EXCEPT
void setDampening(int damp) FL_NO_EXCEPT
WaveSimulation1D_Real(u32 length, float speed=0.16f, int dampening=6) FL_NO_EXCEPT
float getf(fl::size x) const FL_NO_EXCEPT
float getSpeed() const FL_NO_EXCEPT
i16 geti16Previous(fl::size x) const FL_NO_EXCEPT
void update() FL_NO_EXCEPT
void set(fl::size x, float value) FL_NO_EXCEPT
i16 geti16(fl::size x) const FL_NO_EXCEPT
void update() FL_NO_EXCEPT
bool has(fl::size x, fl::size y) const FL_NO_EXCEPT
void setSpeed(float something) FL_NO_EXCEPT
void seti16(fl::size x, fl::size y, i16 value) FL_NO_EXCEPT
i16 geti16(fl::size x, fl::size y) const FL_NO_EXCEPT
WaveSimulation2D_Real(u32 W, u32 H, float speed=0.16f, float dampening=6.0f) FL_NO_EXCEPT
LaplacianStencil mStencil
void setf(fl::size x, fl::size y, float value) FL_NO_EXCEPT
int getDampenening() const FL_NO_EXCEPT
void setDampening(int damp) FL_NO_EXCEPT
i16 geti16Previous(fl::size x, fl::size y) const FL_NO_EXCEPT
float getf(fl::size x, fl::size y) const FL_NO_EXCEPT
float getSpeed() const FL_NO_EXCEPT
#define FL_RESTRICT_PARAM
fl::UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
fl::UISlider dampening("Dampening", 6.0f, 0.0f, 10.0f, 0.1f)
float fixed_to_float(i16 f) FL_NO_EXCEPT
i16 float_to_fixed(float f) FL_NO_EXCEPT
i16 compute_damp_decay_q15(int damp) FL_NO_EXCEPT
u8 u8 fract8 blur_amount FL_NO_EXCEPT
constexpr int type_rank< T >::value
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NO_EXCEPT
memory_resource * psram_memory_resource() FL_NO_EXCEPT
Get the PSRAM memory resource (wraps PSRamAllocate / PSRamDeallocate).
Base definition for an LED controller.