VulcanoLE/src/VulcanoLE/Scripts/WeirdSpec.cpp

65 lines
1.7 KiB
C++

#include <VulcanoLE/Scripts/WeirdSpec.h>
namespace VIZ {
WeirdSpec::WeirdSpec(AudioGrabber *pGrabber, Vulcan121 *pVulcan121) : VIZ(pGrabber, pVulcan121) {
}
void WeirdSpec::on_setup() {
keyboard->send_led_to({ 0, 0, 0, 0 });
grabber->requestMode = AudioGrabber::ReqMode::FFT;
usleep(100000);
}
void WeirdSpec::on_tick() {
auto map = Vulcan121::createEmptyLEDMap();
auto data = grabber->fft.getData()->leftChannel;
auto val = 0.0;
for (int i = 1; i < 4; ++i) {
if (data[ i ] > val) {
val = data[ i ];
}
}
switchOnPeak(val);
tick++;
int colorInd = left ? 0 : 1;
colors[ colorInd ].a = val;
if (left) {
for (int i = 0; i < 62; ++i) {
int ind = i;
map[ 0 ].key[ ind ] = colors[ colorInd ];
}
} else {
for (int i = 62; i < keyboardData.num_keys; ++i) {
int ind = i;
map[ 0 ].key[ ind ] = colors[ colorInd ];
}
}
keyboard->send_led_map(map, true);
}
void WeirdSpec::switchOnPeak(double peak) {
if (tick < 3) {
return;
}
if (peak < 20) {
lastPeak = -1;
return;
}
// we dont have any data! reset ;)
if (lastPeak == -1) {
lastPeak = peak;
return;
}
lastPeak -= decayRate;
if (peak > 100 && peak > lastPeak + threshold) {
left = !left;
lastPeak = peak;
tick = 0;
}
}
const char *WeirdSpec::name() {
return m_name.c_str();
}
}