- reformat to JUCE-Guidelines
- added Matrix => half working ;)
This commit is contained in:
parent
26a2935e1c
commit
ac22ea5e75
58 changed files with 1220 additions and 799 deletions
|
|
@ -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");
|
||||
}
|
||||
|
|
@ -4,8 +4,5 @@
|
|||
|
||||
#ifndef VENO_SAWWAVES_H
|
||||
#define VENO_SAWWAVES_H
|
||||
|
||||
void generateSaw(WaveTableGroup *group);
|
||||
|
||||
|
||||
void generateSaw (WaveTableGroup* group);
|
||||
#endif //VENO_SAWWAVES_H
|
||||
|
|
|
|||
|
|
@ -4,11 +4,8 @@
|
|||
|
||||
#ifndef VENO_SINEWAVES_H
|
||||
#define VENO_SINEWAVES_H
|
||||
|
||||
|
||||
class SineWaves {
|
||||
class SineWaves
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //VENO_SINEWAVES_H
|
||||
|
|
|
|||
|
|
@ -4,11 +4,8 @@
|
|||
|
||||
#ifndef VENO_SQUAREWAVES_H
|
||||
#define VENO_SQUAREWAVES_H
|
||||
|
||||
|
||||
class SquareWaves {
|
||||
class SquareWaves
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //VENO_SQUAREWAVES_H
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -4,11 +4,8 @@
|
|||
|
||||
#ifndef VENO_TRIANGLEWAVES_H
|
||||
#define VENO_TRIANGLEWAVES_H
|
||||
|
||||
|
||||
class TriangleWaves {
|
||||
class TriangleWaves
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //VENO_TRIANGLEWAVES_H
|
||||
|
|
|
|||
|
|
@ -4,11 +4,8 @@
|
|||
|
||||
#ifndef VENO_VENOXWAVES_H
|
||||
#define VENO_VENOXWAVES_H
|
||||
|
||||
|
||||
class VeNoXWaves {
|
||||
class VeNoXWaves
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //VENO_VENOXWAVES_H
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue