Skip to content

perf(wave): precompute damping as a Q15 multiplier (refs #3073 §6, alt to §2) #3096

Closed

Description

@zackees

Scope from #3073 §6.

Idea

Replace f - f / D with a precomputed Q15 multiplier. At setDampening() time, compute:

i16 mDampDecayQ15 = wave_detail::float_to_fixed(1.0f - 1.0f / (1 << damp));

In the inner loop:

f = static_cast<i32>(
    (static_cast<i64>(f) * mDampDecayQ15) >> 15);

Why

This is equivalent to §2 (#TBD — arithmetic shift) for power-of-two damp, but generalizes cleanly if the public API is ever extended to non-power-of-two damping (e.g. setDampening(float) instead of setDampening(int)).

Cortex-M4+ lowers this to a single smmlsr/smulwb. AVR does it as a 16×32 multiply (~30 cycles) — same ballpark as §2's shift but cleaner semantics.

When to pick §6 vs §2

  • Pick §2 (#TBD) if you want the minimum-diff fix and don't care about non-power-of-two damping.
  • Pick §6 if you want the abstraction to last beyond the current int dampening API surface.

If §2 ships first, this becomes a small refactor that drops the "damping is a power of 2" implicit assumption from setDampening.

Acceptance

  • bash test fl_math_wave_wave_simulation_real --cpp passes.
  • Setter accepts float damping and rounds to the nearest 1-LSB Q15 representation; getter round-trips within ±1 LSB.

Refs: #3073 §6, alternative to §2 (#TBD).

Activity

  1. zackees commented on Jun 15, 2026

    @zackees
    MemberAuthor

    Parent meta: #3098. Alternative to #3092 (§2 arithmetic shift) — pick this if you want non-power-of-two damping support.

  2. added a commit that references this issue on Jun 15, 2026
    16c8ab7
  3. moved this from Triage to Done in FastLED Trackeron Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions