Skip to content

fix(audio): invalidate Sample statistics after applyGain #4520

Closed

Description

@zackees

Context

Sample::applyGain changes PCM data, while SampleImpl memoizes RMS and zero-crossing frequency. If those statistics were read before applying gain, subsequent reads return pre-gain values.

Repro: create Sample([1000,-1000]), call rms() (1000), applyGain(2), then rms(); expected 2000, actual 1000. Scaling [1,-1] to zero similarly leaves a cached nonzero zero-crossing statistic.

Proposal

Invalidate or recompute cached statistics whenever the PCM buffer changes.

Acceptance criteria

  • Focused tests demonstrate RED→GREEN for RMS after positive gain and zero-crossing frequency after gain 0.
  • Repeated reads after mutation agree with statistics recomputed from the resulting PCM.

Decisions

  • Scope is cache coherence for applyGain; audit other mutable PCM paths during implementation.
  • Priority: medium; stale analysis values affect downstream audio behavior.

Activity

  1. added
    type: bug
    on Sep 23, 2026
  2. zackees commented on Sep 23, 2026

    @zackees
    MemberAuthor

    Please do an adversarial review on this. I don't know if this is the right decision.

  3. moved this from Triage to Done in FastLED Trackeron Sep 24, 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

    type: bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions