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

◆ loop()

void loop ( )

Definition at line 470 of file advanced.h.

470 {
471 // Check if audio is enabled
472 if (!enableAudio) {
473 // Show a simple test pattern
475 FastLED.show();
476 delay(20);
477 return;
478 }
479
480 // Process only one audio sample per frame to avoid accumulation
481 AudioSample sample = audio.next();
482 if (sample.isValid()) {
483 // Update sound meter
484 soundMeter.processBlock(sample.pcm());
485
486 // Get audio levels
487 float rms = sample.rms() / 32768.0f;
488
489 // Calculate peak
490 int32_t maxSample = 0;
491 for (size_t i = 0; i < sample.pcm().size(); i++) {
492 int32_t absSample = fabsf(sample.pcm()[i]);
493 if (absSample > maxSample) {
494 maxSample = absSample;
495 }
496 }
497 float peak = float(maxSample) / 32768.0f;
498 peakLevel = peakLevel * 0.9f + peak * 0.1f; // Smooth peak
499
500 // Update auto gain
502
503 // Beat detection
504 if (beatDetect) {
505 isBeat = detectBeat(peak);
506 }
507
508 // Get FFT data - create local FFTBins to avoid accumulation
509 FFTBins fftBins(NUM_BANDS);
510 sample.fft(&fftBins);
511
512 // Update color animation
513 hue += 1;
514
515 // Apply beat flash
516 if (isBeat && beatFlash) {
517 for (int i = 0; i < NUM_LEDS; i++) {
518 leds[i].fadeLightBy(-50); // Make brighter
519 }
520 }
521
522 // Draw selected visualization
523 switch (visualMode.as_int()) {
524 case 0: // Spectrum Bars
525 drawSpectrumBars(&fftBins, peakLevel);
526 break;
527
528 case 1: // Radial Spectrum
529 drawRadialSpectrum(&fftBins, peakLevel);
530 break;
531
532 case 2: // Waveform
533 drawWaveform(sample.pcm(), peakLevel);
534 break;
535
536 case 3: // VU Meter
538 break;
539
540 case 4: // Matrix Rain
542 break;
543
544 case 5: // Fire Effect
546 break;
547
548 case 6: // Plasma Wave
550 break;
551 }
552 }
553
554 FastLED.show();
555
556 // Add a small delay to prevent tight loops in WebAssembly
557 #ifdef __EMSCRIPTEN__
558 delay(1);
559 #endif
560}
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:370
SoundLevelMeter soundMeter(0.0, 0.0)
bool detectBeat(float energy)
Definition advanced.h:115
void drawRadialSpectrum(FFTBins *fft, float)
Definition advanced.h:222
bool isBeat
Definition advanced.h:88
static const int NUM_BANDS
Definition advanced.h:81
void drawVUMeter(float rms, float peak)
Definition advanced.h:329
void drawFireEffect(float peak)
Definition advanced.h:396
void updateAutoGain(float level)
Definition advanced.h:146
float peakLevel
Definition advanced.h:90
void drawWaveform(const Slice< const int16_t > &pcm, float)
Definition advanced.h:256
void drawSpectrumBars(FFTBins *fft, float)
Definition advanced.h:174
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:420
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: