41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
#include <VUtils/Logging.h>
|
|
#include <VUtils/Math.h>
|
|
#include <VulcanoLE/Colors/ColorHelper.h>
|
|
#include <VulcanoLE/Scripts/Spectrum.h>
|
|
|
|
namespace VIZ {
|
|
Spectrum::Spectrum(AudioGrabber *pGrabber, Vulcan121 *pVulcan121)
|
|
: VIZ(pGrabber, pVulcan121) {}
|
|
|
|
void Spectrum::onSetup() {
|
|
keyboard->sendToLEDs({0, 0, 0, 0});
|
|
grabber->requestMode = AudioGrabber::ReqMode::FFT;
|
|
}
|
|
void Spectrum::onTick(float delta) {
|
|
led_map map{};
|
|
auto *data = grabber->fft.getData()->leftChannel;
|
|
auto val = 0.0;
|
|
for (int i = 0; i < 3; ++i) {
|
|
if (data[i] > val) {
|
|
val = data[i];
|
|
}
|
|
}
|
|
double normalized = val / 255.0;
|
|
if (m_angle > 360.0)
|
|
m_angle -= 360.0;
|
|
m_angle += (normalized * normalized * normalized) * 5.0;
|
|
rgb nColor =
|
|
Color::Generator::rgbFromHSV({m_angle, 1.0, normalized * normalized});
|
|
int16_t r = nColor.r * 255.0;
|
|
int16_t g = nColor.g * 255.0;
|
|
int16_t b = nColor.b * 255.0;
|
|
rgba color = {r, g, b, 255};
|
|
for (int key = 0; key < keyboardData.num_keys; ++key) {
|
|
map.key[key] = color;
|
|
}
|
|
keyboard->sendLedMap(map);
|
|
}
|
|
|
|
const char *Spectrum::name() { return m_name.c_str(); }
|
|
} // namespace VIZ
|