258 {
261
262 int samplesPerPixel = pcm.size() /
WIDTH;
264
265 for (
size_t x = 0;
x <
WIDTH;
x++) {
266 size_t sampleIndex =
x * samplesPerPixel;
267 if (sampleIndex >= pcm.size()) break;
268
269
270 float sample = float(pcm[sampleIndex]) / 32768.0f;
271
272
273 float absSample = fabsf(sample);
274 float logAmplitude = 0.0f;
275
276 if (absSample > 0.001f) {
277
279 logAmplitude = log10f(1.0f + scaledSample * 9.0f) / log10f(10.0f);
280 }
281
282
283 logAmplitude = powf(logAmplitude, 0.7f);
284
285
286 int amplitude = int(logAmplitude * (
HEIGHT / 2));
288
289
290 if (sample < 0) amplitude = -amplitude;
291
292
293 uint8_t colorIndex = fl::map_range<int, uint8_t>(abs(amplitude), 0,
HEIGHT/2, 40, 255);
295
296
297 if (abs(amplitude) <
HEIGHT / 4) {
299 }
300
301
302 if (amplitude == 0) {
303
304 int ledIndex =
xyMap(
x, centerY);
305 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
307 }
308 } else {
309
310 int startY = (amplitude > 0) ? centerY : centerY + amplitude;
311 int endY = (amplitude > 0) ? centerY + amplitude : centerY;
312
313 for (
int y = startY;
y <= endY;
y++) {
316 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
317
318 CRGB pixelColor = color;
319 if (
y == startY ||
y == endY) {
321 }
322 leds[ledIndex] = pixelColor;
323 }
324 }
325 }
326 }
327 }
328}
UINumberField palette("Palette", 0, 0, 2)
UISlider audioGain("Audio Gain", 1.0f, 0.1f, 5.0f, 0.1f)
CRGBPalette16 getCurrentPalette()
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
FASTLED_FORCE_INLINE T clamp(T value, T min, T max)
CRGB & fadeToBlackBy(fl::u8 fadefactor)
fadeToBlackBy is a synonym for nscale8(), as a fade instead of a scale
Representation of an RGB pixel (Red, Green, Blue)