DONT KNOW :D

This commit is contained in:
Maurice Grönwoldt 2021-12-30 18:06:04 +01:00
commit 8505032307
44 changed files with 1360 additions and 275 deletions

View file

@ -1,7 +1,7 @@
#pragma once
#include <string>
#include <unordered_map>
#include <map>
namespace VUtils {
class Environment {
@ -20,7 +20,7 @@ namespace VUtils {
void set(const char* name, const char *value);
void setNumber(const char* name, double value);
protected:
std::unordered_map<std::string, std::string> m_env;
std::map<std::string, std::string> m_env;
std::string m_prefix = "VENV_";
std::string m_filename;
};

View file

@ -7,5 +7,6 @@ namespace VUtils {
static double bezierBlend(double t);
static double easeIn(double ratio);
static double map(double x, double in_min, double in_max, double out_min, double out_max);
static double cubicInterpolate (double y0, double y1, double y2, double y3, double factor);
};
}

23
headers/VUtils/Random.h Normal file
View file

@ -0,0 +1,23 @@
#pragma once
#include <random>
namespace VUtils {
class Random {
public:
static Random& the() {
static Random _instance;
return _instance;
}
Random();
static double generate(double min, double max);
double get(double min, double max);
void setDist(double min, double max);
double getFast();
private:
std::random_device m_rd;
std::mt19937 m_mt;
std::uniform_real_distribution<double> m_dist;
};
}

View file

@ -0,0 +1,55 @@
/**
* @file SimplexNoise.h
* @brief A Perlin Simplex Noise C++ Implementation (1D, 2D, 3D).
*
* Copyright (c) 2014-2018 Sebastien Rombauts (sebastien.rombauts@gmail.com)
*
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT)
*/
#pragma once
#include <cstddef> // size_t
/**
* @brief A Perlin Simplex Noise C++ Implementation (1D, 2D, 3D, 4D).
*/
class SimplexNoise {
public:
// 1D Perlin simplex noise
static float noise(float x);
// 2D Perlin simplex noise
static float noise(float x, float y);
// 3D Perlin simplex noise
static float noise(float x, float y, float z);
// Fractal/Fractional Brownian Motion (fBm) noise summation
float fractal(size_t octaves, float x) const;
float fractal(size_t octaves, float x, float y) const;
float fractal(size_t octaves, float x, float y, float z) const;
/**
* Constructor of to initialize a fractal noise summation
*
* @param[in] frequency Frequency ("width") of the first octave of noise (default to 1.0)
* @param[in] amplitude Amplitude ("height") of the first octave of noise (default to 1.0)
* @param[in] lacunarity Lacunarity specifies the frequency multiplier between successive octaves (default to 2.0).
* @param[in] persistence Persistence is the loss of amplitude between successive octaves (usually 1/lacunarity)
*/
explicit SimplexNoise(float frequency = 1.0f,
float amplitude = 1.0f,
float lacunarity = 2.0f,
float persistence = 0.5f) :
mFrequency(frequency),
mAmplitude(amplitude),
mLacunarity(lacunarity),
mPersistence(persistence) {
}
private:
// Parameters of Fractional Brownian Motion (fBm) : sum of N "octaves" of noise
float mFrequency; ///< Frequency ("width") of the first octave of noise (default to 1.0)
float mAmplitude; ///< Amplitude ("height") of the first octave of noise (default to 1.0)
float mLacunarity; ///< Lacunarity specifies the frequency multiplier between successive octaves (default to 2.0).
float mPersistence; ///< Persistence is the loss of amplitude between successive octaves (usually 1/lacunarity)
};

View file

@ -7,6 +7,7 @@
#include <VUtils/Environment.h>
#include <VulcanoLE/Audio/FFT.h>
#include <VulcanoLE/Audio/Types.h>
#include <VulcanoLE/Audio/Filter.h>
class AudioGrabber {
public:
@ -14,19 +15,22 @@ public:
FFT = 0,
RMS = 1,
PEAK = 2,
ALL = 3
FILTER = 3,
ALL = 4
};
AudioGrabber();
~AudioGrabber();
bool read(stereoSample *buffer, uint32_t bufferSize);
static AudioGrabber* createAudioGrabber();
void init();
Audio::FilterHelper& getFilter();
FFT fft;
ReqMode requestMode = ReqMode::FFT;
stereoSampleFrame loudness = {0.0, 0.0};
stereoSampleFrame getLoudness();
bool work();
VUtils::Environment *env = nullptr;
double getBass();
private:
std::mutex m_mtx;
stereoSample *m_buffer{};
@ -34,4 +38,5 @@ private:
void calculatePEAK(stereoSample *pFrame);
double m_scale = 1.0;
int availableData = 0;
Audio::FilterHelper m_filter;
};

View file

@ -12,6 +12,7 @@ public:
outputSample *getData();
bool prepareInput(stereoSample *buffer, uint32_t sampleSize, double scale);
double hannWindow[BUFFER_SIZE]{};
int size = BUFFER_SIZE;
protected:
fftw_complex *m_fftwInputLeft{};
fftw_complex *m_fftwInputRight{};
@ -25,4 +26,5 @@ protected:
static double valueToAmp(double value);
double times;
static double limit;
};

View file

@ -0,0 +1,30 @@
#include "Types.h"
#include <vector>
#define FILTER_LIMIT 0.25
namespace Audio {
class Filter {
public:
Filter();
float process(float input, float cut, float);
protected:
float output = 0.0;
int m_counter = 0;
float m_feedback[4][16]{};
float m_filterOutput[4]{};
};
struct FilterHelper {
Filter filter_right{};
Filter filter_left{};
float cutoff{};
float scale{1.0};
std::vector<stereoSample> output;
stereoSampleFrame work(stereoSample *buffer, int size);
protected:
double m_limit = FILTER_LIMIT;
int overshot_times = 0;
stereoSampleFrame doLimit(double, double);
};
}

View file

@ -1,5 +1,4 @@
#pragma once
#define FFT_SIZE 512
#define BUFFER_SIZE 1024
struct stereoSampleFrame {

View file

@ -2,7 +2,8 @@
#include <VulcanoLE/Colors/Type.h>
namespace Color {
struct Generator {
static rgba rgbFromRatio(double ratio, int16_t alpha);
};
}
struct Generator {
static rgba rgbFromRatio(double ratio, int16_t alpha);
static rgb rgbFromHSV(hsv in);
};
} // namespace Color

View file

@ -3,8 +3,20 @@
#include <cstdint>
typedef struct rgba_type {
int16_t r{};
int16_t g{};
int16_t b{};
int16_t a = 255;
} rgba;
int16_t r = 0;
int16_t g = 0;
int16_t b = 0;
int16_t a = 0;
} rgba;
typedef struct {
double r; // a fraction between 0 and 1
double g; // a fraction between 0 and 1
double b; // a fraction between 0 and 1
} rgb;
typedef struct {
double h; // angle in degrees
double s; // a fraction between 0 and 1
double v; // a fraction between 0 and 1
} hsv;

View file

@ -20,13 +20,12 @@ class Vulcan121 {
public:
explicit Vulcan121(HIDHelper *helper);
~Vulcan121();
int sendLedMap(led_map *src, bool deleteMap = false);
int sendLedMap(led_map& src);
int sendToLEDs(rgba rgb);
bool sendInitSequence();
bool queryCtrlReport(unsigned char id);
bool sendCtrlReport(unsigned char id);
bool waitForCtrlDev();
static led_map *createEmptyLEDMap();
struct DATA {
int num_rows = NUM_ROWS;
int num_cols = NUM_COLS;
@ -39,8 +38,10 @@ public:
int getIndex(int row, int col);
// PLEASE MAKE SURE YOU KNOW THE LIMITS!
int getIndexNoCheck(int row, int col);
static void fadeOutMap(led_map* map, double factor);
void fadeOutMapColumn(led_map* map, double factor);
static void fadeOutMap(led_map& map, double factor);
static void setColor(led_map& map, rgba color);
static void setColorNoBrightness(led_map& map, rgba color);
void fadeOutMapColumn(led_map& map, double factor);
protected:
void setupMap();
// we need some mapping feature! rows and cols dont have the same amount of keys. so the struct needs

View file

@ -0,0 +1,20 @@
#pragma once
#include <VulcanoLE/Visual/VIZ.h>
#include <VulcanoLE/Audio/AudioGrabber.h>
#include <queue>
namespace VIZ {
struct BassHistory : public VIZ {
BassHistory(AudioGrabber *pGrabber, Vulcan121 *pVulcan121);
~BassHistory() override = default;
void onSetup() override;
void onTick(float delta) override;
const char *name() override;
std::string m_name = "Bass History";
led_map map{};
std::vector<double> m_history;
void pushNew(double val);
};
}

View file

@ -13,8 +13,11 @@ namespace VIZ {
void onTick(float delta) override;
void setForChannel(float value, int channel);
void drawFrame(int toRow);
void drawSetup(float val);
const char *name() override;
std::string m_name = "Loudness Meter";
bool isSetup = true;
double frameWidth = 0;
protected:
rgba colours[3] = {
{ 0, 0, 255, 80 },
@ -22,7 +25,7 @@ namespace VIZ {
{ 255, 0, 0, 40 }
};
double tailFactor = 0;
led_map *data = Vulcan121::createEmptyLEDMap();
led_map data{};
};
}

View file

@ -5,13 +5,13 @@
namespace VIZ {
class RainbowLine : public VIZ {
int currentColumn = 0;
double deltaNeeded = 100000.0;
double deltaNeeded = 0.0;
double deltaElapsed = 0;
rgba *colours = nullptr;
int maxCols = 0;
double lastValue = 0;
double decayValue = 0;
double tailFactor = 0.3;
double tailFactor = 0.5;
public:
RainbowLine(AudioGrabber *pGrabber, Vulcan121 *vulcan);
~RainbowLine() override;
@ -20,7 +20,7 @@ namespace VIZ {
void calcNextDelta(double ratio);
const char *name() override;
std::string m_name = "Rainbow Line";
led_map *data = Vulcan121::createEmptyLEDMap();
led_map data{};
bool firstUnder = true;
double deltaMove(double val);
void moveLine(double val, double d);

View file

@ -19,7 +19,7 @@ namespace VIZ {
void calcNextDelta(double ratio);
const char *name() override;
std::string m_name = "Rainbow Map";
led_map *data = Vulcan121::createEmptyLEDMap();
led_map data{};
bool firstUnder = true;
double deltaMove(double val);
void moveRainbow(double d);

View file

@ -4,23 +4,18 @@
#include <VulcanoLE/Keyboards/Vulcan121.h>
#include <VulcanoLE/Visual/VIZ.h>
#include <vector>
#include "VUtils/Random.h"
namespace VIZ {
class Random : public VIZ {
protected:
led_map *map = nullptr;
bool isReverse{ false };
bool emptyTicks{ false };
led_map map{};
VUtils::Random m_random;
double m_angle{0.0};
public:
Random(AudioGrabber *pGrabber, Vulcan121 *vulcan);
~Random() override;
void onSetup() override;
void onTick(float delta) override;
const char *name() override;
float deltaElapsed;
float deltaNeeded{ 80000 };
int row;
int columnCount{0}; // for last selected row all previous draw full
int ticks;
};
}

View file

@ -0,0 +1,18 @@
#pragma once
#include <VulcanoLE/Visual/VIZ.h>
#include <VulcanoLE/Audio/AudioGrabber.h>
#include <vector>
namespace VIZ {
struct Spectral : public VIZ {
Spectral(AudioGrabber *pGrabber, Vulcan121 *pVulcan121);
~Spectral() override = default;
void onSetup() override;
void onTick(float delta) override;
const char *name() override;
std::string m_name = "SpectralO";
led_map map{};
};
}

View file

@ -1,22 +1,20 @@
#pragma once
#include <VulcanoLE/Visual/VIZ.h>
#include <VulcanoLE/Audio/AudioGrabber.h>
#include <VulcanoLE/Visual/VIZ.h>
namespace VIZ {
struct Spectrum : public VIZ {
Spectrum(AudioGrabber *pGrabber, Vulcan121 *pVulcan121);
~Spectrum() override = default;
void onSetup() override;
void onTick(float delta) override;
double lastVal = 0;
const char *name() override;
std::string m_name = "Spectrum One";
rgba colors[3] = {
{ 0, 10, 180, 0 },
{ 0, 180, 0, 0 },
{ 150, 0, 0, 0 }
};
};
}
struct Spectrum : public VIZ {
public:
static constexpr int maxColors = 3;
Spectrum(AudioGrabber *pGrabber, Vulcan121 *pVulcan121);
~Spectrum() override = default;
void onSetup() override;
void onTick(float delta) override;
const char *name() override;
protected:
std::string m_name = "Spectrum One";
double m_angle = 0.0;
};
} // namespace VIZ

View file

@ -0,0 +1,21 @@
#pragma once
#include <VulcanoLE/Audio/AudioGrabber.h>
#include <VulcanoLE/Visual/VIZ.h>
namespace VIZ {
struct Strobo : public VIZ {
public:
Strobo(AudioGrabber *pGrabber, Vulcan121 *pVulcan121);
~Strobo() override = default;
void onSetup() override;
void onTick(float delta) override;
const char *name() override;
protected:
std::string m_name = "Strobo";
double m_sinPoint;
bool m_isStanding;
rgba m_color{};
};
} // namespace VIZ

View file

@ -0,0 +1,24 @@
#pragma once
#include <VulcanoLE/Audio/AudioGrabber.h>
#include <VulcanoLE/Keyboards/Vulcan121.h>
#include <VulcanoLE/Visual/VIZ.h>
#include <vector>
#include "VUtils/Random.h"
namespace VIZ {
class TheUnknown : public VIZ {
protected:
VUtils::Random m_random{};
led_map map{};
public:
TheUnknown(AudioGrabber *pGrabber, Vulcan121 *vulcan);
void onSetup() override;
void onTick(float delta) override;
const char *name() override;
double m_keyOffset[NUM_KEYS]{};
double m_keyHeightMap[NUM_KEYS]{};
double m_angle = 0.0001;
};
}

View file

@ -3,7 +3,7 @@
#include <vector>
#include <VulcanoLE/Scripts/Spectrum.h>
#define VIZSIZE 6
#define VIZSIZE 10
using micro = std::chrono::duration<double, std::micro>;
using ms = std::chrono::duration<double, std::milli>;