Skip to content

Commit

Permalink
Added interpolation for some parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
AugsEU committed Jun 25, 2020
1 parent 091120a commit 7edeccb
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Augs Synth.jucer
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
pluginVST3Category="Instrument,Synth" pluginCharacteristicsValue="pluginIsSynth,pluginProducesMidiOut,pluginWantsMidiIn">
<MAINGROUP id="PhCh5B" name="Augs Synth">
<GROUP id="{8A646E7D-788C-F100-CDB0-4BAEF60D8B7F}" name="Source">
<FILE id="QMX77C" name="ParameterInterpolator.cpp" compile="1" resource="0"
file="Source/ParameterInterpolator.cpp"/>
<FILE id="DFcVxV" name="ParameterInterpolator.h" compile="0" resource="0"
file="Source/ParameterInterpolator.h"/>
<GROUP id="{3AB4B9AA-2A1D-6F00-4D3F-E467A4223398}" name="Filters">
<FILE id="Z0ZzTb" name="RecursiveFilter.cpp" compile="1" resource="0"
file="Source/RecursiveFilter.cpp"/>
Expand Down
2 changes: 1 addition & 1 deletion Source/Defs.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#include <string>

#define NUM_VOICES 1

Expand Down
32 changes: 32 additions & 0 deletions Source/ParameterInterpolator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
==============================================================================
ParameterInterpolator.cpp
Created: 25 Jun 2020 6:07:10pm
Author: August
==============================================================================
*/

#include "ParameterInterpolator.h"

void ParameterInterpolator::StartNewBuffer(AudioProcessorValueTreeState& State, int& BuffSize)
{
for (int i = 0; i < NUM_FLOAT_PARAMS; i++)
{
OldFloatParams[i] = GoalFloatParams[i];
}

for (int i = 0; i < NUM_FLOAT_PARAMS; i++)
{
GoalFloatParams[i] = State.getParameterAsValue(FloatParamProps[i].ID).getValue();
}

BufferSize = BuffSize;
}

float ParameterInterpolator::GetFloat(const int& i, const int& SampleIdx)
{
float Multiplyer = (float)SampleIdx / (float)BufferSize;
return OldFloatParams[i] + Multiplyer*(GoalFloatParams[i] - OldFloatParams[i]);
}
30 changes: 30 additions & 0 deletions Source/ParameterInterpolator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
==============================================================================
ParameterInterpolator.h
Created: 25 Jun 2020 6:07:10pm
Author: August
==============================================================================
*/

#pragma once
#include "Defs.h"
#include "JuceHeader.h"

class ParameterInterpolator
{
public:
ParameterInterpolator() {}
~ParameterInterpolator() {}

void StartNewBuffer(AudioProcessorValueTreeState& State, int& BuffSize);
float GetFloat(const int& i, const int& SampleIdx);


private:
int BufferSize = 0;
float OldFloatParams[NUM_FLOAT_PARAMS];
float GoalFloatParams[NUM_FLOAT_PARAMS];

};
20 changes: 15 additions & 5 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ AugsSynthAudioProcessor::AugsSynthAudioProcessor()
#endif
.withOutput ("Output", AudioChannelSet::stereo(), true)
#endif
), mParamTree(*this, nullptr, "PARAMS", createParameterLayout())
), mParamTree(*this, nullptr, "PARAMS", createParameterLayout()), mIterpolator()
#endif
{
for (auto i = 0; i < NUM_VOICES; ++i) // Define voices
Expand Down Expand Up @@ -157,7 +157,10 @@ bool AugsSynthAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts
void AugsSynthAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
buffer.clear();
int Num_Samples = buffer.getNumSamples();

mKeyState.processNextMidiBuffer(midiMessages, 0, buffer.getNumSamples(), true);
mIterpolator.StartNewBuffer(mParamTree, Num_Samples);

double Attack = mParamTree.getParameterAsValue(FloatParamProps[0].ID).getValue();
double Decay = mParamTree.getParameterAsValue(FloatParamProps[1].ID).getValue();
Expand All @@ -182,18 +185,25 @@ void AugsSynthAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer
mSynth.renderNextBlock(buffer, midiMessages, 0, buffer.getNumSamples());

float PowDist = (float)mParamTree.getParameterAsValue(FloatParamProps[6].ID).getValue();
float TrimDist = 1-(float)mParamTree.getParameterAsValue(FloatParamProps[7].ID).getValue();
double Volume = mParamTree.getParameterAsValue(FloatParamProps[4].ID).getValue();




for (int sample = 0; sample < buffer.getNumSamples(); sample++)
for (int sample = 0; sample < Num_Samples; sample++)
{
for (int channel = 0; channel < buffer.getNumChannels(); channel++)
{
float MySample = buffer.getSample(channel, sample);


//Distortion
float PowDist = mIterpolator.GetFloat(6, sample);
float TrimDist = 1 - mIterpolator.GetFloat(7, sample);
ApplyDistort(MySample, PowDist, TrimDist);

//Volume
float Volume = mIterpolator.GetFloat(4, sample);
MySample *= Volume;

buffer.setSample(channel, sample, MySample);
}
}
Expand Down
4 changes: 3 additions & 1 deletion Source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#pragma once

#include <JuceHeader.h>
#include "ParameterInterpolator.h"

//==============================================================================
/**
Expand Down Expand Up @@ -64,10 +65,11 @@ class AugsSynthAudioProcessor : public AudioProcessor

AudioProcessorValueTreeState::ParameterLayout createParameterLayout();


Synthesiser mSynth;
MidiKeyboardState mKeyState;


ParameterInterpolator mIterpolator;

//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AugsSynthAudioProcessor)
Expand Down

0 comments on commit 7edeccb

Please sign in to comment.