- reformat to JUCE-Guidelines

- added Matrix => half working ;)
This commit is contained in:
Maurice Grönwoldt 2020-06-13 16:52:16 +02:00
commit ac22ea5e75
58 changed files with 1220 additions and 799 deletions

View file

@ -0,0 +1,21 @@
//
// Created by versustune on 13.06.20.
//
#include "ModulateValue.h"
ModulateValue::ModulateValue (const std::string& name, const std::string& processId)
{
m_name = name;
m_processId = processId;
}
void ModulateValue::addValue (float d)
{
}
ModulateValue::~ModulateValue ()
{
}

View file

@ -0,0 +1,25 @@
//
// Created by versustune on 13.06.20.
//
#ifndef VENO_MODULATEVALUE_H
#define VENO_MODULATEVALUE_H
#include <string>
// a class that is used to can handle the value from a "gui-part" and the matrix and all other modulation
class ModulateValue
{
public:
ModulateValue (const std::string& name, const std::string& processId);
~ModulateValue ();
void addValue (float d);
private:
std::string m_name;
std::string m_processId;
float m_value;
float m_baseValue = 0;
float m_maxValue = 1;
float m_minValue = -1;
};
#endif //VENO_MODULATEVALUE_H

View file

@ -0,0 +1,24 @@
//
// Created by versustune on 13.06.20.
//
#include "Modulator.h"
float Modulator::getValue ()
{
return m_value;
}
Modulator::Modulator ()
{
}
Modulator::~Modulator ()
{
}
void Modulator::update ()
{
}

View file

@ -0,0 +1,19 @@
//
// Created by versustune on 13.06.20.
//
#ifndef VENO_MODULATOR_H
#define VENO_MODULATOR_H
// class that define if it can be a modulator on not
// like LFO, Envelope, maybe also OSCILLATORS :P VELOCITY AND OTHER STUFF IS ALSO A MODULATOR!
class Modulator
{
public:
Modulator ();
~Modulator ();
float getValue ();
void update ();
protected:
float m_value;
};
#endif //VENO_MODULATOR_H

View file

@ -0,0 +1,81 @@
//
// Created by versustune on 13.06.20.
//
#include "VenoMatrix.h"
VenoMatrix::VenoMatrix (const std::string& processId) : m_processId (processId)
{
for (auto& m_slot : m_slots)
{
m_slot = new VenoMatrixSlot ();
}
}
VenoMatrix::~VenoMatrix ()
{
for (auto& m_slot : m_slots)
{
delete m_slot;
}
}
VenoMatrixSlot* VenoMatrix::getSlotById (int id)
{
return m_slots[id];
}
void VenoMatrix::removeModulateValue (const std::string& name)
{
m_modulationValues.erase (name);
}
void VenoMatrix::removeModulator (const std::string& name)
{
m_modulators.erase (name);
}
void VenoMatrix::addModulateValue (const std::string& name, ModulateValue* modulateValue)
{
m_modulationValues.emplace (std::pair<const std::string&, ModulateValue*> (name, modulateValue));
}
void VenoMatrix::addModulator (const std::string& name, Modulator* modulator)
{
m_modulators.emplace (std::pair<const std::string&, Modulator*> (name, modulator));
}
void VenoMatrix::updateSlots ()
{
for (auto& m_slot : m_slots)
{
if (m_slot->sourceName == "none")
{
continue;
}
if (m_modulators.find (m_slot->sourceName) != m_modulators.end ())
{
auto modulator = m_modulators[m_slot->sourceName];
if (modulator == nullptr)
{
continue;
}
modulator->update ();
for (auto& value : m_slot->targets)
{
if (value.name != "none")
{
if (m_modulationValues.find (value.name) != m_modulationValues.end ())
{
auto modValue = m_modulationValues[value.name];
if (modValue == nullptr)
{
continue;
}
modValue->addValue (modulator->getValue () * value.amount);
}
}
}
}
}
}

View file

@ -0,0 +1,42 @@
//
// Created by versustune on 13.06.20.
//
#ifndef VENO_VENOMATRIX_H
#define VENO_VENOMATRIX_H
#include <string>
#include <unordered_map>
#include <vector>
#include "Modulator.h"
#include "ModulateValue.h"
// class that modulate everything :D
struct VenoMatrixTarget
{
std::string name;
float amount = 0; // always 0 to 1 <-- apply amount to modulator
};
struct VenoMatrixSlot
{
std::string sourceName;
VenoMatrixTarget targets[8];
};
class VenoMatrix
{
public:
explicit VenoMatrix (const std::string& processId);
~VenoMatrix ();
void updateSlots ();
void addModulator (const std::string& name, Modulator* modulator);
void addModulateValue (const std::string& name, ModulateValue* modulateValue);
void removeModulator (const std::string& name);
void removeModulateValue (const std::string& name);
VenoMatrixSlot* getSlotById (int id);
private:
std::unordered_map<std::string, Modulator*> m_modulators; //all sources
std::unordered_map<std::string, ModulateValue*> m_modulationValues;
VenoMatrixSlot* m_slots[8]{}; // 8 source slots
std::string m_processId;
};
#endif //VENO_VENOMATRIX_H

View file

@ -3,9 +3,9 @@
//
#include "SynthInstance.h"
#include <utility>
SynthInstance::SynthInstance(std::string processId)
: m_processId(std::move(processId)) {
SynthInstance::SynthInstance (std::string processId)
: m_processId (std::move (processId))
{
}

View file

@ -5,18 +5,16 @@
#ifndef VENO_SYNTHINSTANCE_H
#define VENO_SYNTHINSTANCE_H
#include <string>
// class that hold all voices, oscillators and other stuff :)
class SynthInstance {
class SynthInstance
{
private:
std::string m_processId;
public:
explicit SynthInstance(std::string processId);
~SynthInstance() = default;
explicit SynthInstance (std::string processId);
~SynthInstance () = default;
protected:
};
#endif //VENO_SYNTHINSTANCE_H

View file

@ -5,24 +5,29 @@
#include <cmath>
#include "VenoBuffer.h"
VenoBuffer::VenoBuffer() {
VenoBuffer::VenoBuffer ()
{
}
VenoBuffer::~VenoBuffer() {
buffer.clear();
right.clear();
left.clear();
VenoBuffer::~VenoBuffer ()
{
buffer.clear ();
right.clear ();
left.clear ();
}
void VenoBuffer::reset(int size) {
if (size != buffer.size()) {
buffer.resize(size);
right.resize(size);
left.resize(size);
void VenoBuffer::reset (int size)
{
if (size != buffer.size ())
{
buffer.resize (size);
right.resize (size);
left.resize (size);
}
// reset to 0 dc :D
for (int i = 0; i < size; ++i) {
for (int i = 0; i < size; ++i)
{
buffer[i] = 0;
left[i] = 0;
right[i] = 0;
@ -32,43 +37,54 @@ void VenoBuffer::reset(int size) {
monoPeak = 0;
}
void VenoBuffer::addMonoSample(float value, int index) {
void VenoBuffer::addMonoSample (float value, int index)
{
buffer[index] = value;
}
void VenoBuffer::addLeftSample(float value, int index) {
void VenoBuffer::addLeftSample (float value, int index)
{
left[index] = value;
}
void VenoBuffer::addRightSample(float value, int index) {
void VenoBuffer::addRightSample (float value, int index)
{
right[index] = value;
}
void VenoBuffer::calcPeak() {
for (int i = 0; i < buffer.size(); ++i) {
auto l = std::abs(left[i]);
auto r = std::abs(right[i]);
auto m = std::abs(buffer[i]);
if (m > monoPeak) {
void VenoBuffer::calcPeak ()
{
for (int i = 0; i < buffer.size (); ++i)
{
auto l = std::abs (left[i]);
auto r = std::abs (right[i]);
auto m = std::abs (buffer[i]);
if (m > monoPeak)
{
monoPeak = m;
}
if (l > leftPeak) {
if (l > leftPeak)
{
leftPeak = l;
}
if (r > rightPeak) {
if (r > rightPeak)
{
rightPeak = r;
}
}
}
const std::vector<float> &VenoBuffer::getBuffer() const {
const std::vector<float>& VenoBuffer::getBuffer () const
{
return buffer;
}
const std::vector<float> &VenoBuffer::getRight() const {
const std::vector<float>& VenoBuffer::getRight () const
{
return right;
}
const std::vector<float> &VenoBuffer::getLeft() const {
const std::vector<float>& VenoBuffer::getLeft () const
{
return left;
}

View file

@ -5,33 +5,27 @@
#ifndef VENO_VENOBUFFER_H
#define VENO_VENOBUFFER_H
#include <vector>
class VenoBuffer {
class VenoBuffer
{
private:
std::vector<float> buffer;
std::vector<float> right;
std::vector<float> left;
public:
VenoBuffer();
~VenoBuffer();
void reset(int size);
void addMonoSample(float value, int index);
void addLeftSample(float value, int index);
void addRightSample(float value, int index);
void calcPeak();
VenoBuffer ();
~VenoBuffer ();
void reset (int size);
void addMonoSample (float value, int index);
void addLeftSample (float value, int index);
void addRightSample (float value, int index);
void calcPeak ();
float leftPeak;
float rightPeak;
float monoPeak;
const std::vector<float> &getBuffer() const;
const std::vector<float> &getRight() const;
const std::vector<float> &getLeft() const;
const std::vector<float>& getBuffer () const;
const std::vector<float>& getRight () const;
const std::vector<float>& getLeft () const;
};
#endif //VENO_VENOBUFFER_H

View file

@ -6,23 +6,26 @@
#include "../../Utils/Logger.h"
#include "TableHelper.h"
void generateSaw(WaveTableGroup *group) {
if (group == nullptr) {
void generateSaw (WaveTableGroup* group)
{
if (group == nullptr)
{
return;
}
int tableLen = findTableLen();
int tableLen = findTableLen ();
int idx;
auto *freqWaveRe = new double[tableLen];
auto *freqWaveIm = new double[tableLen];
for (idx = 0; idx < tableLen; idx++) {
auto* freqWaveRe = new double[tableLen];
auto* freqWaveIm = new double[tableLen];
for (idx = 0; idx < tableLen; idx++)
{
freqWaveIm[idx] = 0.0;
}
freqWaveRe[0] = freqWaveRe[tableLen >> 1] = 0.0;
for (idx = 1; idx < (tableLen >> 1); idx++) {
for (idx = 1; idx < (tableLen >> 1); idx++)
{
freqWaveRe[idx] = 1.0 / idx; // sawtooth spectrum
freqWaveRe[tableLen - idx] = -freqWaveRe[idx]; // mirror
}
fillTables(group, freqWaveRe, freqWaveIm, tableLen);
VeNo::Logger::infoDebugMessage("Generated clean Saw Wave");
fillTables (group, freqWaveRe, freqWaveIm, tableLen);
VeNo::Logger::infoDebugMessage ("Generated clean Saw Wave");
}

View file

@ -4,8 +4,5 @@
#ifndef VENO_SAWWAVES_H
#define VENO_SAWWAVES_H
void generateSaw(WaveTableGroup *group);
void generateSaw (WaveTableGroup* group);
#endif //VENO_SAWWAVES_H

View file

@ -4,11 +4,8 @@
#ifndef VENO_SINEWAVES_H
#define VENO_SINEWAVES_H
class SineWaves {
class SineWaves
{
};
#endif //VENO_SINEWAVES_H

View file

@ -4,11 +4,8 @@
#ifndef VENO_SQUAREWAVES_H
#define VENO_SQUAREWAVES_H
class SquareWaves {
class SquareWaves
{
};
#endif //VENO_SQUAREWAVES_H

View file

@ -6,7 +6,8 @@
#include "../../Core/AudioConfig.h"
#include "../../Utils.h"
void fft(int N, double *ar, double *ai) {
void fft (int N, double* ar, double* ai)
{
int i, j, k, L; /* indexes */
int M, TEMP, LE, LE1, ip; /* M = log N */
int NV2, NM1;
@ -24,8 +25,10 @@ void fft(int N, double *ar, double *ai) {
/* shuffle */
j = 1;
for (i = 1; i <= NM1; i++) {
if (i < j) { /* swap a[i] and a[j] */
for (i = 1; i <= NM1; i++)
{
if (i < j)
{ /* swap a[i] and a[j] */
t = ar[j - 1];
ar[j - 1] = ar[i - 1];
ar[i - 1] = t;
@ -33,26 +36,27 @@ void fft(int N, double *ar, double *ai) {
ai[j - 1] = ai[i - 1];
ai[i - 1] = t;
}
k = NV2; /* bit-reversed counter */
while (k < j) {
while (k < j)
{
j -= k;
k /= 2;
}
j += k;
}
LE = 1.;
for (L = 1; L <= M; L++) { // stage L
for (L = 1; L <= M; L++)
{ // stage L
LE1 = LE; // (LE1 = LE/2)
LE *= 2; // (LE = 2^L)
Ur = 1.0;
Ui = 0.;
Wr = std::cos(M_PI / (float) LE1);
Wi = -std::sin(M_PI / (float) LE1); // Cooley, Lewis, and Welch have "+" here
for (j = 1; j <= LE1; j++) {
for (i = j; i <= N; i += LE) { // butterfly
Wr = std::cos (M_PI / (float) LE1);
Wi = -std::sin (M_PI / (float) LE1); // Cooley, Lewis, and Welch have "+" here
for (j = 1; j <= LE1; j++)
{
for (i = j; i <= N; i += LE)
{ // butterfly
ip = i + LE1;
Tr = ar[ip - 1] * Ur - ai[ip - 1] * Ui;
Ti = ar[ip - 1] * Ui + ai[ip - 1] * Ur;
@ -68,14 +72,16 @@ void fft(int N, double *ar, double *ai) {
}
}
float makeWaveTable(WaveTableGroup *group, int len, double *ar, double *ai, double scale, double topFreq) {
fft(len, ar, ai);
if (scale == 0.0) {
float makeWaveTable (WaveTableGroup* group, int len, double* ar, double* ai, double scale, double topFreq)
{
fft (len, ar, ai);
if (scale == 0.0)
{
// calc normal
double max = 0;
for (int idx = 0; idx < len; idx++) {
double temp = fabs(ai[idx]);
for (int idx = 0; idx < len; idx++)
{
double temp = fabs (ai[idx]);
if (max < temp)
max = temp;
}
@ -83,13 +89,13 @@ float makeWaveTable(WaveTableGroup *group, int len, double *ar, double *ai, doub
}
// normalize
auto *wave = new float[len];
auto* wave = new float[len];
for (int idx = 0; idx < len; idx++)
wave[idx] = ai[idx] * scale;
if (group->m_numWaveTables < WaveTableGroup::numWaveTableSlots) {
auto table = group->m_WaveTables[group->m_numWaveTables] = new WaveTableObject();
float *waveTable = group->m_WaveTables[group->m_numWaveTables]->m_waveTable = new float[len + 1];
if (group->m_numWaveTables < WaveTableGroup::numWaveTableSlots)
{
auto table = group->m_WaveTables[group->m_numWaveTables] = new WaveTableObject ();
float* waveTable = group->m_WaveTables[group->m_numWaveTables]->m_waveTable = new float[len + 1];
table->m_waveTableLen = len;
table->m_topFreq = topFreq;
++group->m_numWaveTables;
@ -100,33 +106,34 @@ float makeWaveTable(WaveTableGroup *group, int len, double *ar, double *ai, doub
waveTable[len] = waveTable[0]; // duplicate for interpolation wraparound
return 0;
} else {
}
else
{
scale = 0.0;
}
return (float) scale;
}
int fillTables(WaveTableGroup *group, double *freqWaveRe, double *freqWaveIm, int numSamples) {
int fillTables (WaveTableGroup* group, double* freqWaveRe, double* freqWaveIm, int numSamples)
{
int idx;
freqWaveRe[0] = freqWaveIm[0] = 0.0;
freqWaveRe[numSamples >> 1] = freqWaveIm[numSamples >> 1] = 0.0;
int maxHarmonic = numSamples >> 1;
const double minVal = 0.000001; // -120 dB
while ((fabs(freqWaveRe[maxHarmonic]) + fabs(freqWaveIm[maxHarmonic]) < minVal) && maxHarmonic) --maxHarmonic;
while ((fabs (freqWaveRe[maxHarmonic]) + fabs (freqWaveIm[maxHarmonic]) < minVal) && maxHarmonic) --maxHarmonic;
double topFreq = 2.0 / 3.0 / maxHarmonic;
double *ar = new double[numSamples];
double *ai = new double[numSamples];
double* ar = new double[numSamples];
double* ai = new double[numSamples];
double scale = 0.0;
int numTables = 0;
while (maxHarmonic) {
while (maxHarmonic)
{
// fill the table in with the needed harmonics
for (idx = 0; idx < numSamples; idx++)
ar[idx] = ai[idx] = 0.0;
for (idx = 1; idx <= maxHarmonic; idx++) {
for (idx = 1; idx <= maxHarmonic; idx++)
{
ar[idx] = freqWaveRe[idx];
ai[idx] = freqWaveIm[idx];
ar[numSamples - idx] = freqWaveRe[numSamples - idx];
@ -134,7 +141,7 @@ int fillTables(WaveTableGroup *group, double *freqWaveRe, double *freqWaveIm, in
}
// make the wavetable
scale = makeWaveTable(group, numSamples, ar, ai, scale, topFreq);
scale = makeWaveTable (group, numSamples, ar, ai, scale, topFreq);
numTables++;
// prepare for next table
@ -144,11 +151,13 @@ int fillTables(WaveTableGroup *group, double *freqWaveRe, double *freqWaveIm, in
return numTables;
}
float getNextRand() {
return std::rand() / double(RAND_MAX);
float getNextRand ()
{
return std::rand () / double (RAND_MAX);
}
int findTableLen() {
int maxHarms = AudioConfig::getInstance()->getSampleRate() / (5.0 * 20) + 0.5;
return VeNo::Utils::nextPowerOfTwo(maxHarms) * 2;
int findTableLen ()
{
int maxHarms = AudioConfig::getInstance ()->getSampleRate () / (5.0 * 20) + 0.5;
return VeNo::Utils::nextPowerOfTwo (maxHarms) * 2;
}

View file

@ -11,7 +11,6 @@
#define M_PI 3.14159265358979323846
#define DOUBLE_PI 6.283185307179586476925286766559
/*
in-place complex fft
After Cooley, Lewis, and Welch; from Rabiner & Gold (1975)
@ -20,15 +19,10 @@
Computer Science Dept.
Princeton University 08544
*/
void fft(int N, double *ar, double *ai);
float makeWaveTable(WaveTableGroup *group, int len, double *ar, double *ai, double scale, double topFreq);
void fft (int N, double* ar, double* ai);
float makeWaveTable (WaveTableGroup* group, int len, double* ar, double* ai, double scale, double topFreq);
// utils stuff
int fillTables(WaveTableGroup *group, double *freqWaveRe, double *freqWaveIm, int numSamples);
int findTableLen();
float getNextRand();
int fillTables (WaveTableGroup* group, double* freqWaveRe, double* freqWaveIm, int numSamples);
int findTableLen ();
float getNextRand ();
#endif //VENO_TABLEHELPER_H

View file

@ -4,11 +4,8 @@
#ifndef VENO_TRIANGLEWAVES_H
#define VENO_TRIANGLEWAVES_H
class TriangleWaves {
class TriangleWaves
{
};
#endif //VENO_TRIANGLEWAVES_H

View file

@ -4,11 +4,8 @@
#ifndef VENO_VENOXWAVES_H
#define VENO_VENOXWAVES_H
class VeNoXWaves {
class VeNoXWaves
{
};
#endif //VENO_VENOXWAVES_H

View file

@ -6,41 +6,48 @@
#include "../../Core/AudioConfig.h"
#include "WavesInlcuder.h"
void WaveTableGenerator::init() {
void WaveTableGenerator::init ()
{
//if the sampleRate changed... the WaveTables are not harmonic Save anymore and are needed to rebuild... pls stay save later!
if (AudioConfig::getInstance()->isNeedToReInit()) {
cleanTables();
AudioConfig::getInstance()->setNeedToReInit(false);
if (AudioConfig::getInstance ()->isNeedToReInit ())
{
cleanTables ();
AudioConfig::getInstance ()->setNeedToReInit (false);
}
if (m_isInit) {
if (m_isInit)
{
return;
}
m_waveTables[WaveForms::SAW] = new WaveTableGroup();
m_waveTables[WaveForms::SINE] = new WaveTableGroup();
m_waveTables[WaveForms::SQUARE] = new WaveTableGroup();
m_waveTables[WaveForms::TRIANGLE] = new WaveTableGroup();
m_waveTables[WaveForms::wSaw] = new WaveTableGroup();
m_waveTables[WaveForms::wSQUARE] = new WaveTableGroup();
m_waveTables[WaveForms::SYNTHONE] = new WaveTableGroup();
m_waveTables[WaveForms::SYNTHTWO] = new WaveTableGroup();
m_waveTables[WaveForms::VENOX] = new WaveTableGroup();
generateSaw(m_waveTables[WaveForms::SAW]);
m_waveTables[WaveForms::SAW] = new WaveTableGroup ();
m_waveTables[WaveForms::SINE] = new WaveTableGroup ();
m_waveTables[WaveForms::SQUARE] = new WaveTableGroup ();
m_waveTables[WaveForms::TRIANGLE] = new WaveTableGroup ();
m_waveTables[WaveForms::wSaw] = new WaveTableGroup ();
m_waveTables[WaveForms::wSQUARE] = new WaveTableGroup ();
m_waveTables[WaveForms::SYNTHONE] = new WaveTableGroup ();
m_waveTables[WaveForms::SYNTHTWO] = new WaveTableGroup ();
m_waveTables[WaveForms::VENOX] = new WaveTableGroup ();
generateSaw (m_waveTables[WaveForms::SAW]);
m_isInit = true;
}
WaveTableGroup *WaveTableGenerator::getGroup(int id) {
if (!m_isInit) {
init();
WaveTableGroup* WaveTableGenerator::getGroup (int id)
{
if (!m_isInit)
{
init ();
}
if (id < 40) {
if (id < 40)
{
return m_waveTables[id];
}
return nullptr;
}
void WaveTableGenerator::cleanTables() {
for (auto & m_waveTable : m_waveTables) {
void WaveTableGenerator::cleanTables ()
{
for (auto& m_waveTable : m_waveTables)
{
delete m_waveTable;
}
m_isInit = false;

View file

@ -4,20 +4,20 @@
#ifndef VENO_WAVETABLEGENERATOR_H
#define VENO_WAVETABLEGENERATOR_H
struct WaveTableObject {
struct WaveTableObject
{
double m_topFreq;
int m_waveTableLen;
float *m_waveTable;
float* m_waveTable;
};
struct WaveTableGroup {
struct WaveTableGroup
{
static constexpr int numWaveTableSlots = 40;
WaveTableObject *m_WaveTables[numWaveTableSlots] = {};
WaveTableObject* m_WaveTables[numWaveTableSlots] = {};
int m_numWaveTables = 0;
};
enum WaveForms {
enum WaveForms
{
SAW = 0,
SINE,
SQUARE,
@ -28,26 +28,24 @@ enum WaveForms {
SYNTHTWO,
VENOX
};
class WaveTableGenerator {
class WaveTableGenerator
{
private:
static constexpr int numWaveTableSlots = 40;
WaveTableGroup *m_waveTables[numWaveTableSlots] = {};
WaveTableGroup* m_waveTables[numWaveTableSlots] = {};
public:
static WaveTableGenerator &getInstance() {
static WaveTableGenerator& getInstance ()
{
static WaveTableGenerator instance;
return instance;
}
WaveTableGroup *getGroup(int id);
void init();
void cleanTables();
WaveTableGroup* getGroup (int id);
void init ();
void cleanTables ();
protected:
bool m_isInit = false;
WaveTableGenerator() = default;
~WaveTableGenerator() = default;
WaveTableGenerator () = default;
~WaveTableGenerator () = default;
};
#endif //VENO_WAVETABLEGENERATOR_H