Skip to content

Commit

Permalink
Added new tuning options
Browse files Browse the repository at this point in the history
  • Loading branch information
AugsEU committed Oct 17, 2020
1 parent c3c21ba commit 91a207a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
22 changes: 20 additions & 2 deletions Source/AugsVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,26 @@ bool AugsVoice::canPlaySound(SynthesiserSound* sound)
void AugsVoice::startNote(int midiNoteNumber, float velocity, SynthesiserSound*, int /*currentPitchWheelPosition*/)
{
mVelocity = velocity;
mOsc.setFrequency(MidiMessage::getMidiNoteInHertz(midiNoteNumber));
TuningType NoteTuningType = static_cast<TuningType>((int)rInterpolator.GetFloatOld(16));
mOsc.setFrequency(NoteNumberToHz(midiNoteNumber, NoteTuningType));
mEnv.enterStage(EnvelopeGenerator::EnvelopeStage::ENVELOPE_STAGE_ATTACK);
}

double AugsVoice::NoteNumberToHz(int midiNoteNumber, TuningType TT)
{
switch (TT)
{
case AugsVoice::TWELVE_TET:
return FREQ_A * std::pow(2.0, (midiNoteNumber - 69) / 12.0);
case AugsVoice::SEVEN_TWELVE_ET:
return FREQ_A * std::pow(1.5, (midiNoteNumber - 69) / 7.0);
case AugsVoice::FOUR_TWELVE_ET:
return FREQ_A * std::pow(1.25, (midiNoteNumber - 69) / 4.0);
default:
return 440.0f;
}
}

void AugsVoice::setEnvelope(double a, double d, double s, double r)
{
mEnv.setStageValue(EnvelopeGenerator::EnvelopeStage::ENVELOPE_STAGE_ATTACK, a);
Expand Down Expand Up @@ -42,6 +58,7 @@ void AugsVoice::controllerMoved(int controllerNumber, int newControllerValue) {}

void AugsVoice::renderNextBlock(AudioBuffer<float>& outputBuffer, int startSample, int numSamples)
{

for (int sample = 0; sample < numSamples; sample++)
{
double Attack = rInterpolator.GetFloat(0, sample);
Expand All @@ -63,10 +80,11 @@ void AugsVoice::renderNextBlock(AudioBuffer<float>& outputBuffer, int startSampl
float FilterRes = rInterpolator.GetFloat(10, sample);
setFilter(FilterCut, FilterRes, FilterMode);

double Volume = rInterpolator.GetFloat(4, sample);

double SampleVal = mOsc.nextSample();
double EnvValue = mEnv.nextSample();
SampleVal = SampleVal * EnvValue * mVelocity;
SampleVal = SampleVal * EnvValue * mVelocity * Volume;
mFilter.ProcessSample(SampleVal);

if ((mEnv.getCurrentStage() == EnvelopeGenerator::EnvelopeStage::ENVELOPE_STAGE_OFF) || (EnvValue < minimumValue))
Expand Down
10 changes: 9 additions & 1 deletion Source/AugsVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
class AugsVoice : public SynthesiserVoice
{
public:
enum TuningType
{
TWELVE_TET = 0,
SEVEN_TWELVE_ET,
FOUR_TWELVE_ET,
kNumTuningTypes
};

bool canPlaySound(SynthesiserSound* sound) override;
void startNote(int midiNoteNumber, float velocity, SynthesiserSound* sound, int currentPitchWheelPosition) override;
void stopNote(float velocity, bool allowTailOff) override;
Expand Down Expand Up @@ -40,5 +48,5 @@ class AugsVoice : public SynthesiserVoice
mFilter.setMode(static_cast<FilterMode>(Mode));
}


double NoteNumberToHz(int midiNoteNumber, TuningType TT);
};
10 changes: 6 additions & 4 deletions Source/Defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <string>

#define NUM_VOICES 8
#define FREQ_A 440.0f

typedef struct
{
Expand All @@ -13,7 +14,7 @@ typedef struct
const double skewFactor;
} FloatParam_Properties;

#define NUM_FLOAT_PARAMS 16
#define NUM_FLOAT_PARAMS 17
const FloatParam_Properties FloatParamProps[NUM_FLOAT_PARAMS] =
{ {"EnvAttack", "Attack", 0.0, 3.0, 0.1, 0.6},//0
{"EnvDecay", "Decay", 0.0, 3.0, 0.1, 0.7},//1
Expand All @@ -24,13 +25,14 @@ const FloatParam_Properties FloatParamProps[NUM_FLOAT_PARAMS] =
{"PowDist", "Pow dist", 0.4, 5.0, 1.0, 0.7},
{"TrimDist", "Trim dist",0.0, 0.99, 0.0, 2.3},
{"FilterTyp", "Filter type",0.0, 4.0, 0.0, 1.0},//8
{"CutOff", "Cut Off", 50.0, 20000.0,1000.0, 0.5},
{"FiltRes", "Resonance", 1.0, 10.0, 3.0, 0.6},
{"CutOff", "Cut Off", 50.0, 20000.0,1000.0, 0.3},
{"FiltRes", "Resonance", 1.0, 10.0, 3.0, 0.6},
{"DelayVol", "DlyVol", 0.0, 1.0, 0.0, 0.7},//11
{"DelayFall", "DlyFll", 0.0, 1.0, 0.5, 0.7}, //12
{"DelayTime", "DlyTm", 0.0, 2.0, 0.5, 0.6}, //13
{"LowTyp", "Low type", 0.0, 1.0, 0.0, 1.0}, //14
{"BandTyp", "Band type",0.0, 1.0, 0.0, 1.0}, };//15
{"BandTyp", "Band type",0.0, 1.0, 0.0, 1.0}, //15
{"Tuning", "Scale Tuning" ,0.0, 2.0, 0.0, 1.0} }; //16

//Filter Enums
enum FilterMode
Expand Down
11 changes: 11 additions & 0 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ void AugsSynthAudioProcessorEditor::InitGUI()
InitSlider(DlyTimeSlider, 13);
DlyTimeSlider.Slider.setTextValueSuffix("s");

//Tuning
InitCombo(TuningSelect, 16, { "12-TET","7-12-ET", "4-12-ET" });
}

void AugsSynthAudioProcessorEditor::InitSlider(Slider_Attach& MySlider, int Param_ID, double Increment, Slider::SliderStyle style)
Expand Down Expand Up @@ -124,6 +126,12 @@ void AugsSynthAudioProcessorEditor::paint (Graphics& g)
g.drawSingleLineText("Pow", 14, GUI_SPACING * 2 + 473);
g.drawSingleLineText("Trim", 14, GUI_SPACING * 3 + 473);

//Tuning
g.setColour(Colours::darkgrey);
g.drawRect(0, 410, 195, 60);
g.setColour(Colours::wheat);
g.drawSingleLineText("Tuning", 14, GUI_SPACING * 1 + 412);

//ADSR
g.setColour(Colours::darkgrey);
g.drawRect(340, 0, 195, 80);
Expand Down Expand Up @@ -167,6 +175,9 @@ void AugsSynthAudioProcessorEditor::resized()
PowerDistortionSlider.Slider.setBounds(2 * GUI_SPACING, 500, SliderWidth, GUI_SPACING);
TrimDistortionSlider.Slider.setBounds(2 * GUI_SPACING, 500 + GUI_SPACING, SliderWidth, GUI_SPACING);

//Tuning
TuningSelect.ComboBox.setBounds(10, 440, 95, 20);

//Filter
FilterSelect.ComboBox.setBounds(245, 21, 95, 20);
LowTypeSelect.ComboBox.setBounds(245, 42, 95, 20);
Expand Down
3 changes: 3 additions & 0 deletions Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class AugsSynthAudioProcessorEditor : public AudioProcessorEditor, public MidiKe
Slider_Attach DlyVolumeSlider;
Slider_Attach DlyFallOffSlider;
Slider_Attach DlyTimeSlider;

//Tuning
Combo_Attach TuningSelect;


private:
Expand Down
10 changes: 6 additions & 4 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,8 @@ void AugsSynthAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer
float TrimDist = 1 - mIterpolator.GetFloat(7, sample);
ApplyDistort(MySample, PowDist, TrimDist);

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



SampleAverage += MySample;
buffer.setSample(channel, sample, MySample);
Expand All @@ -201,7 +200,10 @@ void AugsSynthAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer
mDelay.UpdateParameters(DelayVol, DelayFall, DelayTime, DelayTimeInSamples);
float DelaySample = mDelay.ProcessSample(SampleAverage);

AddToAllChannels(DelaySample, sample, buffer);

//Volume
float Volume = mIterpolator.GetFloat(4, sample);
AddToAllChannels(DelaySample * Volume, sample, buffer);
}
}

Expand Down

0 comments on commit 91a207a

Please sign in to comment.