view 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
line wrap: on
line source
function ef=envadr(att,dec,rel)
% envadr - Make an attack-decay-release envelope function
%
% envadr :: 
%    natural ~'attack time in samples',
%    real    ~'decay time constant in samples',
%    natural ~'release time in seconds'
% -> ([[N]]->[[N]]) ~'function to apply envelope to given signal'
%
% Attack and release are linear, decay is exponential.

	e=expenv(600000,att,dec);
	r=linspace(0,1,rel);
	ef=@shape;

	function x=shape(x)
		L=length(x);
		if L>0,
			x=x.*e(1:L);
			I=L - (0:length(r)-1);
			x(I)=x(I).*r;
		end
	end
end

function x=expenv(t,att,decay)
	x=exp(-(0:t-1)/decay);
	x(1:att)=((0:att-1)/att).*x(1:att);
end