// Kategorie Musik: reagieren auf das Mikrofon // (dazu Spektrum, Puls, Schockwelle, Klangschichten, Klangwelle und Disko aus effects.cpp) #include "fx.h" // --- Pegel: der Würfel füllt sich mit der Lautstärke, Spitzenwert bleibt kurz stehen void renderVu(uint32_t now) { static float level = 0, peak = 0; if (fresh) { fresh = false; level = peak = 0; } float l = audioLevel() * NUM_LAYERS; level = l > level ? l : level * 0.92f; // schnell hoch, langsam zurück peak = level > peak ? level : max(0.0f, peak - 0.03f); FastLED.clear(); FOR_XYZ { float f = constrain(level - z, 0.0f, 1.0f); if (f > 0) at(x, y, z) = CHSV(96 - z * 24, 255, uint8_t(f * min(255, brightness * 2))); // grün .. rot } uint8_t pz = min(TOP, peak); if (peak > 0.5f) for (uint8_t i = 0; i < 16; i++) { // Spitzenwert als heller Ring uint8_t x, y; ringPos(i, x, y); at(x, y, pz) = CRGB(highlight, highlight, highlight); } } // --- Beat-Ebenen: jeder Bass-Schlag lässt eine zufällige Ebene aufleuchten -------- void renderBeatPlanes(uint32_t now) { static uint8_t hue = 0; fadeToBlackBy(leds, NUM_LEDS, 20); if (audioBeat()) { hue += 50; uint8_t axis = random8(3), pos = random8(CUBE_SIZE); FOR_XYZ { if ((axis == 0 ? x : axis == 1 ? y : z) == pos) at(x, y, z) = CHSV(hue, 255, highlight); } } if (random8() < audioLevel() * 200) leds[random16(NUM_LEDS)] += CHSV(hue + 128, 200, brightness); } // --- Klangwürfel: Bass in der Mitte, Mitten in der inneren Schale, Höhen außen ---- void renderSoundCube(uint32_t now) { static float smooth3[3]; float b[CUBE_SIZE]; audioSpectrum(b); float s[3] = {max(b[0], b[1]), b[2], max(b[3], b[4])}; for (uint8_t i = 0; i < 3; i++) smooth3[i] = s[i] > smooth3[i] ? s[i] : smooth3[i] * 0.9f; FOR_XYZ { uint8_t d = shell(x, y, z); uint8_t v = d == 2 ? min(255, brightness * 2) : highlight; // Außenhaut hat die meisten LEDs at(x, y, z) = CHSV(uint8_t(now / 50) + d * 70, 230, uint8_t(smooth3[d] * v)); } } // --- Funkenregen: Funken fallen mit der Lautstärke, jeder Beat gibt einen Schwall -- void renderSparkRain(uint32_t now) { static uint8_t hue = 0; float l = audioLevel(); hue = now / 80; uint8_t n = l * 3 + (random8() < l * 255 ? 1 : 0); for (uint8_t i = 0; i < n; i++) spawnParticle(rnd(0, TOP), rnd(0, TOP), TOP, 0, 0, -rnd(0.05f, 0.1f), CHSV(hue + random8(30), 255, highlight)); if (audioBeat()) for (uint8_t i = 0; i < 12; i++) spawnParticle(MID, MID, TOP, rnd(-0.12f, 0.12f), rnd(-0.12f, 0.12f), rnd(0, 0.08f), CHSV(hue + 128, 200, highlight)); FastLED.clear(); moveParticles(0.006f, 0.98f, 4); drawParticles(); } // --- Oszilloskop: die Lautstärke als Linie, die von vorn nach hinten durchläuft --- void renderScope(uint32_t now) { const uint8_t N = CUBE_SIZE * CUBE_SIZE; static float trace[N]; static uint32_t last = 0; if (fresh) { fresh = false; memset(trace, 0, sizeof(trace)); } if (now - last >= 60) { last = now; memmove(trace + 1, trace, sizeof(float) * (N - 1)); trace[0] = audioLevel(); } FastLED.clear(); for (uint8_t k = 0; k < N; k++) { uint8_t y = k / CUBE_SIZE, x = y % 2 ? k % CUBE_SIZE : TOP - k % CUBE_SIZE; // Schlangenlinie float h = trace[k] * TOP; for (uint8_t z = 0; z < NUM_LAYERS; z++) { float d = fabsf(z - h); if (d < 1) at(x, y, z) += CHSV(160 - y * 30, 255, uint8_t((1 - d) * scale8(highlight, 255 - y * 45))); } } } // --- Ringe: Bass in der Mittelsäule, Mitten im inneren Ring, Höhen am Rand ------ void renderRings(uint32_t now) { float b[CUBE_SIZE]; audioSpectrum(b); float h[3] = {b[0] * NUM_LAYERS, (b[1] + b[2]) * NUM_LAYERS / 2, (b[3] + b[4]) * NUM_LAYERS / 2}; FastLED.clear(); FOR_XYZ { uint8_t r = max(abs(x - 2), abs(y - 2)); float f = constrain(h[r] - z, 0.0f, 1.0f); uint8_t v = r == 2 ? min(255, brightness * 2) : highlight; if (f > 0) at(x, y, z) = CHSV(r * 80 + now / 30, 255, uint8_t(f * v)); } }