annotate dsp/synth/envadr.m @ 61:eff6bddf82e3
tip
Finally implemented perceptual brightness thing.
author |
samer |
date |
Sun, 11 Oct 2015 10:20:42 +0100 |
parents |
c75bb62b90a9 |
children |
|
rev |
line source |
samer@34
|
1 function ef=envadr(att,dec,rel)
|
samer@34
|
2 % envadr - Make an attack-decay-release envelope function
|
samer@34
|
3 %
|
samer@34
|
4 % envadr ::
|
samer@34
|
5 % natural ~'attack time in samples',
|
samer@34
|
6 % real ~'decay time constant in samples',
|
samer@34
|
7 % natural ~'release time in seconds'
|
samer@34
|
8 % -> ([[N]]->[[N]]) ~'function to apply envelope to given signal'
|
samer@34
|
9 %
|
samer@34
|
10 % Attack and release are linear, decay is exponential.
|
samer@34
|
11
|
samer@34
|
12 e=expenv(600000,att,dec);
|
samer@34
|
13 r=linspace(0,1,rel);
|
samer@34
|
14 ef=@shape;
|
samer@34
|
15
|
samer@34
|
16 function x=shape(x)
|
samer@34
|
17 L=length(x);
|
samer@34
|
18 if L>0,
|
samer@34
|
19 x=x.*e(1:L);
|
samer@34
|
20 I=L - (0:length(r)-1);
|
samer@34
|
21 x(I)=x(I).*r;
|
samer@34
|
22 end
|
samer@34
|
23 end
|
samer@34
|
24 end
|
samer@34
|
25
|
samer@34
|
26 function x=expenv(t,att,decay)
|
samer@34
|
27 x=exp(-(0:t-1)/decay);
|
samer@34
|
28 x(1:att)=((0:att-1)/att).*x(1:att);
|
samer@34
|
29 end
|
samer@34
|
30
|