Skip to content

Commit

Permalink
fix the envelope issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vberthiaume committed Jul 5, 2024
1 parent 77a9b6c commit eb881b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
17 changes: 3 additions & 14 deletions source/DSP/ProPhatVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ class ProPhatVoice : public juce::SynthesiserVoice
static constexpr auto envelopeAmount { 2 };

juce::ADSR ampADSR, filterADSR;
juce::ADSR::Parameters ampParams, filterEnvParams;
juce::ADSR::Parameters ampParams { Constants::defaultAmpA, Constants::defaultAmpD, Constants::defaultAmpS, Constants::defaultAmpR };
juce::ADSR::Parameters filterEnvParams { ampParams };
bool currentlyReleasingNote = false, justDoneReleaseEnvelope = false;

T curFilterCutoff { Constants::defaultFilterCutoff };
Expand Down Expand Up @@ -184,16 +185,6 @@ class ProPhatVoice : public juce::SynthesiserVoice

//===========================================================================================================

inline void printADSR (juce::StringRef prefix, const juce::ADSR::Parameters& p)
{
juce::String str { prefix };
str << " a: " << p.attack;
str << " d: " << p.decay;
str << " s: " << p.sustain;
str << " r: " << p.release << "\n";
DBG (str);
}

template<std::floating_point T>
void ProPhatVoice<T>::renderNextBlockTemplate (juce::AudioBuffer<T>& outputBuffer, int startSample, int numSamples)
{
Expand Down Expand Up @@ -311,7 +302,7 @@ void ProPhatVoice<T>::prepare (const juce::dsp::ProcessSpec& spec)

ampADSR.setSampleRate (spec.sampleRate);
ampADSR.setParameters (ampParams);
printADSR ("prepare", ampADSR.getParameters());
Helpers::printADSR ("prepare", ampADSR.getParameters());

filterADSR.setSampleRate (spec.sampleRate);
filterADSR.setParameters (filterEnvParams);
Expand Down Expand Up @@ -399,7 +390,6 @@ void ProPhatVoice<T>::setAmpParam (juce::StringRef parameterID, float newValue)
ampParams.release = newValue;

ampADSR.setParameters (ampParams);
printADSR ("setAmpParam", ampADSR.getParameters());
}

template <std::floating_point T>
Expand Down Expand Up @@ -547,7 +537,6 @@ void ProPhatVoice<T>::startNote (int midiNoteNumber, float velocity, juce::Synth
#endif

ampADSR.setParameters (ampParams);
printADSR ("startNote", ampADSR.getParameters());
ampADSR.reset();
ampADSR.noteOn();

Expand Down
17 changes: 13 additions & 4 deletions source/Utility/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ constexpr float defaultEffectParam1 { 0.f };
constexpr float defaultEffectParam2 { 0.f };

//envelope stuff
constexpr auto minA { .001f };
constexpr auto minAmp { .01f };
constexpr auto minAmp { .000001f };

constexpr auto defaultAmpA { minA };
constexpr auto defaultAmpA { minAmp };
constexpr auto defaultAmpD { minAmp };
constexpr auto defaultAmpS { 1.f };
constexpr auto defaultAmpR { .25f };
Expand All @@ -76,7 +75,7 @@ constexpr auto ampSkewFactor { .5f };
constexpr auto cutOffSkewFactor { .5f };
constexpr auto slopSkewFactor { .5f };

const juce::NormalisableRange<float> attackRange { minA, 25.f, 0.f, ampSkewFactor };
const juce::NormalisableRange<float> attackRange { minAmp, 25.f, 0.f, ampSkewFactor };
const juce::NormalisableRange<float> decayRange { minAmp, 25.f, 0.f, ampSkewFactor };
const juce::NormalisableRange<float> sustainRange { minAmp, 1.f, 0.f, sustainSkewFactor };
const juce::NormalisableRange<float> releaseRange { minAmp, 25.f, 0.f, ampSkewFactor };
Expand Down Expand Up @@ -325,6 +324,16 @@ inline bool areSame (T a, T b, T e = std::numeric_limits <T>::epsilon())
{
return fabs (a - b) <= e;
}

inline void printADSR (juce::StringRef prefix, const juce::ADSR::Parameters& p)
{
juce::String str { prefix };
str << " a: " << p.attack;
str << " d: " << p.decay;
str << " s: " << p.sustain;
str << " r: " << p.release << "\n";
DBG (str);
}
}

#if 0
Expand Down

0 comments on commit eb881b7

Please sign in to comment.