39#define NUM_LEDS (WIDTH * HEIGHT)
41#define LED_TYPE WS2812B
42#define COLOR_ORDER GRB
45#define SAMPLE_RATE 44100
55 {
"Spectrum Bars",
"Radial Spectrum",
"Waveform",
"VU Meter",
"Matrix Rain",
"Fire Effect",
"Plasma Wave"});
66 {
"Rainbow",
"Heat",
"Ocean",
"Forest",
"Party",
"Lava",
"Cloud"});
123 for (
int i = 0; i < 20; i++) {
130 for (
int i = 0; i < 20; i++) {
138 uint32_t currentTime = millis();
140 if (energy > threshold && (currentTime -
lastBeatTime) > 80) {
154 static float targetLevel = 0.7f;
155 static float avgLevel = 0.0f;
157 avgLevel = avgLevel * 0.95f + level * 0.05f;
159 if (avgLevel > 0.01f) {
160 float gainAdjust = targetLevel / avgLevel;
161 gainAdjust =
fl::clamp(gainAdjust, 0.5f, 2.0f);
182 for (
size_t band = 0; band <
NUM_BANDS && band <
fft->bins_db.size(); band++) {
183 float magnitude =
fft->bins_db[band];
186 magnitude = magnitude / 100.0f;
195 magnitude =
fl::clamp(magnitude, 0.0f, 1.0f);
197 int barHeight = magnitude *
HEIGHT;
198 int xStart = band * barWidth;
200 for (
int x = 0;
x < barWidth - 1;
x++) {
201 for (
int y = 0;
y < barHeight;
y++) {
202 uint8_t colorIndex = fl::map_range<float, uint8_t>(
203 float(
y) /
HEIGHT, 0, 1, 0, 255
207 int ledIndex =
xyMap(xStart +
x,
y);
208 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
209 leds[ledIndex] = color;
214 if (mirrorIndex >= 0 && mirrorIndex <
NUM_LEDS) {
215 leds[mirrorIndex] = color;
228 int centerX =
WIDTH / 2;
231 for (
size_t angle = 0; angle < 360; angle += 6) {
233 if (band >=
fft->bins_db.size())
continue;
235 float magnitude =
fft->bins_db[band] / 100.0f;
238 magnitude =
fl::clamp(magnitude, 0.0f, 1.0f);
242 for (
int r = 0; r < radius; r++) {
243 int x = centerX + (r * cosf(angle *
PI / 180.0f));
244 int y = centerY + (r * sinf(angle *
PI / 180.0f));
247 uint8_t colorIndex = fl::map_range<int, uint8_t>(r, 0, radius, 255, 0);
249 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
262 int samplesPerPixel = pcm.
size() /
WIDTH;
265 for (
size_t x = 0;
x <
WIDTH;
x++) {
266 size_t sampleIndex =
x * samplesPerPixel;
267 if (sampleIndex >= pcm.
size())
break;
270 float sample = float(pcm[sampleIndex]) / 32768.0f;
273 float absSample = fabsf(sample);
274 float logAmplitude = 0.0f;
276 if (absSample > 0.001f) {
279 logAmplitude = log10f(1.0f + scaledSample * 9.0f) / log10f(10.0f);
283 logAmplitude = powf(logAmplitude, 0.7f);
286 int amplitude = int(logAmplitude * (
HEIGHT / 2));
290 if (sample < 0) amplitude = -amplitude;
293 uint8_t colorIndex = fl::map_range<int, uint8_t>(abs(amplitude), 0,
HEIGHT/2, 40, 255);
297 if (abs(amplitude) <
HEIGHT / 4) {
302 if (amplitude == 0) {
304 int ledIndex =
xyMap(
x, centerY);
305 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
310 int startY = (amplitude > 0) ? centerY : centerY + amplitude;
311 int endY = (amplitude > 0) ? centerY + amplitude : centerY;
313 for (
int y = startY;
y <= endY;
y++) {
316 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
318 CRGB pixelColor = color;
319 if (
y == startY ||
y == endY) {
322 leds[ledIndex] = pixelColor;
339 for (
int x = 0;
x < rmsWidth;
x++) {
341 uint8_t colorIndex = fl::map_range<int, uint8_t>(
x, 0,
WIDTH, 0, 255);
343 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
354 int ledIndex =
xyMap(peakX,
y);
355 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
363 int ledIndex1 =
xyMap(
x, 0);
376 int currentIndex =
xyMap(
x,
y);
377 int aboveIndex =
xyMap(
x,
y - 1);
378 if (currentIndex >= 0 && currentIndex <
NUM_LEDS &&
379 aboveIndex >= 0 && aboveIndex <
NUM_LEDS) {
380 leds[currentIndex] =
leds[aboveIndex];
381 leds[currentIndex].fadeToBlackBy(40);
388 for (
int i = 0; i < numDrops; i++) {
390 int ledIndex =
xyMap(
x, 0);
391 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
392 leds[ledIndex] =
CHSV(96, 255, 255);
410 heatLevel = heatLevel * random(80, 120) / 100;
411 heatLevel =
MIN(heatLevel, 255);
414 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
423 static float time = 0;
424 time += 0.05f + (peak * 0.2f);
430 float value = sinf(
x * 0.1f +
time) +
431 sinf(
y * 0.1f -
time) +
432 sinf((
x +
y) * 0.1f +
time) +
433 sinf(sqrtf(
x *
x +
y *
y) * 0.1f -
time);
435 value = (value + 4) / 8;
438 uint8_t colorIndex = value * 255;
440 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
448 Serial.begin(115200);
451 Serial.println(
"Audio Reactive Visualizations");
452 Serial.println(
"Initializing...");
453 Serial.print(
"Display size: ");
469 Serial.println(
"Setup complete!");
489 float rms = sample.
rms() / 32768.0f;
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;
499 float peak = float(maxSample) / 32768.0f;
512 sample.
fft(&fftBins);
519 for (
int i = 0; i <
NUM_LEDS; i++) {
520 leds[i].fadeLightBy(-50);
559 #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)).