43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
#include <VulcanoLE/Scripts/Spectrum.h>
|
|
|
|
namespace VIZ {
|
|
Spectrum::Spectrum(AudioGrabber *pGrabber, Vulcan121 *pVulcan121) : VIZ(pGrabber, pVulcan121) {}
|
|
|
|
void Spectrum::on_setup() {
|
|
keyboard->send_led_to({ 0, 0, 0, 0 });
|
|
grabber->requestMode = AudioGrabber::ReqMode::FFT;
|
|
usleep(100000);
|
|
}
|
|
void Spectrum::on_tick() {
|
|
auto map = Vulcan121::createEmptyLEDMap();
|
|
auto data = grabber->fft.getData()->leftChannel;
|
|
// find largest bass ~43hz (44100 / FFT_SIZE) range
|
|
auto val = 0.0;
|
|
for (int i = 1; i < 4; ++i) {
|
|
if (data[ i ] > val) {
|
|
val = data[ i ];
|
|
}
|
|
}
|
|
double newVal = (val + lastVal) / 2.0;
|
|
lastVal = val;
|
|
int split = keyboardData.num_keys / 3;
|
|
int x = 0;
|
|
int colorInd = 0;
|
|
colors[0].a = newVal;
|
|
colors[1].a = newVal;
|
|
colors[2].a = newVal;
|
|
for (int key = 0; key < keyboardData.num_keys; ++key) {
|
|
map[ 0 ].key[ key ] = colors[ colorInd ];
|
|
x++;
|
|
if (x > split) {
|
|
colorInd++;
|
|
x = 0;
|
|
}
|
|
}
|
|
keyboard->send_led_map(map, true);
|
|
}
|
|
|
|
const char *Spectrum::name() {
|
|
return m_name.c_str();
|
|
}
|
|
} |