256 {
259
260 int samplesPerPixel = pcm.size() /
WIDTH;
262
263 for (
size_t x = 0;
x <
WIDTH;
x++) {
264 size_t sampleIndex =
x * samplesPerPixel;
265 if (sampleIndex >= pcm.size()) break;
266
267
268 float sample = float(pcm[sampleIndex]) / 32768.0f;
269
270
271 float absSample = fabsf(sample);
272 float logAmplitude = 0.0f;
273
274 if (absSample > 0.001f) {
275
277 logAmplitude = log10f(1.0f + scaledSample * 9.0f) / log10f(10.0f);
278 }
279
280
281 logAmplitude = powf(logAmplitude, 0.7f);
282
283
284 int amplitude = int(logAmplitude * (
HEIGHT / 2));
286
287
288 if (sample < 0) amplitude = -amplitude;
289
290
291 uint8_t colorIndex = fl::map_range<int, uint8_t>(abs(amplitude), 0,
HEIGHT/2, 40, 255);
293
294
295 if (abs(amplitude) <
HEIGHT / 4) {
297 }
298
299
300 if (amplitude == 0) {
301
302 int ledIndex =
xyMap(
x, centerY);
303 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
305 }
306 } else {
307
308 int startY = (amplitude > 0) ? centerY : centerY + amplitude;
309 int endY = (amplitude > 0) ? centerY + amplitude : centerY;
310
311 for (
int y = startY;
y <= endY;
y++) {
314 if (ledIndex >= 0 && ledIndex <
NUM_LEDS) {
315
316 CRGB pixelColor = color;
317 if (
y == startY ||
y == endY) {
319 }
320 leds[ledIndex] = pixelColor;
321 }
322 }
323 }
324 }
325 }
326}
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)