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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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

View file

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

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