grame-cncm / faustlibraries

The Faust libraries

Home Page:https://faustlibraries.grame.fr

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Attack is too fast on exponential envelope en.adsre

jmidt opened this issue · comments

When the attack time is set high on the exponential ADSR envelope, the level saturates very quickly, both not giving the wanted slow increase and also creating a long time with nothing happening before going to the decay stage. I propose something like this as a fix or a separate function

adsre_variable_attack(attT60,decT60,susLvl,relT60,gate) = envelope
  with {
  ugate = gate>0;
  samps = ugate : +~(*(ugate)); // ramp time in samples
  attSamps = int(attT60 * ma.SR);

  //The function for the attack phase. Should go from 0-1 in attSamps samples. Here it is linear
  attLvl = samps/attSamps; 

   //In the attack phase the target moves up following attLvl
  target = select2(ugate, 0.0,
           select2(samps<attSamps, (susLvl)*float(ugate), attLvl));

  //Instead of attT60, we choose some very small number, such that there is virtually no smoothing in the attack phase
  t60 = select2(ugate, relT60, select2(samps<attSamps, decT60, 0.0000001)); 

  pole = ba.tau2pole(t60/6.91);
  envelope = target : si.smooth(pole);

This gives a linear ramp up, but any function could in principle be used. I can make a pull request if you want?

BTW, is your open-source project using Faust visible somewhere? Thanks.