Gravimeter: bars turn black at full volume (uint8_t(segmentSampleAvg*8) overflows)

オープン 初心者向け
#5,891 コメント 12 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@DedeHai がすでに取り組んでいます。

2026年10月8日 から。

  • #5893 @DedeHai による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp
領域
embedded-iot

調査の方向性

wled00/FX.cpp の mode_gravcenter_base() から始め、issue で示されている Gravimeter のブレンド式を確認し、関連する Gravcenter の行と比較します。高い強度で Gravimeter エフェクトを使って再現し、バーが最大の高さに達したときのブレンド量を調べます。他のモードの動作を変えずに、最大音量でもバーが点灯し続ければ完了です。

索引モデルが issue の本文から書いたものです。

説明

bug confirmed
What happened?

With the AudioReactive Gravimeter effect, the meter tracks volume normally until it reaches the top. At that point every bar goes (almost) black and only the peak/gravity pixel stays lit. At full volume the whole segment is dark except that one pixel.

Versions

16.0.1 (ESP32 release build)
Same code on main @ d2c00c57f8

To Reproduce Bug

Setup
ESP32-PICO-D4 (M5Stack Atom Echo), built-in PDM mic (SPM1423), AGC on. SK6812 RGBW. Seen on an 8×8 matrix with 1D→2D "Bar" mapping, but the cause doesn't depend on the mapping, so 1D strips are affected too.

Steps to reproduce

Select Gravimeter with default intensity (128) and a black secondary colour (the default).
Play loud audio so the meter reaches the top of the segment.
The bars disappear, and only the peak pixel remains.

Cause
In mode_gravcenter_base(), Gravimeter mode (FX.cpp#L6856 @ v16.0.1):

SEGMENT.setPixelColor(i, color_blend(SEGCOLOR(1), SEGMENT.color_from_palette(index, false, PALETTE_SOLID_WRAP, 0), uint8_t(segmentSampleAvg*8)));

For Gravimeter, segmentSampleAvg = volumeSmth * intensity / 255 * 0.25, which can reach about 63.75. The bar height mapf(segmentSampleAvg2, 0, 64, 0, SEGLEN-1) reaches full height at segmentSampleAvg == 32, which is exactly where segmentSampleAvg8 passes 255. Casting that out-of-range float to uint8_t wraps on ESP32 (it's undefined behaviour in C++). The blend amount drops to near 0, so every bar becomes SEGCOLOR(1) (black by default). The peak pixel is drawn straight from the palette, so it stays lit.

Gravcenter, Gravcentric and Gravfreq use the same expression but scale by 0.125, which tops out at about 31.9, so they don't overflow.

Suggested fix
Clamp before the cast:

uint8_t(fminf(segmentSampleAvg * 8.0f, 255.0f))

The same clamp could go on the Gravcenter line (#L6878–6879) for safety.

Workaround
Noisemeter has no such overflow, or keep Gravimeter's intensity below 128 (but then it never reaches the top row).

Expected Behavior

At max intensity, all lights should be lit, rather than the top row of the matrix only.

Install Method

Self-Compiled

What version of WLED?

16.0.1 (ESP32 release build)

Which microcontroller/board are you seeing the problem on?

ESP32

Relevant log/trace output

Anything else?

No response

Code of Conduct
  • I agree to follow this project's Code of Conduct
主要言語
C++
スター
18.8k
フォーク
4.4k
平均マージ
3日 5時間
マージ済み PR(30日)
14

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

wled/WLED のほかの issue

wled/WLED の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。