Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
vu_meter.hpp
Go to the documentation of this file.
1#ifndef VUMETER_MODE_H
2#define VUMETER_MODE_H
3
5
7
9
11
13struct VuMeterMode : public BasicMode
14{
16 static constexpr auto palette = colors::PaletteGradient<colors::Red, colors::Green>;
17
18 static void loop(auto& ctx)
19 {
20 auto& state = ctx.state;
21 state.soundEvent.update(ctx);
22
23 const float decibels = state.soundEvent.level;
24
25 ctx.lamp.fadeToBlackBy(state.fade);
26 const uint16_t maxLedIndex = ctx.lamp.ledCount - 1;
27
28 // convert the sound level in the height lamp level
29 const uint16_t vuLevel = lmpd_constrain<uint16_t>(
30 lmpd_map<uint16_t>(
32 ceilf(2.0 * ctx.lamp.maxWidthFloat),
33 maxLedIndex);
34
35 ctx.lamp.fill(palette, maxLedIndex - vuLevel, maxLedIndex);
36 }
37
38 static void on_enter_mode(auto& ctx)
39 {
40 ctx.state.fade = 128;
41 ctx.state.soundEvent.reset(ctx);
42 }
43
44 struct StateTy
45 {
47 uint8_t fade;
50 };
51};
52
53} // namespace lampda::modes::default_modes
54
55#endif // VUMETER_MODE_H
Define the audio handle object.
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
uint8_t fade
fade rate
Definition: vu_meter.hpp:47
audio::SoundEventTy soundEvent
sound event tracker
Definition: vu_meter.hpp:49
Emulate a vu-sound meter.
Definition: vu_meter.hpp:14
static constexpr auto palette
color to display
Definition: vu_meter.hpp:16