Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
fastFourrierTransform.hpp
Go to the documentation of this file.
1#ifndef FFT_MODE_H
2#define FFT_MODE_H
3
5
8
10
15{
17 static constexpr auto palette = colors::PalettePartyColors;
18
19 static void loop(auto& ctx)
20 {
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);
25
26 const auto& fft_log = state.soundEvent.fft_log;
27 const float maxFftVal = state.soundEvent.maxAmplitude;
28
29 // adjust for volume
30 const float maxLevel = lmpd_map<float>(state.soundEvent.level,
33 0.0,
34 1.0);
35 const float maxDisplaylevel = std::max<float>(2, lmpd_constrain<float>(maxLevel * rows, 2, rows));
36
37 for (uint8_t x = 0; x < cols; ++x)
38 {
39 const uint8_t mappedX =
40 lmpd_map<uint8_t>(x, 0, cols, 0, physical::microphone::SoundStruct::numberOfFFtChanels - 1);
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++)
44 {
45 uint8_t colorIndex = lmpd_map<uint8_t>(y, 0, rows - 1, 0, 255);
46
47 const auto& ledColor = colors::from_palette<false, uint8_t>(colorIndex, palette);
48 ctx.lamp.setPixelColorXY(x, rows - y, ledColor);
49 }
50 // set rest to black
51 for (uint8_t y = mappedY; y <= rows; ++y)
52 ctx.lamp.setPixelColorXY(x, rows - y, 0);
53 }
54 }
55
56 static void on_enter_mode(auto& ctx) { ctx.state.soundEvent.reset(ctx); }
57
58 struct StateTy
59 {
62 };
63};
64
65} // namespace lampda::modes::default_modes
66
67#endif
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
audio::SoundEventTy soundEvent
handle sound events
Definition: fastFourrierTransform.hpp:61
Display the Fourrier Transform of the current room sound.
Definition: fastFourrierTransform.hpp:15
static constexpr auto palette
color palette to use for this mode
Definition: fastFourrierTransform.hpp:17
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