reVeno/Source/Veno/Audio/WaveTable/WaveTableGenerator.cpp

55 lines
1.4 KiB
C++
Raw Normal View History

2020-06-13 10:56:20 +02:00
//
// Created by versustune on 08.06.20.
//
#include "WaveTableGenerator.h"
#include "../../Core/AudioConfig.h"
#include "WavesInlcuder.h"
void WaveTableGenerator::init ()
{
2020-06-13 10:56:20 +02:00
//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);
2020-06-13 10:56:20 +02:00
}
if (m_isInit)
{
2020-06-13 10:56:20 +02:00
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]);
2020-06-13 10:56:20 +02:00
m_isInit = true;
}
WaveTableGroup* WaveTableGenerator::getGroup (int id)
{
if (!m_isInit)
{
init ();
2020-06-13 10:56:20 +02:00
}
if (id < 40)
{
2020-06-13 10:56:20 +02:00
return m_waveTables[id];
}
return nullptr;
}
void WaveTableGenerator::cleanTables ()
{
for (auto& m_waveTable : m_waveTables)
{
2020-06-13 10:56:20 +02:00
delete m_waveTable;
}
m_isInit = false;
}