MCPcopy Create free account
hub / github.com/FastLED/FastLED / drawRadialSpectrum

Function drawRadialSpectrum

examples/Audio/advanced/advanced.h:232–265  ·  view source on GitHub ↗

Visualization: Radial Spectrum

Source from the content-addressed store, hash-verified

230
231// Visualization: Radial Spectrum
232void drawRadialSpectrum(fl::audio::fft::Bins* fft, float /* peak */) {
233 clearDisplay();
234 fl::CRGBPalette16 palette = getCurrentPalette();
235
236 int centerX = WIDTH / 2;
237 int centerY = HEIGHT / 2;
238
239 auto bands = fft->db();
240
241 for (size_t angle = 0; angle < 360; angle += 6) { // Reduced resolution
242 size_t band = (angle / 6) % NUM_BANDS;
243 if (band >= bands.size()) continue;
244
245 float magnitude = bands[band] / 100.0f;
246 magnitude = fl::max(0.0f, magnitude - noiseFloor.value());
247 magnitude *= audioGain.value() * autoGainValue;
248 magnitude = fl::clamp(magnitude, 0.0f, 1.0f);
249
250 int radius = magnitude * (fl::min(WIDTH, HEIGHT) / 2);
251
252 for (int r = 0; r < radius; r++) {
253 int x = centerX + (r * fl::cosf(angle * FL_PI / 180.0f));
254 int y = centerY + (r * fl::sinf(angle * FL_PI / 180.0f));
255
256 if (x >= 0 && x < WIDTH && y >= 0 && y < HEIGHT) {
257 uint8_t colorIndex = fl::map_range<int, uint8_t>(r, 0, radius, 255, 0);
258 int ledIndex = xyMap(x, y);
259 if (ledIndex >= 0 && ledIndex < NUM_LEDS) {
260 leds[ledIndex] = ColorFromPalette(palette, colorIndex + hue);
261 }
262 }
263 }
264 }
265}
266
267// Visualization: Logarithmic Waveform (prevents saturation)
268void drawWaveform(const fl::span<const int16_t>& pcm, float /* peak */) {

Callers 1

loopFunction · 0.85

Calls 10

clearDisplayFunction · 0.85
getCurrentPaletteFunction · 0.85
maxFunction · 0.85
clampFunction · 0.85
cosfFunction · 0.85
sinfFunction · 0.85
ColorFromPaletteFunction · 0.85
dbMethod · 0.80
sizeMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected