- 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 1222 additions and 801 deletions

View file

@ -4,30 +4,35 @@
#include "Veno/Utils/Logger.h"
#include "Veno/Fonts/Fonts.h"
VenoAudioProcessorEditor::VenoAudioProcessorEditor(VenoAudioProcessor &p)
: AudioProcessorEditor(&p), processor(p) {
VenoAudioProcessorEditor::VenoAudioProcessorEditor (VenoAudioProcessor& p)
: AudioProcessorEditor (&p), processor (p)
{
m_id = p.m_id;
Config::getInstance()->registerEditor(this, m_id);
LookAndFeel::setDefaultLookAndFeel(m_look);
waveform = std::make_unique<SidebarLCD>(m_id);
setSize(600, 400);
addAndMakeVisible(*waveform);
Config::getInstance ()->registerEditor (this, m_id);
LookAndFeel::setDefaultLookAndFeel (m_look);
waveform = std::make_unique<SidebarLCD> (m_id);
setSize (600, 400);
addAndMakeVisible (*waveform);
}
VenoAudioProcessorEditor::~VenoAudioProcessorEditor() {
LookAndFeel::setDefaultLookAndFeel(nullptr);
waveform.reset(nullptr);
VenoAudioProcessorEditor::~VenoAudioProcessorEditor ()
{
LookAndFeel::setDefaultLookAndFeel (nullptr);
waveform.reset (nullptr);
delete m_look;
Config::getInstance()->removeEditor(m_id);
Config::getInstance ()->removeEditor (m_id);
}
void VenoAudioProcessorEditor::paint(Graphics &g) {
g.setFont(VenoFonts::getNormal());
g.fillAll(Colour(0, 0, 0));
void VenoAudioProcessorEditor::paint (Graphics& g)
{
g.setFont (*VenoFonts::getNormal ());
g.fillAll (Colour (0, 0, 0));
}
void VenoAudioProcessorEditor::resized() {
if (waveform != nullptr) {
waveform->setBounds(0, 0, getWidth(), getHeight());
void VenoAudioProcessorEditor::resized ()
{
if (waveform != nullptr)
{
waveform->setBounds (0, 0, getWidth (), getHeight ());
}
}

View file

@ -5,19 +5,17 @@
#include "Veno/GUI/LookAndFeel/LookHandler.h"
#include "Veno/GUI/Components/LCD/SidebarLCD.h"
class VenoAudioProcessorEditor : public AudioProcessorEditor
class VenoAudioProcessorEditor : public AudioProcessorEditor
{
public:
VenoAudioProcessorEditor (VenoAudioProcessor&);
~VenoAudioProcessorEditor();
~VenoAudioProcessorEditor ();
void paint (Graphics&) override;
void resized() override;
void resized () override;
private:
VenoAudioProcessor& processor;
std::string m_id = "";
LookAndFeel_V4 *m_look = new LookHandler();
LookAndFeel_V4* m_look = new LookHandler ();
std::unique_ptr<SidebarLCD> waveform;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VenoAudioProcessorEditor)
};

View file

@ -2,7 +2,7 @@
#include "PluginEditor.h"
#include "Veno/Core/AudioConfig.h"
VenoAudioProcessor::VenoAudioProcessor()
VenoAudioProcessor::VenoAudioProcessor ()
/*#ifndef JucePlugin_PreferredChannelConfigurations
: AudioProcessor (BusesProperties()
#if ! JucePlugin_IsMidiEffect
@ -13,21 +13,25 @@ VenoAudioProcessor::VenoAudioProcessor()
#endif
)
#endif*/
: AudioProcessor(BusesProperties().withInput("Input", AudioChannelSet::stereo(), true).withOutput("Output",
AudioChannelSet::stereo(),
true)) {
instance = VenoInstance::createInstance(m_id);
: AudioProcessor (BusesProperties ().withInput ("Input", AudioChannelSet::stereo (), true).withOutput ("Output",
AudioChannelSet::stereo (),
true))
{
instance = VenoInstance::createInstance (m_id);
}
VenoAudioProcessor::~VenoAudioProcessor() {
VenoInstance::deleteInstance(m_id);
VenoAudioProcessor::~VenoAudioProcessor ()
{
VenoInstance::deleteInstance (m_id);
}
const String VenoAudioProcessor::getName() const {
const String VenoAudioProcessor::getName () const
{
return JucePlugin_Name;
}
bool VenoAudioProcessor::acceptsMidi() const {
bool VenoAudioProcessor::acceptsMidi () const
{
#if JucePlugin_WantsMidiInput
return true;
#else
@ -35,7 +39,8 @@ bool VenoAudioProcessor::acceptsMidi() const {
#endif
}
bool VenoAudioProcessor::producesMidi() const {
bool VenoAudioProcessor::producesMidi () const
{
#if JucePlugin_ProducesMidiOutput
return true;
#else
@ -43,7 +48,8 @@ bool VenoAudioProcessor::producesMidi() const {
#endif
}
bool VenoAudioProcessor::isMidiEffect() const {
bool VenoAudioProcessor::isMidiEffect () const
{
#if JucePlugin_IsMidiEffect
return true;
#else
@ -51,96 +57,113 @@ bool VenoAudioProcessor::isMidiEffect() const {
#endif
}
double VenoAudioProcessor::getTailLengthSeconds() const {
double VenoAudioProcessor::getTailLengthSeconds () const
{
return 0.0;
}
int VenoAudioProcessor::getNumPrograms() {
int VenoAudioProcessor::getNumPrograms ()
{
return 1;
}
int VenoAudioProcessor::getCurrentProgram() {
int VenoAudioProcessor::getCurrentProgram ()
{
return 0;
}
void VenoAudioProcessor::setCurrentProgram(int index) {
void VenoAudioProcessor::setCurrentProgram (int index)
{
}
const String VenoAudioProcessor::getProgramName(int index) {
const String VenoAudioProcessor::getProgramName (int index)
{
return {};
}
void VenoAudioProcessor::changeProgramName(int index, const String &newName) {
void VenoAudioProcessor::changeProgramName (int index, const String& newName)
{
}
//==============================================================================
void VenoAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock) {
auto audioConfig = AudioConfig::getInstance();
audioConfig->setSampleRate(sampleRate);
audioConfig->initWaveTables();
void VenoAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
auto audioConfig = AudioConfig::getInstance ();
audioConfig->setSampleRate (sampleRate);
audioConfig->initWaveTables ();
}
void VenoAudioProcessor::releaseResources() {
void VenoAudioProcessor::releaseResources ()
{
}
#ifndef JucePlugin_PreferredChannelConfigurations
bool VenoAudioProcessor::isBusesLayoutSupported(const BusesLayout &layouts) const {
bool VenoAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
{
#if JucePlugin_IsMidiEffect
ignoreUnused (layouts);
return true;
#else
if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono()
&& layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
if (layouts.getMainOutputChannelSet () != AudioChannelSet::mono ()
&& layouts.getMainOutputChannelSet () != AudioChannelSet::stereo ())
return false;
#if !JucePlugin_IsSynth
if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
return false;
#endif
return true;
#endif
}
#endif
void VenoAudioProcessor::processBlock(AudioBuffer<float> &buffer, MidiBuffer &midiMessages) {
void VenoAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
{
ScopedNoDenormals noDenormals;
instance->audioBuffer->reset(buffer.getNumSamples());
int numChannels = buffer.getNumChannels();
for (int i = 0; i < numChannels; ++i) {
auto c = buffer.getReadPointer(i);
for (int j = 0; j < buffer.getNumSamples(); ++j) {
instance->fft.pushNextSampleIntoFifo(c[j]);
instance->audioBuffer->addMonoSample(c[j], j);
if (i == 0) {
instance->audioBuffer->addLeftSample(c[j], j);
instance->matrix.updateSlots ();
instance->audioBuffer->reset (buffer.getNumSamples ());
int numChannels = buffer.getNumChannels ();
for (int i = 0; i < numChannels; ++i)
{
auto c = buffer.getReadPointer (i);
for (int j = 0; j < buffer.getNumSamples (); ++j)
{
instance->fft.pushNextSampleIntoFifo (c[j]);
instance->audioBuffer->addMonoSample (c[j], j);
if (i == 0)
{
instance->audioBuffer->addLeftSample (c[j], j);
}
if (i == 1 || numChannels == 1) {
instance->audioBuffer->addRightSample(c[j], j);
if (i == 1 || numChannels == 1)
{
instance->audioBuffer->addRightSample (c[j], j);
}
}
}
}
//==============================================================================
bool VenoAudioProcessor::hasEditor() const {
bool VenoAudioProcessor::hasEditor () const
{
return true;
}
AudioProcessorEditor *VenoAudioProcessor::createEditor() {
return new VenoAudioProcessorEditor(*this);
AudioProcessorEditor* VenoAudioProcessor::createEditor ()
{
return new VenoAudioProcessorEditor (*this);
}
//==============================================================================
void VenoAudioProcessor::getStateInformation(MemoryBlock &destData) {
void VenoAudioProcessor::getStateInformation (MemoryBlock& destData)
{
}
void VenoAudioProcessor::setStateInformation(const void *data, int sizeInBytes) {
void VenoAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
}
AudioProcessor *JUCE_CALLTYPE createPluginFilter() {
return new VenoAudioProcessor();
AudioProcessor* JUCE_CALLTYPE createPluginFilter ()
{
return new VenoAudioProcessor ();
}

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

Some files were not shown because too many files have changed in this diff Show more