Cleanup Code
- FIXED: Same Naming camelCase - FIXED: member variables marked with m_
This commit is contained in:
parent
1a17f1db63
commit
9b791f0765
21 changed files with 201 additions and 196 deletions
|
@ -10,9 +10,9 @@ public:
|
||||||
HIDHelper();
|
HIDHelper();
|
||||||
~HIDHelper();
|
~HIDHelper();
|
||||||
int openDevices();
|
int openDevices();
|
||||||
int get_feature_report(unsigned char *buf, int size) const;
|
int getFeatureReport(unsigned char *buf, int size) const;
|
||||||
int send_feature_report(unsigned char *buf, int size) const;
|
int sendFeatureReport(unsigned char *buf, int size) const;
|
||||||
void close_ctrl_device();
|
void closeCtrlDevice();
|
||||||
|
|
||||||
hid_device *m_ledDevice{};
|
hid_device *m_ledDevice{};
|
||||||
int ctrl_device{};
|
int ctrl_device{};
|
||||||
|
|
|
@ -12,13 +12,13 @@
|
||||||
#include <VulcanoLE/Audio/FFT.h>
|
#include <VulcanoLE/Audio/FFT.h>
|
||||||
#include <VulcanoLE/Audio/Types.h>
|
#include <VulcanoLE/Audio/Types.h>
|
||||||
|
|
||||||
static const char k_record_stream_name[] = "vulcanoLE";
|
static const char recStreamName[] = "vulcanoLE";
|
||||||
static const char k_record_stream_description[] = "Keyboard Input Stream";
|
static const char recStreamDescription[] = "Keyboard Input Stream";
|
||||||
|
|
||||||
static const int32_t k_sample_rate = 44100;
|
static const int32_t sampleRate = 44100;
|
||||||
static const int32_t k_channels = 2;
|
static const int32_t channels = 2;
|
||||||
|
|
||||||
static const std::string k_default_monitor_postfix = ".monitor";
|
static const std::string defaultMonitorPostfix = ".monitor";
|
||||||
|
|
||||||
class AudioGrabber {
|
class AudioGrabber {
|
||||||
public:
|
public:
|
||||||
|
@ -30,29 +30,29 @@ public:
|
||||||
};
|
};
|
||||||
AudioGrabber();
|
AudioGrabber();
|
||||||
~AudioGrabber();
|
~AudioGrabber();
|
||||||
bool read(pcm_stereo_sample *buffer, uint32_t buffer_size);
|
bool read(stereoSample *buffer, uint32_t bufferSize);
|
||||||
static AudioGrabber* createAudioGrabber();
|
static AudioGrabber* createAudioGrabber();
|
||||||
void init();
|
void init();
|
||||||
FFT fft;
|
FFT fft;
|
||||||
ReqMode requestMode = ReqMode::FFT;
|
ReqMode requestMode = ReqMode::FFT;
|
||||||
double loudness = 0.0;
|
double loudness = 0.0;
|
||||||
float getLoudness();
|
float getLoudness();
|
||||||
bool doWork();
|
bool work();
|
||||||
VUtils::Environment *env = nullptr;
|
VUtils::Environment *env = nullptr;
|
||||||
private:
|
private:
|
||||||
std::mutex m_mtx;
|
std::mutex m_mtx;
|
||||||
pcm_stereo_sample *m_pcm_buffer{};
|
stereoSample *m_buffer{};
|
||||||
pa_simple *m_pulseaudio_simple{};
|
pa_simple *m_pulseaudioSimple{};
|
||||||
pa_mainloop *m_pulseaudio_mainloop{};
|
pa_mainloop *m_pulseaudioMainloop{};
|
||||||
std::string m_pulseaudio_default_source_name;
|
std::string m_PulseaudioDefaultSourceName;
|
||||||
void populate_default_source_name();
|
void populateDefaultSourceName();
|
||||||
bool open_pulseaudio_source(uint32_t max_buffer_size);
|
bool openPulseaudioSource(uint32_t maxBufferSize);
|
||||||
static void pulseaudio_context_state_callback(pa_context *c,
|
static void pulseaudioContextStateCallback(pa_context *c,
|
||||||
void *userdata);
|
void *userdata);
|
||||||
static void pulseaudio_server_info_callback(pa_context *context,
|
static void pulseaudioServerInfoCallback(pa_context *context,
|
||||||
const pa_server_info *i,
|
const pa_server_info *i,
|
||||||
void *userdata);
|
void *userdata);
|
||||||
void calculateRMS(pcm_stereo_sample *pFrame);
|
void calculateRMS(stereoSample *pFrame);
|
||||||
void calculatePEAK(pcm_stereo_sample *pFrame);
|
void calculatePEAK(stereoSample *pFrame);
|
||||||
double m_scale = 1.0;
|
double m_scale = 1.0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,23 +2,23 @@
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <fftw3.h>
|
#include <fftw3.h>
|
||||||
#include "Types.h"
|
#include <VulcanoLE/Audio/Types.h>
|
||||||
|
|
||||||
class FFT {
|
class FFT {
|
||||||
public:
|
public:
|
||||||
FFT();
|
FFT();
|
||||||
~FFT();
|
~FFT();
|
||||||
void process(pcm_stereo_sample *pFrame);
|
void process(stereoSample *frame);
|
||||||
outputSample *getData();
|
outputSample *getData();
|
||||||
bool prepareInput(pcm_stereo_sample *buffer, uint32_t sample_size);
|
bool prepareInput(stereoSample *buffer, uint32_t sampleSize);
|
||||||
protected:
|
protected:
|
||||||
double *m_fftw_input_left{};
|
double *m_fftwInputLeft{};
|
||||||
double *m_fftw_input_right{};
|
double *m_fftwInputRight{};
|
||||||
fftw_complex *m_fftw_output_left{};
|
fftw_complex *m_fftwOutputLeft{};
|
||||||
fftw_complex *m_fftw_output_right{};
|
fftw_complex *m_fftwOutputRight{};
|
||||||
outputSample *m_sample = new outputSample(FFT_SIZE);
|
outputSample *m_sample = new outputSample(FFT_SIZE);
|
||||||
fftw_plan m_fftw_plan_left{};
|
fftw_plan m_fftwPlanLeft{};
|
||||||
fftw_plan m_fftw_plan_right{};
|
fftw_plan m_fftwPlanRight{};
|
||||||
std::mutex m_mtx;
|
std::mutex m_mtx;
|
||||||
size_t m_fftw_results;
|
size_t m_fftwResults;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
#define FFT_SIZE 1024
|
#define FFT_SIZE 1024
|
||||||
#define BUFFER_SIZE 2048
|
#define BUFFER_SIZE 2048
|
||||||
|
|
||||||
struct stereo_sample_frame {
|
struct stereoSampleFrame {
|
||||||
float l;
|
float l;
|
||||||
float r;
|
float r;
|
||||||
};
|
};
|
||||||
|
|
||||||
using pcm_stereo_sample = struct stereo_sample_frame;
|
using stereoSample = struct stereoSampleFrame;
|
||||||
|
|
||||||
struct outputSample {
|
struct outputSample {
|
||||||
explicit outputSample(int fftSize) {
|
explicit outputSample(int fftSize) {
|
||||||
|
|
|
@ -20,12 +20,12 @@ class Vulcan121 {
|
||||||
public:
|
public:
|
||||||
explicit Vulcan121(HIDHelper *helper);
|
explicit Vulcan121(HIDHelper *helper);
|
||||||
~Vulcan121();
|
~Vulcan121();
|
||||||
int send_led_map(led_map *src, bool deleteMap = false);
|
int sendLedMap(led_map *src, bool deleteMap = false);
|
||||||
int send_led_to(rgba rgb);
|
int sendToLEDs(rgba rgb);
|
||||||
bool send_init_sequence();
|
bool sendInitSequence();
|
||||||
bool query_ctrl_report(unsigned char);
|
bool queryCtrlReport(unsigned char id);
|
||||||
bool send_ctrl_report(unsigned char id);
|
bool sendCtrlReport(unsigned char id);
|
||||||
bool wait_for_ctrl_dev();
|
bool waitForCtrlDev();
|
||||||
static led_map *createEmptyLEDMap();
|
static led_map *createEmptyLEDMap();
|
||||||
struct DATA {
|
struct DATA {
|
||||||
int num_rows = NUM_ROWS;
|
int num_rows = NUM_ROWS;
|
||||||
|
@ -43,8 +43,8 @@ protected:
|
||||||
void setupMap();
|
void setupMap();
|
||||||
// we need some mapping feature! rows and cols dont have the same amount of keys. so the struct needs
|
// we need some mapping feature! rows and cols dont have the same amount of keys. so the struct needs
|
||||||
HIDHelper *m_helper;
|
HIDHelper *m_helper;
|
||||||
rgba *rv_fixed[NUM_KEYS]{};
|
rgba *m_fixed[NUM_KEYS]{};
|
||||||
rgba rv_color_off = { 0x0000, 0x0000, 0x0000 };
|
rgba m_colorOff = { 0x0000, 0x0000, 0x0000 };
|
||||||
keys *keyMapRow[NUM_ROWS];
|
keys *keyMapRow[NUM_ROWS];
|
||||||
keys *keyMapCol[NUM_COLS]; // need to find out the count!
|
keys *keyMapCol[NUM_COLS]; // need to find out the count!
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,8 @@ namespace VIZ {
|
||||||
public:
|
public:
|
||||||
Loudness(AudioGrabber *pGrabber, Vulcan121 *pVulcan121);
|
Loudness(AudioGrabber *pGrabber, Vulcan121 *pVulcan121);
|
||||||
~Loudness() override = default;
|
~Loudness() override = default;
|
||||||
void on_setup() override;
|
void onSetup() override;
|
||||||
void on_tick(float delta) override;
|
void onTick(float delta) override;
|
||||||
float lastVal = 0;
|
float lastVal = 0;
|
||||||
const char *name() override;
|
const char *name() override;
|
||||||
std::string m_name = "Loudness Meter";
|
std::string m_name = "Loudness Meter";
|
||||||
|
|
|
@ -11,8 +11,8 @@ namespace VIZ {
|
||||||
public:
|
public:
|
||||||
PoliceLike(AudioGrabber *pGrabber, Vulcan121 *pVulcan121);
|
PoliceLike(AudioGrabber *pGrabber, Vulcan121 *pVulcan121);
|
||||||
~PoliceLike() override = default;
|
~PoliceLike() override = default;
|
||||||
void on_setup() override;
|
void onSetup() override;
|
||||||
void on_tick(float delta) override;
|
void onTick(float delta) override;
|
||||||
void switchOnPeak(double);
|
void switchOnPeak(double);
|
||||||
int tick = 0;
|
int tick = 0;
|
||||||
bool left = true;
|
bool left = true;
|
||||||
|
|
|
@ -15,13 +15,14 @@ namespace VIZ {
|
||||||
public:
|
public:
|
||||||
RainbowLine(AudioGrabber *pGrabber, Vulcan121 *vulcan);
|
RainbowLine(AudioGrabber *pGrabber, Vulcan121 *vulcan);
|
||||||
~RainbowLine() override;
|
~RainbowLine() override;
|
||||||
void on_setup() override;
|
void onSetup() override;
|
||||||
void on_tick(float delta) override;
|
void onTick(float delta) override;
|
||||||
void calcNextDelta(double ratio);
|
void calcNextDelta(double ratio);
|
||||||
void updateMap(double factor);
|
void updateMap(double factor);
|
||||||
const char *name() override;
|
const char *name() override;
|
||||||
std::string m_name = "Rainbow Line";
|
std::string m_name = "Rainbow Line";
|
||||||
led_map *data = Vulcan121::createEmptyLEDMap();
|
led_map *data = Vulcan121::createEmptyLEDMap();
|
||||||
bool firstUnder = true;
|
bool firstUnder = true;
|
||||||
|
double deltaMove(double val);
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -7,8 +7,8 @@ namespace VIZ {
|
||||||
struct Spectrum : public VIZ {
|
struct Spectrum : public VIZ {
|
||||||
Spectrum(AudioGrabber *pGrabber, Vulcan121 *pVulcan121);
|
Spectrum(AudioGrabber *pGrabber, Vulcan121 *pVulcan121);
|
||||||
~Spectrum() override = default;
|
~Spectrum() override = default;
|
||||||
void on_setup() override;
|
void onSetup() override;
|
||||||
void on_tick(float delta) override;
|
void onTick(float delta) override;
|
||||||
double lastVal = 0;
|
double lastVal = 0;
|
||||||
const char *name() override;
|
const char *name() override;
|
||||||
std::string m_name = "Spectrum One";
|
std::string m_name = "Spectrum One";
|
||||||
|
|
|
@ -6,8 +6,8 @@ namespace VIZ {
|
||||||
struct VIZ {
|
struct VIZ {
|
||||||
VIZ(AudioGrabber *pGrabber, Vulcan121 *pVulcan121) : grabber(pGrabber), keyboard(pVulcan121) {}
|
VIZ(AudioGrabber *pGrabber, Vulcan121 *pVulcan121) : grabber(pGrabber), keyboard(pVulcan121) {}
|
||||||
virtual ~VIZ() = default;
|
virtual ~VIZ() = default;
|
||||||
virtual void on_setup() = 0;
|
virtual void onSetup() = 0;
|
||||||
virtual void on_tick(float delta) = 0;
|
virtual void onTick(float delta) = 0;
|
||||||
Vulcan121 *keyboard{};
|
Vulcan121 *keyboard{};
|
||||||
Vulcan121::DATA keyboardData = Vulcan121::DATA{};
|
Vulcan121::DATA keyboardData = Vulcan121::DATA{};
|
||||||
AudioGrabber *grabber{};
|
AudioGrabber *grabber{};
|
||||||
|
|
|
@ -11,9 +11,9 @@ namespace VIZ {
|
||||||
struct VisPlugins {
|
struct VisPlugins {
|
||||||
int mode = 0;
|
int mode = 0;
|
||||||
void init(HIDHelper *, AudioGrabber *);
|
void init(HIDHelper *, AudioGrabber *);
|
||||||
void on_startup();
|
void onStartup();
|
||||||
void on_tick();
|
void onTick();
|
||||||
void on_shutdown();
|
void onShutdown();
|
||||||
void setCurrentMode(int);
|
void setCurrentMode(int);
|
||||||
~VisPlugins();
|
~VisPlugins();
|
||||||
VUtils::Environment *env{};
|
VUtils::Environment *env{};
|
||||||
|
|
|
@ -142,7 +142,7 @@ bool HIDHelper::findLED(hid_device_info *devs, unsigned int product_id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HIDHelper::get_feature_report(unsigned char *buf, int size) const {
|
int HIDHelper::getFeatureReport(unsigned char *buf, int size) const {
|
||||||
int res = ioctl(ctrl_device, HIDIOCGFEATURE(size), buf);
|
int res = ioctl(ctrl_device, HIDIOCGFEATURE(size), buf);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -150,7 +150,7 @@ int HIDHelper::get_feature_report(unsigned char *buf, int size) const {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HIDHelper::send_feature_report(unsigned char *buf, int size) const {
|
int HIDHelper::sendFeatureReport(unsigned char *buf, int size) const {
|
||||||
int res = ioctl(ctrl_device, HIDIOCSFEATURE(size), buf);
|
int res = ioctl(ctrl_device, HIDIOCSFEATURE(size), buf);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -158,7 +158,7 @@ int HIDHelper::send_feature_report(unsigned char *buf, int size) const {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HIDHelper::close_ctrl_device() {
|
void HIDHelper::closeCtrlDevice() {
|
||||||
if (ctrl_device) close(ctrl_device);
|
if (ctrl_device) close(ctrl_device);
|
||||||
ctrl_device = 0;
|
ctrl_device = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,24 +7,24 @@
|
||||||
AudioGrabber::AudioGrabber() = default;
|
AudioGrabber::AudioGrabber() = default;
|
||||||
AudioGrabber::~AudioGrabber() = default;
|
AudioGrabber::~AudioGrabber() = default;
|
||||||
|
|
||||||
bool AudioGrabber::read(pcm_stereo_sample *buffer, uint32_t buffer_size) {
|
bool AudioGrabber::read(stereoSample *buffer, uint32_t bufferSize) {
|
||||||
auto buffer_size_bytes = static_cast<size_t>(sizeof(pcm_stereo_sample) * buffer_size);
|
auto buffer_size_bytes = static_cast<size_t>(sizeof(stereoSample) * bufferSize);
|
||||||
if (m_pulseaudio_simple == nullptr) {
|
if (m_pulseaudioSimple == nullptr) {
|
||||||
open_pulseaudio_source(static_cast<uint32_t>(buffer_size_bytes));
|
openPulseaudioSource(static_cast<uint32_t>(buffer_size_bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_pulseaudio_simple != nullptr) {
|
if (m_pulseaudioSimple != nullptr) {
|
||||||
memset(buffer, 0, buffer_size_bytes);
|
memset(buffer, 0, buffer_size_bytes);
|
||||||
int32_t error_code;
|
int32_t error_code;
|
||||||
auto return_code = pa_simple_read(m_pulseaudio_simple, buffer,
|
auto return_code = pa_simple_read(m_pulseaudioSimple, buffer,
|
||||||
buffer_size_bytes, &error_code);
|
buffer_size_bytes, &error_code);
|
||||||
if (return_code < 0) {
|
if (return_code < 0) {
|
||||||
WARN("Could not finish reading pulse Audio stream buffer\n bytes read: %d buffer\n size: %d", return_code,
|
WARN("Could not finish reading pulse Audio stream buffer\n bytes read: %d buffer\n size: %d", return_code,
|
||||||
buffer_size_bytes)
|
buffer_size_bytes)
|
||||||
// zero out buffer
|
// zero out buffer
|
||||||
memset(buffer, 0, buffer_size_bytes);
|
memset(buffer, 0, buffer_size_bytes);
|
||||||
pa_simple_free(m_pulseaudio_simple);
|
pa_simple_free(m_pulseaudioSimple);
|
||||||
m_pulseaudio_simple = nullptr;
|
m_pulseaudioSimple = nullptr;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -36,51 +36,51 @@ bool AudioGrabber::read(pcm_stereo_sample *buffer, uint32_t buffer_size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AudioGrabber::populate_default_source_name() {
|
void AudioGrabber::populateDefaultSourceName() {
|
||||||
pa_mainloop_api *mainloop_api;
|
pa_mainloop_api *mainloop_api;
|
||||||
pa_context *pulseaudio_context;
|
pa_context *pulseaudio_context;
|
||||||
m_pulseaudio_mainloop = pa_mainloop_new();
|
m_pulseaudioMainloop = pa_mainloop_new();
|
||||||
mainloop_api = pa_mainloop_get_api(m_pulseaudio_mainloop);
|
mainloop_api = pa_mainloop_get_api(m_pulseaudioMainloop);
|
||||||
pulseaudio_context = pa_context_new(mainloop_api, "VulcanoLE device list");
|
pulseaudio_context = pa_context_new(mainloop_api, "VulcanoLE device list");
|
||||||
pa_context_connect(pulseaudio_context, nullptr, PA_CONTEXT_NOFLAGS,
|
pa_context_connect(pulseaudio_context, nullptr, PA_CONTEXT_NOFLAGS,
|
||||||
nullptr);
|
nullptr);
|
||||||
pa_context_set_state_callback(pulseaudio_context,
|
pa_context_set_state_callback(pulseaudio_context,
|
||||||
pulseaudio_context_state_callback,
|
pulseaudioContextStateCallback,
|
||||||
reinterpret_cast<void *>(this));
|
reinterpret_cast<void *>(this));
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
if (pa_mainloop_run(m_pulseaudio_mainloop, &ret) < 0) {
|
if (pa_mainloop_run(m_pulseaudioMainloop, &ret) < 0) {
|
||||||
ERR("Could not open pulseaudio mainloop to find default device name: %d", ret)
|
ERR("Could not open pulseaudio mainloop to find default device name: %d", ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioGrabber::open_pulseaudio_source(uint32_t max_buffer_size) {
|
bool AudioGrabber::openPulseaudioSource(uint32_t maxBufferSize) {
|
||||||
int32_t error_code = 0;
|
int32_t error_code = 0;
|
||||||
static const pa_sample_spec sample_spec = { PA_SAMPLE_FLOAT32NE, k_sample_rate,
|
static const pa_sample_spec sample_spec = { PA_SAMPLE_FLOAT32NE, sampleRate,
|
||||||
k_channels };
|
channels };
|
||||||
static const pa_buffer_attr buffer_attr = { max_buffer_size, 0, 0, 0,
|
static const pa_buffer_attr buffer_attr = { maxBufferSize, 0, 0, 0,
|
||||||
(max_buffer_size / 2) };
|
(maxBufferSize / 2) };
|
||||||
populate_default_source_name();
|
populateDefaultSourceName();
|
||||||
if (!m_pulseaudio_default_source_name.empty()) {
|
if (!m_PulseaudioDefaultSourceName.empty()) {
|
||||||
m_pulseaudio_simple =
|
m_pulseaudioSimple =
|
||||||
pa_simple_new(nullptr, k_record_stream_name, PA_STREAM_RECORD,
|
pa_simple_new(nullptr, recStreamName, PA_STREAM_RECORD,
|
||||||
m_pulseaudio_default_source_name.c_str(),
|
m_PulseaudioDefaultSourceName.c_str(),
|
||||||
k_record_stream_description, &sample_spec,
|
recStreamDescription, &sample_spec,
|
||||||
nullptr, &buffer_attr, &error_code);
|
nullptr, &buffer_attr, &error_code);
|
||||||
}
|
}
|
||||||
if (m_pulseaudio_simple == nullptr) {
|
if (m_pulseaudioSimple == nullptr) {
|
||||||
m_pulseaudio_simple =
|
m_pulseaudioSimple =
|
||||||
pa_simple_new(nullptr, k_record_stream_name, PA_STREAM_RECORD,
|
pa_simple_new(nullptr, recStreamName, PA_STREAM_RECORD,
|
||||||
nullptr, k_record_stream_description,
|
nullptr, recStreamDescription,
|
||||||
&sample_spec, nullptr, &buffer_attr, &error_code);
|
&sample_spec, nullptr, &buffer_attr, &error_code);
|
||||||
}
|
}
|
||||||
if (m_pulseaudio_simple == nullptr) {
|
if (m_pulseaudioSimple == nullptr) {
|
||||||
m_pulseaudio_simple =
|
m_pulseaudioSimple =
|
||||||
pa_simple_new(nullptr, k_record_stream_name, PA_STREAM_RECORD,
|
pa_simple_new(nullptr, recStreamName, PA_STREAM_RECORD,
|
||||||
"0", k_record_stream_description, &sample_spec,
|
"0", recStreamDescription, &sample_spec,
|
||||||
nullptr, &buffer_attr, &error_code);
|
nullptr, &buffer_attr, &error_code);
|
||||||
}
|
}
|
||||||
if (m_pulseaudio_simple != nullptr) {
|
if (m_pulseaudioSimple != nullptr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ bool AudioGrabber::open_pulseaudio_source(uint32_t max_buffer_size) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioGrabber::pulseaudio_context_state_callback(pa_context *c, void *userdata) {
|
void AudioGrabber::pulseaudioContextStateCallback(pa_context *c, void *userdata) {
|
||||||
switch (pa_context_get_state(c)) {
|
switch (pa_context_get_state(c)) {
|
||||||
case PA_CONTEXT_UNCONNECTED:
|
case PA_CONTEXT_UNCONNECTED:
|
||||||
case PA_CONTEXT_CONNECTING:
|
case PA_CONTEXT_CONNECTING:
|
||||||
|
@ -98,7 +98,7 @@ void AudioGrabber::pulseaudio_context_state_callback(pa_context *c, void *userda
|
||||||
|
|
||||||
case PA_CONTEXT_READY: {
|
case PA_CONTEXT_READY: {
|
||||||
pa_operation_unref(pa_context_get_server_info(
|
pa_operation_unref(pa_context_get_server_info(
|
||||||
c, pulseaudio_server_info_callback, userdata));
|
c, pulseaudioServerInfoCallback, userdata));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,21 +106,21 @@ void AudioGrabber::pulseaudio_context_state_callback(pa_context *c, void *userda
|
||||||
case PA_CONTEXT_TERMINATED:
|
case PA_CONTEXT_TERMINATED:
|
||||||
auto *src =
|
auto *src =
|
||||||
reinterpret_cast<AudioGrabber *>(userdata);
|
reinterpret_cast<AudioGrabber *>(userdata);
|
||||||
pa_mainloop_quit(src->m_pulseaudio_mainloop, 0);
|
pa_mainloop_quit(src->m_pulseaudioMainloop, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioGrabber::pulseaudio_server_info_callback(pa_context *context, const pa_server_info *i, void *userdata) {
|
void AudioGrabber::pulseaudioServerInfoCallback(pa_context *context, const pa_server_info *i, void *userdata) {
|
||||||
if (i != nullptr) {
|
if (i != nullptr) {
|
||||||
auto *src = reinterpret_cast<AudioGrabber *>(userdata);
|
auto *src = reinterpret_cast<AudioGrabber *>(userdata);
|
||||||
std::string name = i->default_sink_name;
|
std::string name = i->default_sink_name;
|
||||||
name.append(k_default_monitor_postfix);
|
name.append(defaultMonitorPostfix);
|
||||||
|
|
||||||
src->m_pulseaudio_default_source_name = name;
|
src->m_PulseaudioDefaultSourceName = name;
|
||||||
|
|
||||||
// stop mainloop after finding default name
|
// stop mainloop after finding default name
|
||||||
pa_mainloop_quit(src->m_pulseaudio_mainloop, 0);
|
pa_mainloop_quit(src->m_pulseaudioMainloop, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,14 +130,14 @@ AudioGrabber *AudioGrabber::createAudioGrabber() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioGrabber::init() {
|
void AudioGrabber::init() {
|
||||||
m_pcm_buffer = static_cast<pcm_stereo_sample *>(calloc(BUFFER_SIZE, sizeof(pcm_stereo_sample)));
|
m_buffer = static_cast<stereoSample *>(calloc(BUFFER_SIZE, sizeof(stereoSample)));
|
||||||
if (env != nullptr)
|
if (env != nullptr)
|
||||||
m_scale = env->getAsDouble("audio_scale", 1.0);
|
m_scale = env->getAsDouble("audio_scale", 1.0);
|
||||||
DBG("SET Audio Scale: %.3f", m_scale)
|
DBG("SET Audio Scale: %.3f", m_scale)
|
||||||
loudness = 0.0;
|
loudness = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioGrabber::calculateRMS(pcm_stereo_sample *pFrame) {
|
void AudioGrabber::calculateRMS(stereoSample *pFrame) {
|
||||||
float square = 0, mean;
|
float square = 0, mean;
|
||||||
for (int i = 0; i < BUFFER_SIZE; i++) {
|
for (int i = 0; i < BUFFER_SIZE; i++) {
|
||||||
float left = pFrame[0].l;
|
float left = pFrame[0].l;
|
||||||
|
@ -147,7 +147,7 @@ void AudioGrabber::calculateRMS(pcm_stereo_sample *pFrame) {
|
||||||
loudness = std::sqrt(mean);
|
loudness = std::sqrt(mean);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioGrabber::calculatePEAK(pcm_stereo_sample *pFrame) {
|
void AudioGrabber::calculatePEAK(stereoSample *pFrame) {
|
||||||
float max = 0;
|
float max = 0;
|
||||||
for (int i = 0; i < BUFFER_SIZE; i++) {
|
for (int i = 0; i < BUFFER_SIZE; i++) {
|
||||||
float left = std::abs(pFrame[0].l);
|
float left = std::abs(pFrame[0].l);
|
||||||
|
@ -163,28 +163,28 @@ float AudioGrabber::getLoudness() {
|
||||||
return (float) loudness;
|
return (float) loudness;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioGrabber::doWork() {
|
bool AudioGrabber::work() {
|
||||||
std::unique_lock<std::mutex> lck(m_mtx);
|
std::unique_lock<std::mutex> lck(m_mtx);
|
||||||
if (this->read(m_pcm_buffer, BUFFER_SIZE)) {
|
if (this->read(m_buffer, BUFFER_SIZE)) {
|
||||||
for (int i = 0; i < BUFFER_SIZE; ++i) {
|
for (int i = 0; i < BUFFER_SIZE; ++i) {
|
||||||
// my system is fucking quite
|
// my system is fucking quite
|
||||||
m_pcm_buffer[i].l *= m_scale;
|
m_buffer[i].l *= m_scale;
|
||||||
m_pcm_buffer[i].r *= m_scale;
|
m_buffer[i].r *= m_scale;
|
||||||
}
|
}
|
||||||
switch (requestMode) {
|
switch (requestMode) {
|
||||||
case ReqMode::FFT:
|
case ReqMode::FFT:
|
||||||
fft.process(m_pcm_buffer);
|
fft.process(m_buffer);
|
||||||
break;
|
break;
|
||||||
case ReqMode::RMS:
|
case ReqMode::RMS:
|
||||||
calculateRMS(m_pcm_buffer);
|
calculateRMS(m_buffer);
|
||||||
break;
|
break;
|
||||||
case ReqMode::PEAK:
|
case ReqMode::PEAK:
|
||||||
calculatePEAK(m_pcm_buffer);
|
calculatePEAK(m_buffer);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fft.process(m_pcm_buffer);
|
fft.process(m_buffer);
|
||||||
calculateRMS(m_pcm_buffer);
|
calculateRMS(m_buffer);
|
||||||
calculatePEAK(m_pcm_buffer);
|
calculatePEAK(m_buffer);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
#include <VulcanoLE/Audio/FFT.h>
|
#include <VulcanoLE/Audio/FFT.h>
|
||||||
#include <VUtils/Logging.h>
|
#include <VUtils/Logging.h>
|
||||||
|
|
||||||
void FFT::process(pcm_stereo_sample *pFrame) {
|
void FFT::process(stereoSample *frame) {
|
||||||
std::unique_lock<std::mutex> lck(m_mtx);
|
std::unique_lock<std::mutex> lck(m_mtx);
|
||||||
prepareInput(pFrame, FFT_SIZE);
|
prepareInput(frame, FFT_SIZE);
|
||||||
m_fftw_plan_left = fftw_plan_dft_r2c_1d(static_cast<int>(BUFFER_SIZE), m_fftw_input_left,
|
m_fftwPlanLeft = fftw_plan_dft_r2c_1d(static_cast<int>(BUFFER_SIZE), m_fftwInputLeft,
|
||||||
m_fftw_output_left, FFTW_ESTIMATE);
|
m_fftwOutputLeft, FFTW_ESTIMATE);
|
||||||
m_fftw_plan_right = fftw_plan_dft_r2c_1d(static_cast<int>(BUFFER_SIZE), m_fftw_input_right,
|
m_fftwPlanRight = fftw_plan_dft_r2c_1d(static_cast<int>(BUFFER_SIZE), m_fftwInputRight,
|
||||||
m_fftw_output_right, FFTW_ESTIMATE);
|
m_fftwOutputRight, FFTW_ESTIMATE);
|
||||||
fftw_execute(m_fftw_plan_left);
|
fftw_execute(m_fftwPlanLeft);
|
||||||
fftw_execute(m_fftw_plan_right);
|
fftw_execute(m_fftwPlanRight);
|
||||||
fftw_destroy_plan(m_fftw_plan_left);
|
fftw_destroy_plan(m_fftwPlanLeft);
|
||||||
fftw_destroy_plan(m_fftw_plan_right);
|
fftw_destroy_plan(m_fftwPlanRight);
|
||||||
for (int i = 0; i < FFT_SIZE; ++i) {
|
for (int i = 0; i < FFT_SIZE; ++i) {
|
||||||
double left = (double(*m_fftw_output_left[i]));
|
double left = (double(*m_fftwOutputLeft[i]));
|
||||||
double right = (double(*m_fftw_output_right[i]));
|
double right = (double(*m_fftwOutputRight[i]));
|
||||||
m_sample->leftChannel[i] = left;
|
m_sample->leftChannel[i] = left;
|
||||||
m_sample->rightChannel[i] = right;
|
m_sample->rightChannel[i] = right;
|
||||||
}
|
}
|
||||||
|
@ -26,28 +26,28 @@ outputSample *FFT::getData() {
|
||||||
return m_sample;
|
return m_sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FFT::prepareInput(pcm_stereo_sample *buffer, uint32_t sample_size) {
|
bool FFT::prepareInput(stereoSample *buffer, uint32_t sampleSize) {
|
||||||
bool is_silent = true;
|
bool is_silent = true;
|
||||||
for (auto i = 0u; i < sample_size; ++i) {
|
for (auto i = 0u; i < sampleSize; ++i) {
|
||||||
m_fftw_input_left[i] = buffer[i].l;
|
m_fftwInputLeft[i] = buffer[i].l;
|
||||||
m_fftw_input_right[i] = buffer[i].r;
|
m_fftwInputRight[i] = buffer[i].r;
|
||||||
if (is_silent && (m_fftw_input_left[i] > 0 || m_fftw_input_right[i] > 0)) is_silent = false;
|
if (is_silent && (m_fftwInputLeft[i] > 0 || m_fftwInputRight[i] > 0)) is_silent = false;
|
||||||
}
|
}
|
||||||
return is_silent;
|
return is_silent;
|
||||||
}
|
}
|
||||||
|
|
||||||
FFT::FFT() {
|
FFT::FFT() {
|
||||||
m_fftw_results = (static_cast<size_t>(BUFFER_SIZE) / 2) + 1;
|
m_fftwResults = (static_cast<size_t>(BUFFER_SIZE) / 2) + 1;
|
||||||
|
|
||||||
m_fftw_input_left = static_cast<double *>(
|
m_fftwInputLeft = static_cast<double *>(
|
||||||
fftw_malloc(sizeof(double) * BUFFER_SIZE));
|
fftw_malloc(sizeof(double) * BUFFER_SIZE));
|
||||||
m_fftw_input_right = static_cast<double *>(
|
m_fftwInputRight = static_cast<double *>(
|
||||||
fftw_malloc(sizeof(double) * BUFFER_SIZE));
|
fftw_malloc(sizeof(double) * BUFFER_SIZE));
|
||||||
|
|
||||||
m_fftw_output_left = static_cast<fftw_complex *>(
|
m_fftwOutputLeft = static_cast<fftw_complex *>(
|
||||||
fftw_malloc(sizeof(fftw_complex) * m_fftw_results));
|
fftw_malloc(sizeof(fftw_complex) * m_fftwResults));
|
||||||
m_fftw_output_right = static_cast<fftw_complex *>(
|
m_fftwOutputRight = static_cast<fftw_complex *>(
|
||||||
fftw_malloc(sizeof(fftw_complex) * m_fftw_results));
|
fftw_malloc(sizeof(fftw_complex) * m_fftwResults));
|
||||||
}
|
}
|
||||||
FFT::~FFT() {
|
FFT::~FFT() {
|
||||||
delete m_sample;
|
delete m_sample;
|
||||||
|
|
|
@ -17,7 +17,7 @@ void VisAudioRunner::init() {
|
||||||
grabber->env = env;
|
grabber->env = env;
|
||||||
plugins->env = env;
|
plugins->env = env;
|
||||||
grabber->init();
|
grabber->init();
|
||||||
plugins->on_startup();
|
plugins->onStartup();
|
||||||
LOG("Create Visual Audio Runner Thread")
|
LOG("Create Visual Audio Runner Thread")
|
||||||
thread = std::thread(&VisAudioRunner::run, this);
|
thread = std::thread(&VisAudioRunner::run, this);
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,13 @@ void VisAudioRunner::init() {
|
||||||
void VisAudioRunner::run() const {
|
void VisAudioRunner::run() const {
|
||||||
usleep(5000);
|
usleep(5000);
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
if (grabber->doWork()) {
|
if (grabber->work()) {
|
||||||
plugins->on_tick();
|
plugins->onTick();
|
||||||
} else {
|
} else {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100ul));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100ul));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
usleep(50000);
|
usleep(50000);
|
||||||
DBG("SHUTDOWN HOOk")
|
DBG("SHUTDOWN HOOk")
|
||||||
plugins->on_shutdown();
|
plugins->onShutdown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,14 +26,14 @@ Vulcan121::~Vulcan121() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Vulcan121::send_led_map(led_map *src, bool deleteMap) {
|
int Vulcan121::sendLedMap(led_map *src, bool deleteMap) {
|
||||||
int i, k;
|
int i, k;
|
||||||
rgba rgb;
|
rgba rgb;
|
||||||
unsigned char hwmap[444]{};
|
unsigned char hwmap[444]{};
|
||||||
unsigned char workbuf[65];
|
unsigned char workbuf[65];
|
||||||
memset(hwmap, 0, sizeof(hwmap));
|
memset(hwmap, 0, sizeof(hwmap));
|
||||||
for (k = 0; k < NUM_KEYS; k++) {
|
for (k = 0; k < NUM_KEYS; k++) {
|
||||||
rgb = rv_fixed[k] ? *(rv_fixed[k]) : (src ? src->key[k] : rv_color_off);
|
rgb = m_fixed[k] ? *(m_fixed[k]) : (src ? src->key[k] : m_colorOff);
|
||||||
|
|
||||||
rgb.r = (rgb.r > 255) ? 255 : (rgb.r < 0) ? 0 : rgb.r;
|
rgb.r = (rgb.r > 255) ? 255 : (rgb.r < 0) ? 0 : rgb.r;
|
||||||
rgb.g = (rgb.g > 255) ? 255 : (rgb.g < 0) ? 0 : rgb.g;
|
rgb.g = (rgb.g > 255) ? 255 : (rgb.g < 0) ? 0 : rgb.g;
|
||||||
|
@ -80,12 +80,12 @@ int Vulcan121::send_led_map(led_map *src, bool deleteMap) {
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
int Vulcan121::send_led_to(rgba rgb) {
|
int Vulcan121::sendToLEDs(rgba rgb) {
|
||||||
auto *map = new led_map();
|
auto *map = new led_map();
|
||||||
for (auto &i : map->key) {
|
for (auto &i : map->key) {
|
||||||
i = rgb;
|
i = rgb;
|
||||||
}
|
}
|
||||||
int st = send_led_map(map, true);
|
int st = sendLedMap(map, true);
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,34 +93,34 @@ led_map *Vulcan121::createEmptyLEDMap() {
|
||||||
return new led_map();
|
return new led_map();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vulcan121::send_init_sequence() {
|
bool Vulcan121::sendInitSequence() {
|
||||||
LOG("Sending device init sequence...")
|
LOG("Sending device init sequence...")
|
||||||
unsigned char a[9] = { 0x15, 0x05, 0x07, 0x0a, 0x0b, 0x06, 0x09, 0x0d, 0x13 };
|
unsigned char a[9] = { 0x15, 0x05, 0x07, 0x0a, 0x0b, 0x06, 0x09, 0x0d, 0x13 };
|
||||||
if (!query_ctrl_report(0x0f))
|
if (!queryCtrlReport(0x0f))
|
||||||
return false;
|
return false;
|
||||||
for (auto i : a) {
|
for (auto i : a) {
|
||||||
if (!send_ctrl_report(i) || !wait_for_ctrl_dev()) {
|
if (!sendCtrlReport(i) || !waitForCtrlDev()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_helper->close_ctrl_device();
|
m_helper->closeCtrlDevice();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vulcan121::query_ctrl_report(unsigned char id) {
|
bool Vulcan121::queryCtrlReport(unsigned char id) {
|
||||||
if (id != 0x0f) return false;
|
if (id != 0x0f) return false;
|
||||||
unsigned char buffer[8] = {};
|
unsigned char buffer[8] = {};
|
||||||
int length = 8;
|
int length = 8;
|
||||||
buffer[0] = id;
|
buffer[0] = id;
|
||||||
int res = m_helper->get_feature_report(buffer, length);
|
int res = m_helper->getFeatureReport(buffer, length);
|
||||||
if (res) {
|
if (res) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
ERR("query_ctrl_report(%02hhx) failed", id);
|
ERR("queryCtrlReport(%02hhx) failed", id);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vulcan121::send_ctrl_report(unsigned char id) {
|
bool Vulcan121::sendCtrlReport(unsigned char id) {
|
||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
|
@ -209,19 +209,19 @@ bool Vulcan121::send_ctrl_report(unsigned char id) {
|
||||||
default: ERR("UNKNOWN BUFFER OPTION")
|
default: ERR("UNKNOWN BUFFER OPTION")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int res = m_helper->send_feature_report(buffer, length);
|
int res = m_helper->sendFeatureReport(buffer, length);
|
||||||
if (res == length) return true;
|
if (res == length) return true;
|
||||||
ERR("send_ctrl_report(%02hhx) failed", id)
|
ERR("sendCtrlReport(%02hhx) failed", id)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vulcan121::wait_for_ctrl_dev() {
|
bool Vulcan121::waitForCtrlDev() {
|
||||||
unsigned char buffer[] = { 0x04, 0x00, 0x00, 0x00 };
|
unsigned char buffer[] = { 0x04, 0x00, 0x00, 0x00 };
|
||||||
int res;
|
int res;
|
||||||
while (true) {
|
while (true) {
|
||||||
// 150ms is the magic number here, should suffice on first try.
|
// 150ms is the magic number here, should suffice on first try.
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
res = m_helper->get_feature_report(buffer, sizeof(buffer));
|
res = m_helper->getFeatureReport(buffer, sizeof(buffer));
|
||||||
if (res) {
|
if (res) {
|
||||||
if (buffer[1] == 0x01) break;
|
if (buffer[1] == 0x01) break;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
namespace VIZ {
|
namespace VIZ {
|
||||||
Loudness::Loudness(AudioGrabber *pGrabber, Vulcan121 *pVulcan121) : VIZ(pGrabber, pVulcan121) {}
|
Loudness::Loudness(AudioGrabber *pGrabber, Vulcan121 *pVulcan121) : VIZ(pGrabber, pVulcan121) {}
|
||||||
|
|
||||||
void Loudness::on_setup() {
|
void Loudness::onSetup() {
|
||||||
keyboard->send_led_to({ 0, 0, 0, 0 });
|
keyboard->sendToLEDs({ 0, 0, 0, 0 });
|
||||||
grabber->requestMode = AudioGrabber::ReqMode::PEAK;
|
grabber->requestMode = AudioGrabber::ReqMode::PEAK;
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Loudness::on_tick(float delta) {
|
void Loudness::onTick(float delta) {
|
||||||
auto data = Vulcan121::createEmptyLEDMap();
|
auto data = Vulcan121::createEmptyLEDMap();
|
||||||
float val = grabber->getLoudness();
|
float val = grabber->getLoudness();
|
||||||
val = val > 1.0f ? 1.0f : val;
|
val = val > 1.0f ? 1.0f : val;
|
||||||
|
@ -25,7 +25,7 @@ namespace VIZ {
|
||||||
}
|
}
|
||||||
// delete map! ;)
|
// delete map! ;)
|
||||||
lastVal = val;
|
lastVal = val;
|
||||||
keyboard->send_led_map(data, true);
|
keyboard->sendLedMap(data, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Loudness::name() {
|
const char *Loudness::name() {
|
||||||
|
|
|
@ -5,13 +5,13 @@ namespace VIZ {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoliceLike::on_setup() {
|
void PoliceLike::onSetup() {
|
||||||
keyboard->send_led_to({ 0, 0, 0, 0 });
|
keyboard->sendToLEDs({ 0, 0, 0, 0 });
|
||||||
grabber->requestMode = AudioGrabber::ReqMode::FFT;
|
grabber->requestMode = AudioGrabber::ReqMode::FFT;
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoliceLike::on_tick(float delta) {
|
void PoliceLike::onTick(float delta) {
|
||||||
auto map = Vulcan121::createEmptyLEDMap();
|
auto map = Vulcan121::createEmptyLEDMap();
|
||||||
auto data = grabber->fft.getData()->leftChannel;
|
auto data = grabber->fft.getData()->leftChannel;
|
||||||
auto val = 0.0;
|
auto val = 0.0;
|
||||||
|
@ -32,7 +32,7 @@ namespace VIZ {
|
||||||
map[0].key[col->index[j]] = colors[colorInd];
|
map[0].key[col->index[j]] = colors[colorInd];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
keyboard->send_led_map(map, true);
|
keyboard->sendLedMap(map, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoliceLike::switchOnPeak(double peak) {
|
void PoliceLike::switchOnPeak(double peak) {
|
||||||
|
|
|
@ -18,16 +18,16 @@ namespace VIZ {
|
||||||
delete[] colours;
|
delete[] colours;
|
||||||
delete data;
|
delete data;
|
||||||
}
|
}
|
||||||
void RainbowLine::on_setup() {
|
void RainbowLine::onSetup() {
|
||||||
currentColumn = 0;
|
currentColumn = 0;
|
||||||
updateMap(0);
|
updateMap(0);
|
||||||
tailFactor = VUtils::Math::clamp(grabber->env->getAsDouble("rainbow_tail_factor", 0.3), 0.0, 0.9);
|
tailFactor = VUtils::Math::clamp(grabber->env->getAsDouble("rainbow_tail_factor", 0.3), 0.0, 0.9);
|
||||||
keyboard->send_led_to({ 0, 0, 0, 0 });
|
keyboard->sendToLEDs({ 0, 0, 0, 0 });
|
||||||
grabber->requestMode = AudioGrabber::ReqMode::FFT;
|
grabber->requestMode = AudioGrabber::ReqMode::FFT;
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RainbowLine::on_tick(float delta) {
|
void RainbowLine::onTick(float delta) {
|
||||||
updateMap(tailFactor);
|
updateMap(tailFactor);
|
||||||
deltaElapsed += delta;
|
deltaElapsed += delta;
|
||||||
auto fftData = grabber->fft.getData()->leftChannel;
|
auto fftData = grabber->fft.getData()->leftChannel;
|
||||||
|
@ -38,6 +38,26 @@ namespace VIZ {
|
||||||
val = avg;
|
val = avg;
|
||||||
}
|
}
|
||||||
val = VUtils::Math::clamp(val, 0, 255);
|
val = VUtils::Math::clamp(val, 0, 255);
|
||||||
|
double avg = deltaMove(val);
|
||||||
|
if (deltaElapsed >= deltaNeeded) {
|
||||||
|
deltaElapsed = 0;
|
||||||
|
currentColumn++;
|
||||||
|
if (currentColumn >= keyboardData.num_cols) {
|
||||||
|
currentColumn = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
colours[currentColumn].a = val;
|
||||||
|
auto column = keyboard->getColumn(currentColumn);
|
||||||
|
for (int i = 0; i < column->count; ++i) {
|
||||||
|
auto index = column->index[i];
|
||||||
|
data[0].key[index] = colours[currentColumn];
|
||||||
|
}
|
||||||
|
lastValue = avg;
|
||||||
|
// we clean up the map self later! :)
|
||||||
|
keyboard->sendLedMap(data, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
double RainbowLine::deltaMove(double val) {
|
||||||
auto avg = (lastValue + val) * 0.5;
|
auto avg = (lastValue + val) * 0.5;
|
||||||
if (avg > MAX_PEAK || avg > decayValue) {
|
if (avg > MAX_PEAK || avg > decayValue) {
|
||||||
calcNextDelta(val < MAX_PEAK && firstUnder ? 160 : val);
|
calcNextDelta(val < MAX_PEAK && firstUnder ? 160 : val);
|
||||||
|
@ -50,25 +70,9 @@ namespace VIZ {
|
||||||
if (avg < 10) {
|
if (avg < 10) {
|
||||||
deltaNeeded = 1000000000;
|
deltaNeeded = 1000000000;
|
||||||
}
|
}
|
||||||
if (deltaElapsed >= deltaNeeded) {
|
|
||||||
deltaElapsed = 0;
|
|
||||||
currentColumn++;
|
|
||||||
if (currentColumn >= keyboardData.num_cols) {
|
|
||||||
currentColumn = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (decayValue >= 0)
|
if (decayValue >= 0)
|
||||||
decayValue -= 10;
|
decayValue -= 10;
|
||||||
colours[currentColumn].a = val;
|
return avg;
|
||||||
auto column = keyboard->getColumn(currentColumn);
|
|
||||||
for (int i = 0; i < column->count; ++i) {
|
|
||||||
auto index = column->index[i];
|
|
||||||
data[0].key[index] = colours[currentColumn];
|
|
||||||
}
|
|
||||||
lastValue = avg;
|
|
||||||
// we clean up the map self later! :)
|
|
||||||
keyboard->send_led_map(data, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *RainbowLine::name() {
|
const char *RainbowLine::name() {
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
namespace VIZ {
|
namespace VIZ {
|
||||||
Spectrum::Spectrum(AudioGrabber *pGrabber, Vulcan121 *pVulcan121) : VIZ(pGrabber, pVulcan121) {}
|
Spectrum::Spectrum(AudioGrabber *pGrabber, Vulcan121 *pVulcan121) : VIZ(pGrabber, pVulcan121) {}
|
||||||
|
|
||||||
void Spectrum::on_setup() {
|
void Spectrum::onSetup() {
|
||||||
keyboard->send_led_to({ 0, 0, 0, 0 });
|
keyboard->sendToLEDs({ 0, 0, 0, 0 });
|
||||||
grabber->requestMode = AudioGrabber::ReqMode::FFT;
|
grabber->requestMode = AudioGrabber::ReqMode::FFT;
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
}
|
}
|
||||||
void Spectrum::on_tick(float delta) {
|
void Spectrum::onTick(float delta) {
|
||||||
auto map = Vulcan121::createEmptyLEDMap();
|
auto map = Vulcan121::createEmptyLEDMap();
|
||||||
auto data = grabber->fft.getData()->leftChannel;
|
auto data = grabber->fft.getData()->leftChannel;
|
||||||
// find largest bass ~43hz (44100 / FFT_SIZE) range
|
// find largest bass ~43hz (44100 / FFT_SIZE) range
|
||||||
|
@ -34,7 +34,7 @@ namespace VIZ {
|
||||||
x = 0;
|
x = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
keyboard->send_led_map(map, true);
|
keyboard->sendLedMap(map, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Spectrum::name() {
|
const char *Spectrum::name() {
|
||||||
|
|
|
@ -16,29 +16,29 @@ namespace VIZ {
|
||||||
currentVis = viz[mode];
|
currentVis = viz[mode];
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisPlugins::on_startup() {
|
void VisPlugins::onStartup() {
|
||||||
if (!keyboard->send_init_sequence()) {
|
if (!keyboard->sendInitSequence()) {
|
||||||
ERR("FAILED TO INIT KEYBOARD")
|
ERR("FAILED TO INIT KEYBOARD")
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
currentVis->on_setup();
|
currentVis->onSetup();
|
||||||
start = std::chrono::high_resolution_clock::now();
|
start = std::chrono::high_resolution_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisPlugins::on_tick() {
|
void VisPlugins::onTick() {
|
||||||
auto stop = std::chrono::high_resolution_clock::now();
|
auto stop = std::chrono::high_resolution_clock::now();
|
||||||
auto delta = std::chrono::duration_cast<micro>(stop - start).count();
|
auto delta = std::chrono::duration_cast<micro>(stop - start).count();
|
||||||
currentVis->on_tick(delta);
|
currentVis->onTick(delta);
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
start = stop;
|
start = stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisPlugins::on_shutdown() {
|
void VisPlugins::onShutdown() {
|
||||||
int16_t r = env->getAsInt("shutdown_color_red", 0);
|
int16_t r = env->getAsInt("shutdown_color_red", 0);
|
||||||
int16_t g = env->getAsInt("shutdown_color_green", 0);
|
int16_t g = env->getAsInt("shutdown_color_green", 0);
|
||||||
int16_t b = env->getAsInt("shutdown_color_blue", 150);
|
int16_t b = env->getAsInt("shutdown_color_blue", 150);
|
||||||
int16_t a = env->getAsInt("shutdown_brightness", 100);
|
int16_t a = env->getAsInt("shutdown_brightness", 100);
|
||||||
keyboard->send_led_to({ r, g, b, a });
|
keyboard->sendToLEDs({ r, g, b, a });
|
||||||
}
|
}
|
||||||
|
|
||||||
VisPlugins::~VisPlugins() {
|
VisPlugins::~VisPlugins() {
|
||||||
|
@ -58,7 +58,7 @@ namespace VIZ {
|
||||||
m -= 1;
|
m -= 1;
|
||||||
currentVis = viz[m];
|
currentVis = viz[m];
|
||||||
LOG("Now Using: %s", currentVis->name());
|
LOG("Now Using: %s", currentVis->name());
|
||||||
currentVis->on_setup();
|
currentVis->onSetup();
|
||||||
mode = m;
|
mode = m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue