Skip to content

Commit

Permalink
fixed ratio modulation
Browse files Browse the repository at this point in the history
fixed operator level control
  • Loading branch information
hsetlik committed Apr 13, 2021
1 parent ff9492e commit ffa2ecd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
12 changes: 6 additions & 6 deletions Source/FmVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ void FmVoice::renderNextBlock(juce::AudioBuffer<float> &outputBuffer, int startS
{
for(int i = startSample; i < (startSample + numSamples); ++i)
{
for(int lfo = 0; lfo < 4; ++ lfo)
{
applyLfo(lfo);
}

opSum = 0.0f;
sumL = 0.0f;
sumR = 0.0f;
for(Operator* op : operators)
{op->cleanFreqOffset();}
for(int lfo = 0; lfo < 4; ++ lfo)
{
applyLfo(lfo);
}
op1Index = 0;
for(Operator* o : operators)
{
Expand All @@ -72,13 +73,12 @@ void FmVoice::renderNextBlock(juce::AudioBuffer<float> &outputBuffer, int startS
++op2Index;
}
opSample = o->sample(fundamental);
if(opAudible[o->getIndex()])
if(opAudible[op1Index])
{
opSum += opSample;
sumL += o->lastOutputL;
sumR += o->lastOutputR;
}

++op1Index;
}
outputBuffer.addSample(0, i, sumL);
Expand Down
6 changes: 5 additions & 1 deletion Source/LfoComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ LfoModeSelector::LfoModeSelector(int index) : modeSelectorIndex(index)
addAndMakeVisible(bothButton);
addAndMakeVisible(downButton);
addAndMakeVisible(choiceHandler);
choiceHandler.setVisible(false);
upButton.addListener(this);
bothButton.addListener(this);
downButton.addListener(this);
//choiceHandler.setVisible(false);
auto none = juce::Colours::transparentBlack;
upButton.setImages(true, true, true, upOffImg, 1.0f, none, upOffImg, 1.0f, none, upOnImg, 1.0f, none);
upButton.setClickingTogglesState(true);
Expand Down Expand Up @@ -62,6 +65,7 @@ void LfoModeSelector::resized()
upButton.setBounds(0, 0, bWidth, getHeight());
bothButton.setBounds(bWidth, 0, bWidth, getHeight());
downButton.setBounds(2 * bWidth, 0, bWidth, getHeight());
choiceHandler.toBack();
}

void LfoModeSelector::attach(juce::AudioProcessorValueTreeState *tree)
Expand Down
36 changes: 21 additions & 15 deletions Source/OperatorProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,48 @@

#include "OperatorProcessor.h"

float Operator::sample(float fundamental)
float Operator::sample(float fund)
{
rawSample = wtOsc.getSample((fundamental * ratio) + (modOffset * modIndex));
fundamental = fund;
rawSample = wtOsc.getSample((fund * workingRatio) + (modOffset * modIndex)) * level;
lastOutputSample = envelope.process(rawSample) * ( 1.0f - amplitudeMod);
updatePan();
return lastOutputSample;
}

void Operator::modulateRatio(float value, int mode)
{
//value is between 0 and 1
//min ratio is 0.1f, max is 10.0f
auto maxIncrease = 10.0f - ratio;
auto maxDecrease = ratio - 0.1f;
float modValue;
//value is between 0 and 0.6f (just a bit of limiting)
//value *= 0.6f;
switch(mode)
{
case 0: //upwards only
{
modValue = maxIncrease * value;
maxRatioOffset = baseRatio;
workingRatio = baseRatio + (maxRatioOffset * value);
break;
}
case 1: // both directions
{
auto biValue = (value * 2.0f) - 1.0f; //track value to range -1, 1
if(biValue > 0.0f)
modValue = maxIncrease * biValue;
else
modValue = maxDecrease * biValue;
if(value > 0.5f)
{
value = (value - 0.5f) * 2.0f;
maxRatioOffset = baseRatio;
workingRatio = baseRatio + (maxRatioOffset * value);
}
if(value < 0.5f)
{
value *= 2.0f;
maxRatioOffset = baseRatio / 2.0f;
workingRatio = baseRatio - (maxRatioOffset * (1.0f - value));
}
break;
}
case 2: //downwards only
{
modValue = -maxDecrease * value;
maxRatioOffset = baseRatio / 2.0f;
workingRatio = baseRatio - (maxRatioOffset * (1.0f - value));
break;
}
}
ratio = ratio + modValue;
}
21 changes: 13 additions & 8 deletions Source/OperatorProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ class Operator
{
public:
juce::AudioProcessorValueTreeState* tree;
Operator(int opIndex, int voiceIndex, juce::AudioProcessorValueTreeState* t) : tree(t), lastOutputSample(0.0f), envelope(opIndex, tree), voice(voiceIndex), ratio(1.0f), index(opIndex)
Operator(int opIndex, int voiceIndex, juce::AudioProcessorValueTreeState* t) : tree(t), lastOutputSample(0.0f), envelope(opIndex, tree), voice(voiceIndex), baseRatio(1.0f), index(opIndex)
{
minRatio = std::numeric_limits<float>::max();
maxRatio = std::numeric_limits<float>::min();
auto iStr = juce::String(opIndex);
panId = "panParam" + iStr;
levelId = "levelParam" + iStr;
ratioId = "ratioParam" + iStr;
modIndexId = "indexParam" + iStr;

workingRatio = baseRatio;
}
~Operator()
{
Expand All @@ -44,7 +42,8 @@ class Operator
envelope.updateParams();
pan = getValue(panId);
level = getValue(levelId);
ratio = getValue(ratioId);
baseRatio = getValue(ratioId);
workingRatio = baseRatio;
modIndex = getValue(modIndexId);
}
int getIndex()
Expand Down Expand Up @@ -81,6 +80,10 @@ class Operator
{
amplitudeMod = value;
}
static float lerp(float min, float max, float value)
{
return min + ((max - min) * value);
}
float sample(float fundamental);
float lastOutputSample;
float gainL;
Expand All @@ -96,17 +99,19 @@ class Operator
private:
int index;
SineTableOscillator wtOsc;
float minRatio;
float maxRatio;
juce::String panId;
juce::String modIndexId;
juce::String levelId;
juce::String ratioId;
juce::String amplitudeId;
float pan;
float ratio;
float baseRatio;
float workingRatio;
float modIndex;
float level;
float amplitudeMod;
float fundamental;
float maxRatioOffset;
float minRatio;

};

0 comments on commit ffa2ecd

Please sign in to comment.