This commit is contained in:
Maurice Grönwoldt 2021-05-02 17:25:03 +02:00
commit 4152ee0413
33 changed files with 27356 additions and 233 deletions

View file

@ -1,6 +1,7 @@
#pragma once
#include <string>
#include <vector>
namespace VUtils {
class FileHandler {
@ -17,6 +18,7 @@ namespace VUtils {
static bool createDirectoryIfNotExist(const std::basic_string<char>& fileName);
static char * getHomeDirectory();
static std::string getFromHomeDir(const std::basic_string<char>& path);
static std::vector<std::string> readDir(const std::basic_string<char>& path);
};
}

View file

@ -6,5 +6,6 @@ namespace VUtils {
static double lerp(double a, double b, double f);
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);
};
}

View file

@ -0,0 +1,12 @@
#pragma once
#include <string>
struct I2CDevice {
std::string name;
};
class I2C {
public:
int readDevices();
};

View file

@ -1,8 +1,4 @@
#pragma once
#include <pulse/error.h>
#include <pulse/pulseaudio.h>
#include <pulse/simple.h>
#include <unistd.h>
#include <string>
#include <fstream>
@ -12,14 +8,6 @@
#include <VulcanoLE/Audio/FFT.h>
#include <VulcanoLE/Audio/Types.h>
static const char recStreamName[] = "vulcanoLE";
static const char recStreamDescription[] = "Keyboard Input Stream";
static const int32_t sampleRate = 44100;
static const int32_t channels = 2;
static const std::string defaultMonitorPostfix = ".monitor";
class AudioGrabber {
public:
enum class ReqMode {
@ -42,17 +30,8 @@ public:
private:
std::mutex m_mtx;
stereoSample *m_buffer{};
pa_simple *m_pulseaudioSimple{};
pa_mainloop *m_pulseaudioMainloop{};
std::string m_PulseaudioDefaultSourceName;
void populateDefaultSourceName();
bool openPulseaudioSource(uint32_t maxBufferSize);
static void pulseaudioContextStateCallback(pa_context *c,
void *userdata);
static void pulseaudioServerInfoCallback(pa_context *context,
const pa_server_info *i,
void *userdata);
void calculateRMS(stereoSample *pFrame);
void calculatePEAK(stereoSample *pFrame);
double m_scale = 1.0;
int availableData = 0;
};

View file

@ -11,14 +11,18 @@ public:
void process(stereoSample *frame, double d);
outputSample *getData();
bool prepareInput(stereoSample *buffer, uint32_t sampleSize, double scale);
double hannWindow[BUFFER_SIZE]{};
protected:
double *m_fftwInputLeft{};
double *m_fftwInputRight{};
fftw_complex *m_fftwInputLeft{};
fftw_complex *m_fftwInputRight{};
fftw_complex *m_fftwOutputLeft{};
fftw_complex *m_fftwOutputRight{};
outputSample *m_sample = new outputSample(FFT_SIZE);
outputSample *m_sample = new outputSample(BUFFER_SIZE);
fftw_plan m_fftwPlanLeft{};
fftw_plan m_fftwPlanRight{};
std::mutex m_mtx;
size_t m_fftwResults;
static double valueToAmp(double value);
double times;
static double limit;
};

View file

@ -0,0 +1,46 @@
#pragma once
#include <VUtils/Environment.h>
#include <jack/jack.h>
#include <string>
#include <mutex>
#include <VUtils/Logging.h>
#include "Types.h"
#include "AudioGrabber.h"
class JackClient {
public:
static JackClient &get() {
static JackClient client;
return client;
}
void start();
static int processSamples(jack_nframes_t frames, void *arg);
static void onExit();
void connect(const char *port_name, jack_port_t* channel);
void fillSamples(stereoSample *pFrame, uint32_t i) {
std::lock_guard<std::mutex> lockGuard(guard);
for (int j = 0; j < i; ++j) {
pFrame[j].l = samples[j].l;
pFrame[j].r = samples[j].r;
}
m_newDataAvailable = false;
}
bool isData();
std::string getPort(bool isLeft);
bool checkPort(const std::string& port);
VUtils::Environment* env{};
int getFrames();
AudioGrabber *grabber;
private:
std::mutex guard;
stereoSample samples[BUFFER_SIZE]{};
stereoSample ringBuffer[BUFFER_SIZE]{};
int samplesAdded = 0;
jack_port_t *input_port_l = nullptr;
jack_port_t *input_port_r = nullptr;
bool m_newDataAvailable = false;
jack_client_t *client = nullptr;
jack_options_t options = jack_options_t(JackNoStartServer | JackUseExactName);
void addFrames(jack_default_audio_sample_t *pDouble, jack_default_audio_sample_t *pDouble1, jack_nframes_t i);
};

View file

@ -1,6 +1,6 @@
#pragma once
#define FFT_SIZE 1024
#define BUFFER_SIZE 2048
#define FFT_SIZE 512
#define BUFFER_SIZE 1024
struct stereoSampleFrame {
float l;

View file

@ -4,6 +4,7 @@
#include <VulcanoLE/Audio/AudioGrabber.h>
#include <VulcanoLE/Visual/VisPlugins.h>
#include <VUtils/Environment.h>
#include <VulcanoLE/API/I2C.h>
class VisAudioRunner {
public:
@ -16,5 +17,6 @@ public:
VIZ::VisPlugins* plugins;
bool isActive = true;
std::thread thread;
I2C i2c;
VUtils::Environment *env = nullptr;
};

View file

@ -40,6 +40,7 @@ public:
// 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);
protected:
void setupMap();
// we need some mapping feature! rows and cols dont have the same amount of keys. so the struct needs

View file

@ -5,9 +5,9 @@
namespace VIZ {
class PoliceLike : public VIZ {
protected:
int decayRate = 10;
int decayRate = 5;
double lastPeak = -1;
double threshold = 15;
double threshold = 45;
public:
PoliceLike(AudioGrabber *pGrabber, Vulcan121 *pVulcan121);
~PoliceLike() override = default;

View file

@ -8,9 +8,9 @@ namespace VIZ {
double deltaNeeded = 100000.0;
double deltaElapsed = 0;
rgba *colours = nullptr;
int maxCols = 0;
double lastValue = 0;
double decayValue = 0;
double ratios[4] = {1.3,1.3,1.3,1.2};
double tailFactor = 0.3;
public:
RainbowLine(AudioGrabber *pGrabber, Vulcan121 *vulcan);
@ -23,5 +23,7 @@ namespace VIZ {
led_map *data = Vulcan121::createEmptyLEDMap();
bool firstUnder = true;
double deltaMove(double val);
void moveLine(double val, double d);
double factor = 1.0;
};
}

View file

@ -0,0 +1,28 @@
#pragma once
#include <VulcanoLE/Visual/VIZ.h>
namespace VIZ {
class RainbowMap : public VIZ {
int currentColumn = 0;
double deltaNeeded = 100000.0;
double deltaElapsed = 0;
rgba *colours = nullptr;
int maxCols = 0;
double lastValue = 0;
double decayValue = 0;
public:
RainbowMap(AudioGrabber *pGrabber, Vulcan121 *vulcan);
~RainbowMap() override;
void onSetup() override;
void onTick(float delta) override;
void calcNextDelta(double ratio);
const char *name() override;
std::string m_name = "Rainbow Map";
led_map *data = Vulcan121::createEmptyLEDMap();
bool firstUnder = true;
double deltaMove(double val);
void moveRainbow(double d);
void updateColumn(int column, int colIndex);
};
}

View file

@ -0,0 +1,26 @@
#pragma once
#include <VulcanoLE/Audio/AudioGrabber.h>
#include <VulcanoLE/Keyboards/Vulcan121.h>
#include <VulcanoLE/Visual/VIZ.h>
#include <vector>
namespace VIZ {
class Random : public VIZ {
protected:
led_map *map = nullptr;
bool isReverse{ false };
bool emptyTicks{ false };
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

@ -13,9 +13,9 @@ namespace VIZ {
const char *name() override;
std::string m_name = "Spectrum One";
rgba colors[3] = {
{ 0, 30, 150, 0 },
{ 150, 150, 0, 0 },
{ 150, 0, 40, 0 }
{ 0, 10, 180, 0 },
{ 0, 180, 0, 0 },
{ 150, 0, 0, 0 }
};
};
}

View file

@ -3,9 +3,10 @@
#include <vector>
#include <VulcanoLE/Scripts/Spectrum.h>
#define VIZSIZE 4
#define VIZSIZE 6
using micro = std::chrono::duration<double, std::micro>;
using ms = std::chrono::duration<double, std::milli>;
namespace VIZ {
struct VisPlugins {
@ -18,11 +19,14 @@ namespace VIZ {
~VisPlugins();
VUtils::Environment *env{};
protected:
std::mutex guard;
VIZ *viz[VIZSIZE]{};
VIZ *currentVis{};
Vulcan121 *keyboard{};
AudioGrabber *grabber{};
std::chrono::time_point<std::chrono::system_clock, micro> start;
std::chrono::time_point<std::chrono::system_clock, ms> frameStart;
long frames = 0;
};
}

26674
headers/sol/sol.hpp Normal file

File diff suppressed because it is too large Load diff