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

◆ loop()

void loop ( )

Definition at line 472 of file advanced.h.

472 {
473 // Check if audio is enabled
474 if (!enableAudio) {
475 // Show a simple test pattern
477 FastLED.show();
478 delay(20);
479 return;
480 }
481
482 // Process only one audio sample per frame to avoid accumulation
483 AudioSample sample = audio.next();
484 if (sample.isValid()) {
485 // Update sound meter
486 soundMeter.processBlock(sample.pcm());
487
488 // Get audio levels
489 float rms = sample.rms() / 32768.0f;
490
491 // Calculate peak
492 int32_t maxSample = 0;
493 for (size_t i = 0; i < sample.pcm().size(); i++) {
494 int32_t absSample = fabsf(sample.pcm()[i]);
495 if (absSample > maxSample) {
496 maxSample = absSample;
497 }
498 }
499 float peak = float(maxSample) / 32768.0f;
500 peakLevel = peakLevel * 0.9f + peak * 0.1f; // Smooth peak
501
502 // Update auto gain
504
505 // Beat detection
506 if (beatDetect) {
507 isBeat = detectBeat(peak);
508 }
509
510 // Get FFT data - create local FFTBins to avoid accumulation
511 FFTBins fftBins(NUM_BANDS);
512 sample.fft(&fftBins);
513
514 // Update color animation
515 hue += 1;
516
517 // Apply beat flash
518 if (isBeat && beatFlash) {
519 for (int i = 0; i < NUM_LEDS; i++) {
520 leds[i].fadeLightBy(-50); // Make brighter
521 }
522 }
523
524 // Draw selected visualization
525 switch (visualMode.as_int()) {
526 case 0: // Spectrum Bars
527 drawSpectrumBars(&fftBins, peakLevel);
528 break;
529
530 case 1: // Radial Spectrum
531 drawRadialSpectrum(&fftBins, peakLevel);
532 break;
533
534 case 2: // Waveform
535 drawWaveform(sample.pcm(), peakLevel);
536 break;
537
538 case 3: // VU Meter
540 break;
541
542 case 4: // Matrix Rain
544 break;
545
546 case 5: // Fire Effect
548 break;
549
550 case 6: // Plasma Wave
552 break;
553 }
554 }
555
556 FastLED.show();
557
558 // Add a small delay to prevent tight loops in WebAssembly
559 #ifdef __EMSCRIPTEN__
560 delay(1);
561 #endif
562}
CRGB leds[NUM_LEDS]
#define NUM_LEDS
uint8_t hue
float rms(Slice< const int16_t > data)
Definition simple.h:98
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:74
UICheckbox beatFlash("Beat Flash", true)
void drawMatrixRain(float peak)
Definition advanced.h:372
SoundLevelMeter soundMeter(0.0, 0.0)
bool detectBeat(float energy)
Definition advanced.h:117
void drawRadialSpectrum(FFTBins *fft, float)
Definition advanced.h:224
bool isBeat
Definition advanced.h:90
static const int NUM_BANDS
Definition advanced.h:83
void drawVUMeter(float rms, float peak)
Definition advanced.h:331
void drawFireEffect(float peak)
Definition advanced.h:398
void updateAutoGain(float level)
Definition advanced.h:148
float peakLevel
Definition advanced.h:92
void drawWaveform(const Slice< const int16_t > &pcm, float)
Definition advanced.h:258
void drawSpectrumBars(FFTBins *fft, float)
Definition advanced.h:176
UIDropdown visualMode("Visualization Mode", {"Spectrum Bars", "Radial Spectrum", "Waveform", "VU Meter", "Matrix Rain", "Fire Effect", "Plasma Wave"})
UIAudio audio("Audio Input")
UICheckbox beatDetect("Beat Detection", true)
void drawPlasmaWave(float peak)
Definition advanced.h:422
UICheckbox enableAudio("Enable Audio", true)
void fill_rainbow(struct CRGB *targetArray, int numToFill, fl::u8 initialhue, fl::u8 deltahue=5)
Fill a range of LEDs with a rainbow of colors.
Definition fill.cpp:29

References audio(), beatDetect(), beatFlash(), detectBeat(), drawFireEffect(), drawMatrixRain(), drawPlasmaWave(), drawRadialSpectrum(), drawSpectrumBars(), drawVUMeter(), drawWaveform(), enableAudio(), FastLED, fl::AudioSample::fft(), fill_rainbow(), hue, isBeat, fl::AudioSample::isValid(), leds, NUM_BANDS, NUM_LEDS, fl::AudioSample::pcm(), peakLevel, fl::AudioSample::rms(), rms(), soundMeter(), updateAutoGain(), and visualMode().

+ Here is the call graph for this function: