Skip to content

Commit 55e8868

Browse files
committed
fix a few more AI-generated bugs
WTF, dude
1 parent bfb2b88 commit 55e8868

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

usermods/audioreactive/audio_reactive.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,7 @@ class AudioReactive : public Usermod {
17271727
// reset sound data
17281728
volumeRaw = 0; volumeSmth = 0;
17291729
for(int i=(init?0:1); i<NUM_GEQ_CHANNELS; i+=2) fftResult[i] = 16; // make a tiny pattern
1730+
memset(paletteBandAvg, 0, sizeof(paletteBandAvg));
17301731
autoResetPeak();
17311732
if (init) {
17321733
if (udpSyncConnected) { // close UDP sync connection (if open)
@@ -2250,7 +2251,7 @@ CRGB AudioReactive::getCRGBForBand(int x, int pal) {
22502251
// Map centroid to hue on a log scale (human pitch perception is logarithmic).
22512252
// log2(60 Hz) ≈ 5.9, log2(8000 Hz) ≈ 13.0 → hue range 0..200 (red → blue-purple)
22522253
float logC = log2f(constrain(centroid, 60.0f, 8000.0f)); // softhack007 ToDO: use logf() instead of log2f()
2253-
uint8_t baseHue = (uint8_t)mapf(logC, 5.9f, 13.0f, 0.0f, 200.0f);
2254+
uint8_t baseHue = (uint8_t)mapf(logC, 5.9f, 13.0f, 0.0f, 200.0f); // mapf() cannot produce negative results due to previous constrain() --> safe to directly cast to uint8_t
22542255
int8_t hueSpread = map(x, 0, 255, -30, 30); // spread palette positions ±30 hue units // softhack007 ToDO: use CHSV32 with 16bit HUE
22552256
uint8_t saturation = (uint8_t)constrain((int)(tEnergy / 6.0f) + 180, 180, 255); // louder = more saturated // softhack007 WTF dude?
22562257
hsv = CHSV(baseHue + hueSpread, saturation, (uint8_t)constrain(x, 30, 255));
@@ -2277,7 +2278,8 @@ CRGB AudioReactive::getCRGBForBand(int x, int pal) {
22772278
float midRatio = midEnergy / total;
22782279
float highRatio = highEnergy / total;
22792280
// Weighted hue: pure bass→20, pure mid→110, pure high→190
2280-
uint8_t hue = (uint8_t)(bassRatio * 20.0f + midRatio * 110.0f + highRatio * 190.0f);
2281+
int weightedHue = roundf(bassRatio * 20.0f + midRatio * 110.0f + highRatio * 190.0f);
2282+
uint8_t hue = min(255, max(0, weightedHue)); // clamp to [0...255]
22812283
// Saturation: dominated spectrum (one band clearly wins) → high sat; balanced → lower sat
22822284
float maxRatio = max(bassRatio, max(midRatio, highRatio));
22832285
uint8_t sat = (uint8_t)constrain((int)(maxRatio * 255.0f * 1.5f), 180, 255); // softhack007 OMG, WTF?

0 commit comments

Comments
 (0)