Re: ADSR - How to Trigger Envelope?
Posted: Thu Oct 07, 2021 6:52 pm
Actually, looks like I figured it out; I needed to run 'envelope.SetGate(false)' whenever the gate signal becomes 0.0. Here is the whole code block in case it helps someone:
Code: Select all
if(outputJack.IsConnected()){
if(inputJackGate.GetValue() > 0.0 && gateSet == false ){
envelope.SetGate(true);
gateSet = true;
}
if(inputJackGate.GetValue() <= 0.0 && envelope.GetStage() == ADSREnvelope.ENV_STAGE.ADSR_Stage_Sustain){
envelope.SetGate(false);
gateSet = false;
}
if(envelope.GetStage() == ADSREnvelope.ENV_STAGE.ADSR_Stage_Off) {
envelope.Reset();
gateSet = false;
}
if(inputJackGate.GetValue() == 0.0){
envelope.SetGate(false);
gateSet = false;
}
if(inputJackV.IsConnected()){
cv = Math.pow(2, inputJackV.GetValue() + 0.25) * 55.0;
}
myosc.SetFrequency(cv + freq);
outputJack.SetValue(myosc.GetSawtoothValue() * envelope.GetValue());
myosc.AdvanceSample();
envelope.AdvanceSample();
}