FastLED 3.9.15
Loading...
Searching...
No Matches

◆ drawSpectrumBars()

void drawSpectrumBars ( FFTBins * fft,
float  )

Definition at line 176 of file advanced.h.

176 {
177 clearDisplay();
178 CRGBPalette16 palette = getCurrentPalette();
179
180 int barWidth = WIDTH / NUM_BANDS;
181
182 for (size_t band = 0; band < NUM_BANDS && band < fft->bins_db.size(); band++) {
183 float magnitude = fft->bins_db[band];
184
185 // Apply noise floor
186 magnitude = magnitude / 100.0f; // Normalize from dB
187 magnitude = MAX(0.0f, magnitude - noiseFloor.value());
188
189 // Smooth the FFT
190 fftSmooth[band] = fftSmooth[band] * 0.8f + magnitude * 0.2f;
191 magnitude = fftSmooth[band];
192
193 // Apply gain
194 magnitude *= audioGain.value() * autoGainValue;
195 magnitude = fl::clamp(magnitude, 0.0f, 1.0f);
196
197 int barHeight = magnitude * HEIGHT;
198 int xStart = band * barWidth;
199
200 for (int x = 0; x < barWidth - 1; x++) {
201 for (int y = 0; y < barHeight; y++) {
202 uint8_t colorIndex = fl::map_range<float, uint8_t>(
203 float(y) / HEIGHT, 0, 1, 0, 255
204 );
205 CRGB color = ColorFromPalette(palette, colorIndex + hue);
206
207 int ledIndex = xyMap(xStart + x, y);
208 if (ledIndex >= 0 && ledIndex < NUM_LEDS) {
209 leds[ledIndex] = color;
210 }
211
212 if (mirrorMode) {
213 int mirrorIndex = xyMap(WIDTH - 1 - (xStart + x), y);
214 if (mirrorIndex >= 0 && mirrorIndex < NUM_LEDS) {
215 leds[mirrorIndex] = color;
216 }
217 }
218 }
219 }
220 }
221}
CRGB leds[NUM_LEDS]
#define NUM_LEDS
uint8_t hue
int y
Definition simple.h:93
int x
Definition simple.h:92
fl::XYMap xyMap
Definition ColorBoost.h:61
UINumberField palette("Palette", 0, 0, 2)
AudioAnalyzeFFT1024 fft
#define WIDTH
Definition advanced.h:36
static const int NUM_BANDS
Definition advanced.h:83
float fftSmooth[NUM_BANDS]
Definition advanced.h:84
UISlider noiseFloor("Noise Floor", 0.1f, 0.0f, 1.0f, 0.01f)
UICheckbox mirrorMode("Mirror Mode", false)
float autoGainValue
Definition advanced.h:91
UISlider audioGain("Audio Gain", 1.0f, 0.1f, 5.0f, 0.1f)
CRGBPalette16 getCurrentPalette()
Definition advanced.h:103
#define HEIGHT
Definition advanced.h:37
void clearDisplay()
Definition advanced.h:167
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
#define MAX(a, b)
Definition math_macros.h:37
FASTLED_FORCE_INLINE T clamp(T value, T min, T max)
Definition clamp.h:10
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86

References audioGain(), autoGainValue, fl::clamp(), clearDisplay(), ColorFromPalette(), fft, fftSmooth, getCurrentPalette(), HEIGHT, hue, leds, MAX, mirrorMode(), noiseFloor(), NUM_BANDS, NUM_LEDS, palette(), WIDTH, x, xyMap, and y.

Referenced by loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: