WIP
This commit is contained in:
parent
d735c1d076
commit
26a2935e1c
52 changed files with 1510 additions and 104 deletions
|
|
@ -1,26 +1,33 @@
|
||||||
#include "PluginProcessor.h"
|
#include "PluginProcessor.h"
|
||||||
#include "PluginEditor.h"
|
#include "PluginEditor.h"
|
||||||
#include "Veno/Core/Config.h"
|
#include "Veno/Core/Config.h"
|
||||||
|
#include "Veno/Utils/Logger.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);
|
||||||
setSize(400, 300);
|
waveform = std::make_unique<SidebarLCD>(m_id);
|
||||||
|
setSize(600, 400);
|
||||||
|
addAndMakeVisible(*waveform);
|
||||||
}
|
}
|
||||||
|
|
||||||
VenoAudioProcessorEditor::~VenoAudioProcessorEditor() {
|
VenoAudioProcessorEditor::~VenoAudioProcessorEditor() {
|
||||||
LookAndFeel::setDefaultLookAndFeel(nullptr);
|
LookAndFeel::setDefaultLookAndFeel(nullptr);
|
||||||
Config::getInstance()->removeEditor(m_id);
|
waveform.reset(nullptr);
|
||||||
delete m_look;
|
delete m_look;
|
||||||
|
Config::getInstance()->removeEditor(m_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VenoAudioProcessorEditor::paint(Graphics &g) {
|
void VenoAudioProcessorEditor::paint(Graphics &g) {
|
||||||
g.fillAll(getLookAndFeel().findColour(ResizableWindow::backgroundColourId));
|
g.setFont(VenoFonts::getNormal());
|
||||||
g.setColour(Colours::white);
|
g.fillAll(Colour(0, 0, 0));
|
||||||
g.setFont(15.0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VenoAudioProcessorEditor::resized() {
|
void VenoAudioProcessorEditor::resized() {
|
||||||
|
if (waveform != nullptr) {
|
||||||
|
waveform->setBounds(0, 0, getWidth(), getHeight());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <JuceHeader.h>
|
#include <JuceHeader.h>
|
||||||
#include "PluginProcessor.h"
|
#include "PluginProcessor.h"
|
||||||
#include "Veno/GUI/LookAndFeel/LookHandler.h"
|
#include "Veno/GUI/LookAndFeel/LookHandler.h"
|
||||||
|
#include "Veno/GUI/Components/LCD/SidebarLCD.h"
|
||||||
|
|
||||||
class VenoAudioProcessorEditor : public AudioProcessorEditor
|
class VenoAudioProcessorEditor : public AudioProcessorEditor
|
||||||
{
|
{
|
||||||
|
|
@ -16,6 +17,7 @@ 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;
|
||||||
|
|
||||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VenoAudioProcessorEditor)
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VenoAudioProcessorEditor)
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
#include "PluginProcessor.h"
|
#include "PluginProcessor.h"
|
||||||
#include "PluginEditor.h"
|
#include "PluginEditor.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
|
||||||
#if ! JucePlugin_IsSynth
|
#if ! JucePlugin_IsSynth
|
||||||
|
|
@ -10,138 +12,135 @@ VenoAudioProcessor::VenoAudioProcessor()
|
||||||
.withOutput ("Output", AudioChannelSet::stereo(), true)
|
.withOutput ("Output", AudioChannelSet::stereo(), true)
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
#endif
|
#endif*/
|
||||||
{
|
: AudioProcessor(BusesProperties().withInput("Input", AudioChannelSet::stereo(), true).withOutput("Output",
|
||||||
|
AudioChannelSet::stereo(),
|
||||||
|
true)) {
|
||||||
|
instance = VenoInstance::createInstance(m_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
VenoAudioProcessor::~VenoAudioProcessor()
|
VenoAudioProcessor::~VenoAudioProcessor() {
|
||||||
{
|
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
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VenoAudioProcessor::producesMidi() const
|
bool VenoAudioProcessor::producesMidi() const {
|
||||||
{
|
#if JucePlugin_ProducesMidiOutput
|
||||||
#if JucePlugin_ProducesMidiOutput
|
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VenoAudioProcessor::isMidiEffect() const
|
bool VenoAudioProcessor::isMidiEffect() const {
|
||||||
{
|
#if JucePlugin_IsMidiEffect
|
||||||
#if JucePlugin_IsMidiEffect
|
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#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);
|
||||||
|
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
|
|
||||||
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void VenoAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
|
return true;
|
||||||
{
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void VenoAudioProcessor::processBlock(AudioBuffer<float> &buffer, MidiBuffer &midiMessages) {
|
||||||
ScopedNoDenormals noDenormals;
|
ScopedNoDenormals noDenormals;
|
||||||
auto totalNumInputChannels = getTotalNumInputChannels();
|
|
||||||
auto totalNumOutputChannels = getTotalNumOutputChannels();
|
instance->audioBuffer->reset(buffer.getNumSamples());
|
||||||
for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
|
int numChannels = buffer.getNumChannels();
|
||||||
buffer.clear (i, 0, buffer.getNumSamples());
|
for (int i = 0; i < numChannels; ++i) {
|
||||||
for (int channel = 0; channel < totalNumInputChannels; ++channel)
|
auto c = buffer.getReadPointer(i);
|
||||||
{
|
for (int j = 0; j < buffer.getNumSamples(); ++j) {
|
||||||
auto* channelData = buffer.getWritePointer (channel);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <JuceHeader.h>
|
#include <JuceHeader.h>
|
||||||
|
#include "Veno/VenoInstance.h"
|
||||||
|
|
||||||
class VenoAudioProcessor : public AudioProcessor {
|
class VenoAudioProcessor : public AudioProcessor {
|
||||||
public:
|
public:
|
||||||
|
|
@ -51,6 +52,8 @@ public:
|
||||||
|
|
||||||
// Variable to communicate with the GUI and the Processor
|
// Variable to communicate with the GUI and the Processor
|
||||||
std::string m_id = Uuid().toString().toStdString();
|
std::string m_id = Uuid().toString().toStdString();
|
||||||
|
std::shared_ptr<VenoInstance> instance;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VenoAudioProcessor)
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VenoAudioProcessor)
|
||||||
};
|
};
|
||||||
|
|
|
||||||
8
Source/Resources/GL/WaveForm.fragment.glsl
Normal file
8
Source/Resources/GL/WaveForm.fragment.glsl
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#version 330 core
|
||||||
|
in vec4 newColor;
|
||||||
|
|
||||||
|
out vec4 fragColor;
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fragColor = newColor;
|
||||||
|
}
|
||||||
10
Source/Resources/GL/WaveForm.vertex.glsl
Normal file
10
Source/Resources/GL/WaveForm.vertex.glsl
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#version 330 core
|
||||||
|
in vec4 position;
|
||||||
|
uniform vec4 color = vec4(1f, 1f, 1f, 1f);
|
||||||
|
|
||||||
|
out vec4 newColor;
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = position;
|
||||||
|
newColor = color;
|
||||||
|
}
|
||||||
BIN
Source/Resources/arvo.ttf
Normal file
BIN
Source/Resources/arvo.ttf
Normal file
Binary file not shown.
BIN
Source/Resources/lcd.ttf
Normal file
BIN
Source/Resources/lcd.ttf
Normal file
Binary file not shown.
11
Source/Veno/Audio/Synth/SynthInstance.cpp
Normal file
11
Source/Veno/Audio/Synth/SynthInstance.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
//
|
||||||
|
// Created by versustune on 09.06.20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "SynthInstance.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
SynthInstance::SynthInstance(std::string processId)
|
||||||
|
: m_processId(std::move(processId)) {
|
||||||
|
}
|
||||||
22
Source/Veno/Audio/Synth/SynthInstance.h
Normal file
22
Source/Veno/Audio/Synth/SynthInstance.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
//
|
||||||
|
// Created by versustune on 09.06.20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef VENO_SYNTHINSTANCE_H
|
||||||
|
#define VENO_SYNTHINSTANCE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// class that hold all voices, oscillators and other stuff :)
|
||||||
|
class SynthInstance {
|
||||||
|
private:
|
||||||
|
std::string m_processId;
|
||||||
|
public:
|
||||||
|
explicit SynthInstance(std::string processId);
|
||||||
|
~SynthInstance() = default;
|
||||||
|
protected:
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //VENO_SYNTHINSTANCE_H
|
||||||
74
Source/Veno/Audio/VenoBuffer.cpp
Normal file
74
Source/Veno/Audio/VenoBuffer.cpp
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
//
|
||||||
|
// Created by versustune on 12.06.20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include "VenoBuffer.h"
|
||||||
|
|
||||||
|
VenoBuffer::VenoBuffer() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
// reset to 0 dc :D
|
||||||
|
for (int i = 0; i < size; ++i) {
|
||||||
|
buffer[i] = 0;
|
||||||
|
left[i] = 0;
|
||||||
|
right[i] = 0;
|
||||||
|
}
|
||||||
|
leftPeak = 0;
|
||||||
|
rightPeak = 0;
|
||||||
|
monoPeak = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VenoBuffer::addMonoSample(float value, int index) {
|
||||||
|
buffer[index] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VenoBuffer::addLeftSample(float value, int index) {
|
||||||
|
left[index] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
monoPeak = m;
|
||||||
|
}
|
||||||
|
if (l > leftPeak) {
|
||||||
|
leftPeak = l;
|
||||||
|
}
|
||||||
|
if (r > rightPeak) {
|
||||||
|
rightPeak = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<float> &VenoBuffer::getBuffer() const {
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<float> &VenoBuffer::getRight() const {
|
||||||
|
return right;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<float> &VenoBuffer::getLeft() const {
|
||||||
|
return left;
|
||||||
|
}
|
||||||
37
Source/Veno/Audio/VenoBuffer.h
Normal file
37
Source/Veno/Audio/VenoBuffer.h
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
//
|
||||||
|
// Created by versustune on 12.06.20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef VENO_VENOBUFFER_H
|
||||||
|
#define VENO_VENOBUFFER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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();
|
||||||
|
float leftPeak;
|
||||||
|
float rightPeak;
|
||||||
|
float monoPeak;
|
||||||
|
|
||||||
|
const std::vector<float> &getBuffer() const;
|
||||||
|
|
||||||
|
const std::vector<float> &getRight() const;
|
||||||
|
|
||||||
|
const std::vector<float> &getLeft() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //VENO_VENOBUFFER_H
|
||||||
28
Source/Veno/Audio/WaveTable/SawWaves.cpp
Normal file
28
Source/Veno/Audio/WaveTable/SawWaves.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
//
|
||||||
|
// Created by versustune on 08.06.20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "WaveTableGenerator.h"
|
||||||
|
#include "../../Utils/Logger.h"
|
||||||
|
#include "TableHelper.h"
|
||||||
|
|
||||||
|
void generateSaw(WaveTableGroup *group) {
|
||||||
|
if (group == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int tableLen = findTableLen();
|
||||||
|
int 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++) {
|
||||||
|
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");
|
||||||
|
}
|
||||||
11
Source/Veno/Audio/WaveTable/SawWaves.h
Normal file
11
Source/Veno/Audio/WaveTable/SawWaves.h
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
//
|
||||||
|
// Created by versustune on 08.06.20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef VENO_SAWWAVES_H
|
||||||
|
#define VENO_SAWWAVES_H
|
||||||
|
|
||||||
|
void generateSaw(WaveTableGroup *group);
|
||||||
|
|
||||||
|
|
||||||
|
#endif //VENO_SAWWAVES_H
|
||||||
5
Source/Veno/Audio/WaveTable/SineWaves.cpp
Normal file
5
Source/Veno/Audio/WaveTable/SineWaves.cpp
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
//
|
||||||
|
// Created by versustune on 08.06.20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "SineWaves.h"
|
||||||
14
Source/Veno/Audio/WaveTable/SineWaves.h
Normal file
14
Source/Veno/Audio/WaveTable/SineWaves.h
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
//
|
||||||
|
// Created by versustune on 08.06.20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef VENO_SINEWAVES_H
|
||||||
|
#define VENO_SINEWAVES_H
|
||||||
|
|
||||||
|
|
||||||
|
class SineWaves {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //VENO_SINEWAVES_H
|
||||||
5
Source/Veno/Audio/WaveTable/SquareWaves.cpp
Normal file
5
Source/Veno/Audio/WaveTable/SquareWaves.cpp
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
//
|
||||||
|
// Created by versustune on 08.06.20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "SquareWaves.h"
|
||||||
14
Source/Veno/Audio/WaveTable/SquareWaves.h
Normal file
14
Source/Veno/Audio/WaveTable/SquareWaves.h
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
//
|
||||||
|
// Created by versustune on 08.06.20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef VENO_SQUAREWAVES_H
|
||||||
|
#define VENO_SQUAREWAVES_H
|
||||||
|
|
||||||
|
|
||||||
|
class SquareWaves {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //VENO_SQUAREWAVES_H
|
||||||
154
Source/Veno/Audio/WaveTable/TableHelper.cpp
Normal file
154
Source/Veno/Audio/WaveTable/TableHelper.cpp
Normal file
|
|
@ -0,0 +1,154 @@
|
||||||
|
//
|
||||||
|
// Created by versustune on 08.06.20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "TableHelper.h"
|
||||||
|
#include "../../Core/AudioConfig.h"
|
||||||
|
#include "../../Utils.h"
|
||||||
|
|
||||||
|
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;
|
||||||
|
double t; /* temp */
|
||||||
|
double Ur, Ui, Wr, Wi, Tr, Ti;
|
||||||
|
double Ur_old;
|
||||||
|
|
||||||
|
// if ((N > 1) && !(N & (N - 1))) // make sure we have a power of 2
|
||||||
|
|
||||||
|
NV2 = N >> 1;
|
||||||
|
NM1 = N - 1;
|
||||||
|
TEMP = N; /* get M = log N */
|
||||||
|
M = 0;
|
||||||
|
while (TEMP >>= 1) ++M;
|
||||||
|
|
||||||
|
/* shuffle */
|
||||||
|
j = 1;
|
||||||
|
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;
|
||||||
|
t = ai[j - 1];
|
||||||
|
ai[j - 1] = ai[i - 1];
|
||||||
|
ai[i - 1] = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
k = NV2; /* bit-reversed counter */
|
||||||
|
while (k < j) {
|
||||||
|
j -= k;
|
||||||
|
k /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
j += k;
|
||||||
|
}
|
||||||
|
|
||||||
|
LE = 1.;
|
||||||
|
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
|
||||||
|
ip = i + LE1;
|
||||||
|
Tr = ar[ip - 1] * Ur - ai[ip - 1] * Ui;
|
||||||
|
Ti = ar[ip - 1] * Ui + ai[ip - 1] * Ur;
|
||||||
|
ar[ip - 1] = ar[i - 1] - Tr;
|
||||||
|
ai[ip - 1] = ai[i - 1] - Ti;
|
||||||
|
ar[i - 1] = ar[i - 1] + Tr;
|
||||||
|
ai[i - 1] = ai[i - 1] + Ti;
|
||||||
|
}
|
||||||
|
Ur_old = Ur;
|
||||||
|
Ur = Ur_old * Wr - Ui * Wi;
|
||||||
|
Ui = Ur_old * Wi + Ui * Wr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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]);
|
||||||
|
if (max < temp)
|
||||||
|
max = temp;
|
||||||
|
}
|
||||||
|
scale = 1.0 / max * .999;
|
||||||
|
}
|
||||||
|
|
||||||
|
// normalize
|
||||||
|
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];
|
||||||
|
table->m_waveTableLen = len;
|
||||||
|
table->m_topFreq = topFreq;
|
||||||
|
++group->m_numWaveTables;
|
||||||
|
|
||||||
|
// fill in wave
|
||||||
|
for (long idx = 0; idx < len; idx++)
|
||||||
|
waveTable[idx] = wave[idx];
|
||||||
|
waveTable[len] = waveTable[0]; // duplicate for interpolation wraparound
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
scale = 0.0;
|
||||||
|
}
|
||||||
|
return (float) scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
double topFreq = 2.0 / 3.0 / maxHarmonic;
|
||||||
|
|
||||||
|
double *ar = new double[numSamples];
|
||||||
|
double *ai = new double[numSamples];
|
||||||
|
double scale = 0.0;
|
||||||
|
int numTables = 0;
|
||||||
|
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++) {
|
||||||
|
ar[idx] = freqWaveRe[idx];
|
||||||
|
ai[idx] = freqWaveIm[idx];
|
||||||
|
ar[numSamples - idx] = freqWaveRe[numSamples - idx];
|
||||||
|
ai[numSamples - idx] = freqWaveIm[numSamples - idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
// make the wavetable
|
||||||
|
scale = makeWaveTable(group, numSamples, ar, ai, scale, topFreq);
|
||||||
|
numTables++;
|
||||||
|
|
||||||
|
// prepare for next table
|
||||||
|
topFreq *= 2;
|
||||||
|
maxHarmonic >>= 1;
|
||||||
|
}
|
||||||
|
return numTables;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
34
Source/Veno/Audio/WaveTable/TableHelper.h
Normal file
34
Source/Veno/Audio/WaveTable/TableHelper.h
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
//
|
||||||
|
// Created by versustune on 08.06.20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef VENO_TABLEHELPER_H
|
||||||
|
#define VENO_TABLEHELPER_H
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include "WaveTableGenerator.h"
|
||||||
|
|
||||||
|
#define M_PI 3.14159265358979323846
|
||||||
|
#define DOUBLE_PI 6.283185307179586476925286766559
|
||||||
|
|
||||||
|
/*
|
||||||
|
in-place complex fft
|
||||||
|
After Cooley, Lewis, and Welch; from Rabiner & Gold (1975)
|
||||||
|
program adapted from FORTRAN
|
||||||
|
by K. Steiglitz (ken@princeton.edu)
|
||||||
|
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);
|
||||||
|
|
||||||
|
// utils stuff
|
||||||
|
int fillTables(WaveTableGroup *group, double *freqWaveRe, double *freqWaveIm, int numSamples);
|
||||||
|
|
||||||
|
int findTableLen();
|
||||||
|
|
||||||
|
float getNextRand();
|
||||||
|
|
||||||
|
#endif //VENO_TABLEHELPER_H
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue