samer@34: function ef=envadr(att,dec,rel) samer@34: % envadr - Make an attack-decay-release envelope function samer@34: % samer@34: % envadr :: samer@34: % natural ~'attack time in samples', samer@34: % real ~'decay time constant in samples', samer@34: % natural ~'release time in seconds' samer@34: % -> ([[N]]->[[N]]) ~'function to apply envelope to given signal' samer@34: % samer@34: % Attack and release are linear, decay is exponential. samer@34: samer@34: e=expenv(600000,att,dec); samer@34: r=linspace(0,1,rel); samer@34: ef=@shape; samer@34: samer@34: function x=shape(x) samer@34: L=length(x); samer@34: if L>0, samer@34: x=x.*e(1:L); samer@34: I=L - (0:length(r)-1); samer@34: x(I)=x(I).*r; samer@34: end samer@34: end samer@34: end samer@34: samer@34: function x=expenv(t,att,decay) samer@34: x=exp(-(0:t-1)/decay); samer@34: x(1:att)=((0:att-1)/att).*x(1:att); samer@34: end samer@34: