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

◆ drawSpectrumBars()

void drawSpectrumBars ( fl::audio::fft::Bins * fft,
float  )

Definition at line 182 of file advanced.h.

182 {
183 clearDisplay();
184 fl::CRGBPalette16 palette = getCurrentPalette();
185
186 int barWidth = WIDTH / NUM_BANDS;
187
188 auto bands = fft->db();
189
190 for (size_t band = 0; band < NUM_BANDS && band < bands.size(); band++) {
191 float magnitude = bands[band];
192
193 // Apply noise floor
194 magnitude = magnitude / 100.0f; // Normalize from dB
195 magnitude = fl::max(0.0f, magnitude - noiseFloor.value());
196
197 // Smooth the FFT
198 fftSmooth[band] = fftSmooth[band] * 0.8f + magnitude * 0.2f;
199 magnitude = fftSmooth[band];
200
201 // Apply gain
202 magnitude *= audioGain.value() * autoGainValue;
203 magnitude = fl::clamp(magnitude, 0.0f, 1.0f);
204
205 int barHeight = magnitude * HEIGHT;
206 int xStart = band * barWidth;
207
208 for (int x = 0; x < fl::max(barWidth, 1); x++) {
209 for (int y = 0; y < barHeight; y++) {
211 float(y) / HEIGHT, 0, 1, 0, 255
212 );
213 fl::CRGB color = ColorFromPalette(palette, colorIndex + hue);
214
215 int ledIndex = xyMap(xStart + x, y);
216 if (ledIndex >= 0 && ledIndex < NUM_LEDS) {
217 leds[ledIndex] = color;
218 }
219
220 if (mirrorMode) {
221 int mirrorIndex = xyMap(WIDTH - 1 - (xStart + x), y);
222 if (mirrorIndex >= 0 && mirrorIndex < NUM_LEDS) {
223 leds[mirrorIndex] = color;
224 }
225 }
226 }
227 }
228 }
229}
fl::XYMap xyMap
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
int y
Definition simple.h:93
int x
Definition simple.h:92
UINumberField palette("Palette", 0, 0, 2)
AudioAnalyzeFFT1024 fft
#define WIDTH
fl::CRGBPalette16 getCurrentPalette()
Definition advanced.h:109
static const int NUM_BANDS
Definition advanced.h:82
float fftSmooth[NUM_BANDS]
Definition advanced.h:83
fl::UISlider noiseFloor("Noise Floor", 0.1f, 0.0f, 1.0f, 0.01f)
float autoGainValue
Definition advanced.h:90
fl::UICheckbox mirrorMode("Mirror Mode", false)
fl::UISlider audioGain("Audio Gain", 1.0f, 0.1f, 5.0f, 0.1f)
uint8_t hue
Definition advanced.h:94
#define HEIGHT
void clearDisplay()
Definition advanced.h:173
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75
FASTLED_FORCE_INLINE U map_range(T value, T in_min, T in_max, U out_min, U out_max) FL_NOEXCEPT
Definition math.h:174
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NOEXCEPT
unsigned char uint8_t
Definition s16x16x4.h:209
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38

References audioGain(), autoGainValue, fl::clamp(), clearDisplay(), ColorFromPalette(), fft, fftSmooth, getCurrentPalette(), HEIGHT, hue, leds, fl::map_range(), fl::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: