Skip to content

use memory aligned allocations, fix bug in FFT magnitude (integer path)#5499

Merged
DedeHai merged 2 commits intowled:16_xfrom
DedeHai:AR_allocFixes
Apr 12, 2026
Merged

use memory aligned allocations, fix bug in FFT magnitude (integer path)#5499
DedeHai merged 2 commits intowled:16_xfrom
DedeHai:AR_allocFixes

Conversation

@DedeHai
Copy link
Copy Markdown
Collaborator

@DedeHai DedeHai commented Apr 12, 2026

  • improved memory allocations: use proper function calls to make code more roust
  • fix bug in integer path magnitude calculation

Summary by CodeRabbit

  • Bug Fixes

    • Improved memory allocation reliability and error handling in audio reactive features with better failure recovery.
  • Performance

    • Optimized buffer allocation mechanisms in audio processing routines for more efficient resource utilization.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 12, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 55ef4b9f-c032-4f81-bccc-cf8056418cfd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR refactors FFT buffer allocation in the audio reactive module to use heap_caps_aligned_calloc() with explicit alignment instead of manual pointer arithmetic or basic calloc(), improving memory management. Error handling is enhanced with coordinated cleanup on allocation failures in both integer and float FFT paths.

Changes

Cohort / File(s) Summary
Audio Reactive FFT Buffer Allocation
usermods/audioreactive/audio_reactive.cpp
Refactored FFT buffer allocation (valFFT, windowFFT, windowFloat) to use heap_caps_aligned_calloc() with explicit alignment instead of manual over-allocation; improved failure handling with coordinated resource cleanup; removed redundant FFT_Magnitude assignment.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • netmindz
  • blazoncek
  • softhack007
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: improved memory allocations using aligned allocation functions and a bug fix in FFT magnitude calculation for the integer path.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DedeHai
Copy link
Copy Markdown
Collaborator Author

DedeHai commented Apr 12, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 12, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@usermods/audioreactive/audio_reactive.cpp`:
- Around line 299-309: The code is shadowing the file-scope pointers valFFT and
windowFFT by declaring new local float* variables when calling
heap_caps_aligned_calloc, leaving the globals nullptr and causing FFTcode() to
crash or leak; change the allocations to assign directly to the existing globals
(valFFT = (float*)heap_caps_aligned_calloc(...), windowFFT =
(float*)heap_caps_aligned_calloc(...)), keep the null checks as is, and ensure
on failure you call heap_caps_free(valFFT) only if the global valFFT was
actually set and then set the globals to nullptr; reference functions/variables:
valFFT, windowFFT, FFTcode(), heap_caps_aligned_calloc, heap_caps_free.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 436b027f-1316-4c26-b76b-49a6b327b035

📥 Commits

Reviewing files that changed from the base of the PR and between 945896d and aa5a409.

📒 Files selected for processing (1)
  • usermods/audioreactive/audio_reactive.cpp

@DedeHai DedeHai merged commit ae36f7e into wled:16_x Apr 12, 2026
257 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant