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

◆ drawSpectrumBars()

void drawSpectrumBars ( FFTBins * fft,
float  )

Definition at line 174 of file advanced.h.

174 {
175 clearDisplay();
176 CRGBPalette16 palette = getCurrentPalette();
177
178 int barWidth = WIDTH / NUM_BANDS;
179
180 for (size_t band = 0; band < NUM_BANDS && band < fft->bins_db.size(); band++) {
181 float magnitude = fft->bins_db[band];
182
183 // Apply noise floor
184 magnitude = magnitude / 100.0f; // Normalize from dB
185 magnitude = MAX(0.0f, magnitude - noiseFloor.value());
186
187 // Smooth the FFT
188 fftSmooth[band] = fftSmooth[band] * 0.8f + magnitude * 0.2f;
189 magnitude = fftSmooth[band];
190
191 // Apply gain
192 magnitude *= audioGain.value() * autoGainValue;
193 magnitude = fl::clamp(magnitude, 0.0f, 1.0f);
194
195 int barHeight = magnitude * HEIGHT;
196 int xStart = band * barWidth;
197
198 for (int x = 0; x < barWidth - 1; x++) {
199 for (int y = 0; y < barHeight; y++) {
200 uint8_t colorIndex = fl::map_range<float, uint8_t>(
201 float(y) / HEIGHT, 0, 1, 0, 255
202 );
203 CRGB color = ColorFromPalette(palette, colorIndex + hue);
204
205 int ledIndex = xyMap(xStart + x, y);
206 if (ledIndex >= 0 && ledIndex < NUM_LEDS) {
207 leds[ledIndex] = color;
208 }
209
210 if (mirrorMode) {
211 int mirrorIndex = xyMap(WIDTH - 1 - (xStart + x), y);
212 if (mirrorIndex >= 0 && mirrorIndex < NUM_LEDS) {
213 leds[mirrorIndex] = color;
214 }
215 }
216 }
217 }
218 }
219}
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:57
UINumberField palette("Palette", 0, 0, 2)
AudioAnalyzeFFT1024 fft
#define WIDTH
Definition advanced.h:34
static const int NUM_BANDS
Definition advanced.h:81
float fftSmooth[NUM_BANDS]
Definition advanced.h:82
UISlider noiseFloor("Noise Floor", 0.1f, 0.0f, 1.0f, 0.01f)
UICheckbox mirrorMode("Mirror Mode", false)
float autoGainValue
Definition advanced.h:89
UISlider audioGain("Audio Gain", 1.0f, 0.1f, 5.0f, 0.1f)
CRGBPalette16 getCurrentPalette()
Definition advanced.h:101
#define HEIGHT
Definition advanced.h:35
void clearDisplay()
Definition advanced.h:165
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
#define MAX(a, b)
Definition math_macros.h:45
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: