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

◆ drawRadialSpectrum()

void drawRadialSpectrum ( fl::audio::fft::Bins * fft,
float  )

Definition at line 232 of file advanced.h.

232 {
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}
fl::XYMap xyMap
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
int y
Definition simple.h:93
int x
Definition simple.h:92
UINumberField palette("Palette", 0, 0, 2)
AudioAnalyzeFFT1024 fft
#define WIDTH
fl::CRGBPalette16 getCurrentPalette()
Definition advanced.h:109
static const int NUM_BANDS
Definition advanced.h:82
fl::UISlider noiseFloor("Noise Floor", 0.1f, 0.0f, 1.0f, 0.01f)
float autoGainValue
Definition advanced.h:90
fl::UISlider audioGain("Audio Gain", 1.0f, 0.1f, 5.0f, 0.1f)
uint8_t hue
Definition advanced.h:94
#define HEIGHT
void clearDisplay()
Definition advanced.h:173
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
#define FL_PI
Definition math.h:26
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
Definition math.h:71
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75
FASTLED_FORCE_INLINE U map_range(T value, T in_min, T in_max, U out_min, U out_max) FL_NOEXCEPT
Definition math.h:174
float sinf(float value) FL_NOEXCEPT
Definition math.h:352
float cosf(float value) FL_NOEXCEPT
Definition math.h:358
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NOEXCEPT
unsigned char uint8_t
Definition s16x16x4.h:209

References audioGain(), autoGainValue, fl::clamp(), clearDisplay(), ColorFromPalette(), fl::cosf(), fft, FL_PI, getCurrentPalette(), HEIGHT, hue, leds, fl::map_range(), fl::max(), fl::min(), noiseFloor(), NUM_BANDS, NUM_LEDS, palette(), fl::sinf(), WIDTH, x, xyMap, and y.

Referenced by loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: