19 static void loop(
auto& ctx)
21 const uint16_t cols = ctx.lamp.maxWidth - 1;
22 const uint16_t rows = ctx.lamp.maxHeight;
23 auto& state = ctx.state;
24 state.soundEvent.update(ctx);
26 const auto& fft_log = state.soundEvent.fft_log;
27 const float maxFftVal = state.soundEvent.maxAmplitude;
30 const float maxLevel = lmpd_map<float>(state.soundEvent.level,
35 const float maxDisplaylevel = std::max<float>(2, lmpd_constrain<float>(maxLevel * rows, 2, rows));
37 for (uint8_t x = 0; x < cols; ++x)
39 const uint8_t mappedX =
41 const uint8_t mappedY = lmpd_constrain<uint8_t>(
42 lmpd_map<uint8_t>(fft_log[mappedX], 0, maxFftVal, 2, maxDisplaylevel), 2, maxDisplaylevel);
43 for (uint8_t y = 0; y <= mappedY; y++)
45 uint8_t colorIndex = lmpd_map<uint8_t>(y, 0, rows - 1, 0, 255);
47 const auto& ledColor = colors::from_palette<false, uint8_t>(colorIndex,
palette);
48 ctx.lamp.setPixelColorXY(x, rows - y, ledColor);
51 for (uint8_t y = mappedY; y <= rows; ++y)
52 ctx.lamp.setPixelColorXY(x, rows - y, 0);
56 static void on_enter_mode(
auto& ctx) { ctx.state.soundEvent.reset(ctx); }
Define the audio handle object.
static constexpr PaletteTy PalettePartyColors
basically, HSV with no green. looks better when lighing people
Definition: palettes.hpp:378
Basic "default" modes included with the hardware.
Definition: aurora.hpp:12
constexpr float highLevelDb
Microphone is not good enough at after this.
Definition: sound.h:21
constexpr float silenceLevelDb
Decibel level for a silent room.
Definition: sound.h:19
Define some useful color palettes, and tools to use them.
Parent object for all custom user modes.
Definition: mode_type.hpp:53
Sound processor able to detect sound level events.
Definition: utils.hpp:92
static constexpr uint8_t numberOfFFtChanels
Define the number of FFt bins to use. You should set this number close to the lamp max X coordinates.
Definition: sound.h:64