This commit is contained in:
Maurice Grönwoldt 2020-06-14 21:14:28 +02:00
commit a27c62f062
49 changed files with 1171 additions and 385 deletions

View file

@ -4,11 +4,11 @@
#include "VenoMatrix.h"
VenoMatrix::VenoMatrix (const std::string& processId) : m_processId (processId)
VenoMatrix::VenoMatrix (const std::string& processId) : m_processId(processId)
{
for (auto& m_slot : m_slots)
{
m_slot = new VenoMatrixSlot ();
m_slot = new VenoMatrixSlot();
}
}
@ -27,22 +27,22 @@ VenoMatrixSlot* VenoMatrix::getSlotById (int id)
void VenoMatrix::removeModulateValue (const std::string& name)
{
m_modulationValues.erase (name);
m_modulationValues.erase(name);
}
void VenoMatrix::removeModulator (const std::string& name)
{
m_modulators.erase (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));
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));
m_modulators.emplace(std::pair<const std::string&, Modulator*>(name, modulator));
}
void VenoMatrix::updateSlots ()
@ -53,26 +53,26 @@ void VenoMatrix::updateSlots ()
{
continue;
}
if (m_modulators.find (m_slot->sourceName) != m_modulators.end ())
if (m_modulators.find(m_slot->sourceName) != m_modulators.end())
{
auto modulator = m_modulators[m_slot->sourceName];
if (modulator == nullptr)
{
continue;
}
modulator->update ();
modulator->update();
for (auto& value : m_slot->targets)
{
if (value.name != "none")
{
if (m_modulationValues.find (value.name) != m_modulationValues.end ())
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);
modValue->addValue(modulator->getValue() * value.amount);
}
}
}

View file

@ -6,6 +6,6 @@
#include <utility>
SynthInstance::SynthInstance (std::string processId)
: m_processId (std::move (processId))
: m_processId(std::move(processId))
{
}

View file

@ -12,18 +12,18 @@ VenoBuffer::VenoBuffer ()
VenoBuffer::~VenoBuffer ()
{
buffer.clear ();
right.clear ();
left.clear ();
buffer.clear();
right.clear();
left.clear();
}
void VenoBuffer::reset (int size)
{
if (size != buffer.size ())
if (size != buffer.size())
{
buffer.resize (size);
right.resize (size);
left.resize (size);
buffer.resize(size);
right.resize(size);
left.resize(size);
}
// reset to 0 dc :D
for (int i = 0; i < size; ++i)
@ -54,11 +54,11 @@ void VenoBuffer::addRightSample (float value, int index)
void VenoBuffer::calcPeak ()
{
for (int i = 0; i < buffer.size (); ++i)
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]);
auto l = std::abs(left[i]);
auto r = std::abs(right[i]);
auto m = std::abs(buffer[i]);
if (m > monoPeak)
{
monoPeak = m;

View file

@ -12,7 +12,7 @@ void generateSaw (WaveTableGroup* group)
{
return;
}
int tableLen = findTableLen ();
int tableLen = findTableLen();
int idx;
auto* freqWaveRe = new double[tableLen];
auto* freqWaveIm = new double[tableLen];
@ -26,6 +26,6 @@ void generateSaw (WaveTableGroup* group)
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

@ -51,8 +51,8 @@ void fft (int N, double* ar, double* ai)
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
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)
@ -74,14 +74,14 @@ 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);
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]);
double temp = fabs(ai[idx]);
if (max < temp)
max = temp;
}
@ -94,7 +94,7 @@ float makeWaveTable (WaveTableGroup* group, int len, double* ar, double* ai, dou
wave[idx] = ai[idx] * scale;
if (group->m_numWaveTables < WaveTableGroup::numWaveTableSlots)
{
auto table = group->m_WaveTables[group->m_numWaveTables] = new WaveTableObject ();
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;
@ -121,7 +121,7 @@ int fillTables (WaveTableGroup* group, double* freqWaveRe, double* freqWaveIm, i
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];
@ -141,7 +141,7 @@ int fillTables (WaveTableGroup* group, double* freqWaveRe, double* freqWaveIm, i
}
// make the wavetable
scale = makeWaveTable (group, numSamples, ar, ai, scale, topFreq);
scale = makeWaveTable(group, numSamples, ar, ai, scale, topFreq);
numTables++;
// prepare for next table
@ -153,11 +153,11 @@ int fillTables (WaveTableGroup* group, double* freqWaveRe, double* freqWaveIm, i
float getNextRand ()
{
return std::rand () / double (RAND_MAX);
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 maxHarms = AudioConfig::getInstance()->getSampleRate() / (5.0 * 20) + 0.5;
return VeNo::Utils::nextPowerOfTwo(maxHarms) * 2;
}

View file

@ -9,25 +9,25 @@
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 ())
if (AudioConfig::getInstance()->isNeedToReInit())
{
cleanTables ();
AudioConfig::getInstance ()->setNeedToReInit (false);
cleanTables();
AudioConfig::getInstance()->setNeedToReInit(false);
}
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;
}
@ -35,7 +35,7 @@ WaveTableGroup* WaveTableGenerator::getGroup (int id)
{
if (!m_isInit)
{
init ();
init();
}
if (id < 40)
{