ADSR - How to Trigger Envelope?

bcgreen24
Posts: 13
Joined: Mon Oct 04, 2021 9:25 pm

Re: ADSR - How to Trigger Envelope?

Post by bcgreen24 »

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();
   }
bcgreen24
Posts: 13
Joined: Mon Oct 04, 2021 9:25 pm

Re: ADSR - How to Trigger Envelope?

Post by bcgreen24 »

OK, another newb question-- why am I having to divide the envelope values by 4 in order to get the voltage down to +/-5 and avoid clipping (saw tooth wave in my current test)?

Code: Select all

outputJack.SetValue(myosc1.GetSawtoothValue() * (envelope.GetValue()/4));
Also-- does anyone know where I can find a gentel introduction to DSP? All the searches I've performed so far have brought back results that are way over the head of this neophyte. :)

Thanks!
Bryan
ColinP
Posts: 939
Joined: Mon Aug 03, 2020 7:46 pm

Re: ADSR - How to Trigger Envelope?

Post by ColinP »

Hi Bryan,

I'm hopeless at diplomacy so the following is unfiltered opinion but with friendly intent. :D

If you had taken my advice then by now you would have a working envelope generator that you fully understood and would be able to modify in any way you desired.

Have more faith in your own abilities. A basic envelope generator is maybe two dozen lines of code. Using invisible, undocumented code that doesn't even come with a basic application example is folly.

Read what I said on Wednesday. Think about what the problem is and write your own code.

OK, grandad's rant over....

Nobody is going to give you a bibliography that has taken them thousands of hours to collate. (A) because a good one is commercially valuable and perhaps more importantly, (B) the research involved in trawling through all the garbage is an essential part of the learning process.

I divide my time between working on the main project, servicing old ones, developing the next one, thinking about "blue sky" projects, reading academic papers and such like but very importantly I also spend an hour or two per week working on improving my understanding of mathematics.

Algebra is crucial in my opinion. You need to be able to understand it to the extent that it's completely natural and you need to be able to translate that into code and understand the subtle differences between abstract numbers and numbers with finite bit lengths.

In the other direction you need to be able to translate all the higher mathematical symbols into algebraic and algorithmic components. This is tricky but you can find all the info you need online.

Then there are loads of higher level mathematical concepts to explore, but you can tackle them one by one once you have the groundwork in place.

DSP is a notoriously difficult field, although this is largely because there are lots of people who don't really understand the maths and write articles that pretend they do. I call this intellectual masturbation. The internet is full of people pretending to be clever. If you don't understand what someone is saying then remember that one possible explanation is that they don't understand it either.

DSP is a vague term like Computer Graphics. It's too wide a field. I advise you to think about what your goals are. Are you a student, a hobbyist, looking to develop a career? How many hours a week do you have available?

I'm part way through transitioning from control to audio work as LSSP should be pretty solid by the end of the year so I've spent some of the last few months researching granular synthesis and in my research I came across the following abstracts from a book by a guy called Dan Mitchell. It's perhaps the best beginner's guide to DSP that I've found so hopefully you will find it useful. The link is to the page on envelope generators that will show you just how simple it is to write your own, but there's loads more info there.

https://basicsynth.com/index.php?page=envgen

Best Regards,

Colin
Post Reply

Return to “Module Designer”