Skip to content

Commit

Permalink
Make some optimization changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dchan3 committed Aug 17, 2018
1 parent 9f85731 commit 1bde6c2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
30 changes: 20 additions & 10 deletions Source/OvertonixVoice.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#include "OvertonixVoice.h"
#include "OvertonixSound.h"

#define NUM_SAMPLES 1024

OvertonixVoice::OvertonixVoice(AudioProcessorValueTreeState& args) : params(&args) {
generateSinTable(NUM_SAMPLES);

}

void OvertonixVoice::generateSinTable(int samples) {
for (int x = 0; x < 20; x++) {
for (int y = 0; y < samples; y++) {
sinTable[x][y] = std::sin((double)(x) * ((double)y * (2.0 * double_Pi / (double)samples)));
}
}
}

bool OvertonixVoice::canPlaySound(SynthesiserSound* sound) {
Expand All @@ -13,7 +24,7 @@ void OvertonixVoice::startNote(int note, float velocity, SynthesiserSound* sound
level = velocity * 0.001;
double cycHz = MidiMessage::getMidiNoteInHertz(note);
currentSampleIndex = 0.0;
currentSampleDelta = cycHz * 128.0 / getSampleRate();
currentSampleDelta = cycHz * NUM_SAMPLES / getSampleRate();
generateWavetable();
tailOff = 0.0;
}
Expand Down Expand Up @@ -45,7 +56,7 @@ void OvertonixVoice::processBlock(AudioBuffer<FloatType>& out, int start, int nu
for (int i = out.getNumChannels(); --i >= 0;) out.addSample(i, start, current);

currentSampleIndex += currentSampleDelta;
if (currentSampleIndex > 128) currentSampleIndex -= 128;
if (currentSampleIndex > NUM_SAMPLES) currentSampleIndex -= NUM_SAMPLES;
++start;

if (tailOff > 0.0) {
Expand All @@ -59,21 +70,20 @@ void OvertonixVoice::processBlock(AudioBuffer<FloatType>& out, int start, int nu
}

void OvertonixVoice::generateWavetable() {
double retval = 0.0, angle = 0.0, delta = 2.0 * double_Pi / 128.0;
double retval = 0.0;
float highEndSlope = *(params->getRawParameterValue(strs[7])), highEndLevel = *(params->getRawParameterValue(strs[8]));
for (int p = 0; p < 128; p++) {
retval = std::sin(angle) * 100.0;
for (int p = 0; p < NUM_SAMPLES; p++) {
retval = sinTable[1][p] * 100.0;

for (int o = 0; o < 7; o++) {
double level = *(params->getRawParameterValue(strs[o]));
retval += std::sin((o + 2) * angle) * level;
for (int o = 2; o < 9; o++) {
double level = *(params->getRawParameterValue(strs[o - 2]));
retval += sinTable[o][p] * level;
}

for (int k = 9; k < 20; k++) {
retval += std::sin(k * angle) * (highEndLevel) * pow(5 - highEndSlope, 8 - k);
retval += sinTable[k][p] * (highEndLevel) * pow((float)5 - highEndSlope, (float)8 - k);
}
wavetable[p] = retval;
angle += delta;
}
}

Expand Down
6 changes: 5 additions & 1 deletion Source/OvertonixVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "../JuceLibraryCode/JuceHeader.h"

#define NUM_SAMPLES 1024

class OvertonixVoice : public SynthesiserVoice {
public:
OvertonixVoice(AudioProcessorValueTreeState&);
Expand All @@ -13,6 +15,7 @@ class OvertonixVoice : public SynthesiserVoice {
void pitchWheelMoved(int) override;
void controllerMoved(int, int) override;
void generateWavetable();
void generateSinTable(int);
private:
template <typename FloatType>
void processBlock(AudioBuffer<FloatType>&, int, int);
Expand All @@ -28,7 +31,8 @@ class OvertonixVoice : public SynthesiserVoice {
StringRef("highEndSlope"),
StringRef("highEndLevel")
};
double wavetable[128];
double sinTable[20][NUM_SAMPLES];
double wavetable[NUM_SAMPLES];
double newValues[9];
AudioProcessorValueTreeState* params;
};
2 changes: 2 additions & 0 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ OvertonixAudioProcessorEditor::OvertonixAudioProcessorEditor (OvertonixAudioProc
addAndMakeVisible(labels[8]);

setSize (450, 400);
setRepaintsOnMouseActivity(true);
}

OvertonixAudioProcessorEditor::~OvertonixAudioProcessorEditor()
Expand All @@ -73,5 +74,6 @@ void OvertonixAudioProcessorEditor::resized()
}

void OvertonixAudioProcessorEditor::sliderValueChanged(Slider *slider) {
slider->repaint();
processor.updateValue();
}
2 changes: 1 addition & 1 deletion Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ OvertonixAudioProcessor::OvertonixAudioProcessor()
}
parameters.createAndAddParameter("highEndLevel", "High End Level", String(), NormalisableRange<float>(0.0f, 100.0f, 1.0f), 100.f, nullptr, nullptr);

parameters.createAndAddParameter("highEndSlope", "High End Slope", String(), NormalisableRange<float>(1.00f, 4.80f, 0.05f), 1.5f, nullptr, nullptr);
parameters.createAndAddParameter("highEndSlope", "High End Slope", String(), NormalisableRange<float>(1.00f, 4.00f, 0.05f), 1.5f, nullptr, nullptr);

parameters.state = ValueTree(Identifier("Overtonix"));

Expand Down

0 comments on commit 1bde6c2

Please sign in to comment.