37#define NUM_LEDS (WIDTH * HEIGHT)
39#define LED_TYPE WS2812B
40#define COLOR_ORDER GRB
43#define SAMPLE_RATE 44100
53 {
"Spectrum Bars",
"Radial Spectrum",
"Waveform",
"VU Meter",
"Matrix Rain",
"Fire Effect",
"Plasma Wave"});
64 {
"Rainbow",
"Heat",
"Ocean",
"Forest",
"Party",
"Lava",
"Cloud"});
121 for (
int i = 0; i < 20; i++) {
128 for (
int i = 0; i < 20; i++) {
136 uint32_t currentTime = millis();
138 if (energy > threshold && (currentTime -
lastBeatTime) > 80) {
152 static float targetLevel = 0.7f;
153 static float avgLevel = 0.0f;
155 avgLevel = avgLevel * 0.95f + level * 0.05f;
157 if (avgLevel > 0.01f) {
158 float gainAdjust = targetLevel / avgLevel;
159 gainAdjust =
fl::clamp(gainAdjust, 0.5f, 2.0f);
180 for (
size_t band = 0; band <
NUM_BANDS && band <
fft->bins_db.size(); band++) {
181 float magnitude =
fft->bins_db[band];
184 magnitude = magnitude / 100.0f;
193 magnitude =
fl::clamp(magnitude, 0.0f, 1.0f);
195 int barHeight = magnitude *
HEIGHT;
196 int xStart = band * barWidth;
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
205 int ledIndex =
xyMap(xStart +
x,
y);
206 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
207 leds[ledIndex] = color;
212 if (mirrorIndex >= 0 && mirrorIndex <
NUM_LEDS) {
213 leds[mirrorIndex] = color;
226 int centerX =
WIDTH / 2;
229 for (
size_t angle = 0; angle < 360; angle += 6) {
231 if (band >=
fft->bins_db.size())
continue;
233 float magnitude =
fft->bins_db[band] / 100.0f;
236 magnitude =
fl::clamp(magnitude, 0.0f, 1.0f);
240 for (
int r = 0; r < radius; r++) {
241 int x = centerX + (r * cosf(angle *
PI / 180.0f));
242 int y = centerY + (r * sinf(angle *
PI / 180.0f));
245 uint8_t colorIndex = fl::map_range<int, uint8_t>(r, 0, radius, 255, 0);
247 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
260 int samplesPerPixel = pcm.
size() /
WIDTH;
263 for (
size_t x = 0;
x <
WIDTH;
x++) {
264 size_t sampleIndex =
x * samplesPerPixel;
265 if (sampleIndex >= pcm.
size())
break;
268 float sample = float(pcm[sampleIndex]) / 32768.0f;
271 float absSample = fabsf(sample);
272 float logAmplitude = 0.0f;
274 if (absSample > 0.001f) {
277 logAmplitude = log10f(1.0f + scaledSample * 9.0f) / log10f(10.0f);
281 logAmplitude = powf(logAmplitude, 0.7f);
284 int amplitude = int(logAmplitude * (
HEIGHT / 2));
288 if (sample < 0) amplitude = -amplitude;
291 uint8_t colorIndex = fl::map_range<int, uint8_t>(abs(amplitude), 0,
HEIGHT/2, 40, 255);
295 if (abs(amplitude) <
HEIGHT / 4) {
300 if (amplitude == 0) {
302 int ledIndex =
xyMap(
x, centerY);
303 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
308 int startY = (amplitude > 0) ? centerY : centerY + amplitude;
309 int endY = (amplitude > 0) ? centerY + amplitude : centerY;
311 for (
int y = startY;
y <= endY;
y++) {
314 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
316 CRGB pixelColor = color;
317 if (
y == startY ||
y == endY) {
320 leds[ledIndex] = pixelColor;
337 for (
int x = 0;
x < rmsWidth;
x++) {
339 uint8_t colorIndex = fl::map_range<int, uint8_t>(
x, 0,
WIDTH, 0, 255);
341 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
352 int ledIndex =
xyMap(peakX,
y);
353 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
361 int ledIndex1 =
xyMap(
x, 0);
374 int currentIndex =
xyMap(
x,
y);
375 int aboveIndex =
xyMap(
x,
y - 1);
376 if (currentIndex >= 0 && currentIndex <
NUM_LEDS &&
377 aboveIndex >= 0 && aboveIndex <
NUM_LEDS) {
378 leds[currentIndex] =
leds[aboveIndex];
379 leds[currentIndex].fadeToBlackBy(40);
386 for (
int i = 0; i < numDrops; i++) {
388 int ledIndex =
xyMap(
x, 0);
389 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
390 leds[ledIndex] =
CHSV(96, 255, 255);
408 heatLevel = heatLevel * random(80, 120) / 100;
409 heatLevel =
MIN(heatLevel, 255);
412 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
421 static float time = 0;
422 time += 0.05f + (peak * 0.2f);
428 float value = sinf(
x * 0.1f +
time) +
429 sinf(
y * 0.1f -
time) +
430 sinf((
x +
y) * 0.1f +
time) +
431 sinf(sqrtf(
x *
x +
y *
y) * 0.1f -
time);
433 value = (value + 4) / 8;
436 uint8_t colorIndex = value * 255;
438 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
446 Serial.begin(115200);
449 Serial.println(
"Audio Reactive Visualizations");
450 Serial.println(
"Initializing...");
451 Serial.print(
"Display size: ");
467 Serial.println(
"Setup complete!");
487 float rms = sample.
rms() / 32768.0f;
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;
497 float peak = float(maxSample) / 32768.0f;
510 sample.
fft(&fftBins);
517 for (
int i = 0; i <
NUM_LEDS; i++) {
518 leds[i].fadeLightBy(-50);
557 #ifdef __EMSCRIPTEN__
float rms(Slice< const int16_t > data)
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
central include file for FastLED, defines the CFastLED class/object
UINumberField palette("Palette", 0, 0, 2)
UISlider beatSensitivity("Beat Sensitivity", 1.5f, 0.5f, 3.0f, 0.1f)
UICheckbox beatFlash("Beat Flash", true)
void drawMatrixRain(float peak)
SoundLevelMeter soundMeter(0.0, 0.0)
bool detectBeat(float energy)
void drawRadialSpectrum(FFTBins *fft, float)
static const int NUM_BANDS
float fftSmooth[NUM_BANDS]
void drawVUMeter(float rms, float peak)
UISlider fadeSpeed("Fade Speed", 20, 0, 255, 1)
UITitle title("Audio Reactive Visualizations")
UIDescription description("Real-time audio visualizations with beat detection and multiple modes")
uint8_t fireBuffer[WIDTH][HEIGHT]
void drawFireEffect(float peak)
void updateAutoGain(float level)
void drawWaveform(const Slice< const int16_t > &pcm, float)
UISlider noiseFloor("Noise Floor", 0.1f, 0.0f, 1.0f, 0.01f)
void drawSpectrumBars(FFTBins *fft, float)
UIDropdown visualMode("Visualization Mode", {"Spectrum Bars", "Radial Spectrum", "Waveform", "VU Meter", "Matrix Rain", "Fire Effect", "Plasma Wave"})
UICheckbox mirrorMode("Mirror Mode", false)
UISlider brightness("Brightness", 128, 0, 255, 1)
UISlider audioGain("Audio Gain", 1.0f, 0.1f, 5.0f, 0.1f)
CRGBPalette16 getCurrentPalette()
UIAudio audio("Audio Input")
UICheckbox beatDetect("Beat Detection", true)
UICheckbox autoGain("Auto Gain", true)
float plasma[WIDTH][HEIGHT]
void drawPlasmaWave(float peak)
UICheckbox enableAudio("Enable Audio", true)
UIDropdown colorPalette("Color Palette", {"Rainbow", "Heat", "Ocean", "Forest", "Party", "Lava", "Cloud"})
const VectorPCM & pcm() const
void fft(FFTBins *out) const
void fadeToBlackBy(CRGB *leds, fl::u16 num_leds, fl::u8 fadeBy)
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
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.
CRGB HeatColor(fl::u8 temperature)
void fill_solid(struct CRGB *targetArray, int numToFill, const struct CRGB &color)
Fill a range of LEDs with a solid color.
#define FL_DISABLE_WARNING(warning)
#define FL_DISABLE_WARNING_PUSH
#define FL_DISABLE_WARNING_POP
const TProgmemRGBPalette16 OceanColors_p
Ocean colors, blues and whites.
const TProgmemRGBPalette16 CloudColors_p
Cloudy color palette.
const TProgmemRGBPalette16 HeatColors_p
Approximate "black body radiation" palette, akin to the FastLED HeatColor() function.
const TProgmemRGBPalette16 ForestColors_p
Forest colors, greens.
const TProgmemRGBPalette16 LavaColors_p
Lava color palette.
const TProgmemRGBPalette16 PartyColors_p
HSV color ramp: blue, purple, pink, red, orange, yellow (and back).
const TProgmemRGBPalette16 RainbowColors_p
HSV Rainbow.
FASTLED_FORCE_INLINE T clamp(T value, T min, T max)
fl::u32 time()
Universal millisecond timer - returns milliseconds since system startup.
CRGB & fadeToBlackBy(fl::u8 fadefactor)
fadeToBlackBy is a synonym for nscale8(), as a fade instead of a scale
@ White
<div style='background:#FFFFFF;width:4em;height:4em;'></div>
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Representation of an RGB pixel (Red, Green, Blue)
Representation of an HSV pixel (hue, saturation, value (aka brightness)).