[b]Implementation of an ADSR envelope, help needed! [/b]
[b]Implementation of an ADSR envelope, help needed! [/b]
(OP)
Guys,
I'm trying to implement an ADSR envelope to a piano note that I have synthesised. I basically just want to apply the envelope to the final signal 'y'.
Anyone done this before or have and code/ideas on how to get it to work?
Thanks in advance!
I'm trying to implement an ADSR envelope to a piano note that I have synthesised. I basically just want to apply the envelope to the final signal 'y'.
Anyone done this before or have and code/ideas on how to get it to work?
Thanks in advance!





RE: [b]Implementation of an ADSR envelope, help needed! [/b]
RE: [b]Implementation of an ADSR envelope, help needed! [/b]
OK, that could sound odd as there are some weird phase effects.
Still, i haven't found any suggestion that it is more complex than I have suggested.
Here's a hint or two:
http
Cheers
Greg Locock
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
RE: [b]Implementation of an ADSR envelope, help needed! [/b]
close all; clear all;
rate=20000;
duration=4;
length=duration*rate;
t=linspace(0,duration,length);
A1=exp(-0.1*t)*1; A2=exp(-0.7*t)*0.907; A3=exp(-0.5*t)*0.366; A4=exp(-0.9*t)*0.159; A5=exp(-1.2*t)*0.194; A6=exp(-1.4*t)*0.169; A7=exp(-1.7*t)*0.176; A8=exp(-2*t)*0.101;
f1=261.2; f2=523.4; f3=785.0; f4=1047.7; f5=1312.45; f6=1577.1; f7=1843.85; f8=2111;
y=A1.*sin(2*pi*f1*t)+A2.*sin(2*pi*f2*t)+A3.*sin(2*pi*f3*t)+A4.*sin(2*pi*f4*t)+A5.*sin(2*pi*f5*t)+A6.*sin(2*pi*f6*t)+A7.*sin(2*pi*f7*t)+A8.*sin(2*pi*f8*t);
y=y/8;
sound(y,rate);
Now, I've found this ADSR envelope, but I don't understand how to apply it to my note.
function y = adsr(a, d, s, r, fs)
% ADSR An ADSR envelope generator.
% Y = ADSR(A,D,S,R,FS) generates a vector filled with envelope
% values as computed for the specified attack (A), decay (D),
% sustain (S), and release (R) times in seconds at the sample rate
% FS. The envelope attack reaches a value of 1 and then decays to a
% sustained value of 0.5, before decaying to 0.0
% Do attack portion
N = a * fs;
y = [0:N-1] / (N-1);
% Do decay portion
N = d * fs;
y = [y ([N-1:-1:0] / (2*N)) + 0.5];
% Do sustain portion
N = s * fs;
y = [y 0.5 * ones(1, N)];
% Do release portion
N = r * fs;
y = [y, 0.5 * [N-1:-1:0] / N];
Can anyone help me out?
RE: [b]Implementation of an ADSR envelope, help needed! [/b]
if so then you need to create an m file called adsr with that function in it.
Then tack on to your code
a=whatever;
d=whatever;
s=whatever;
r=whatever;
x = adsr(a, d, s, r, rate); 'creates a vector x with the envelope
'Then do an element by element multiplication of x and y
'I can't remember the posh way
for i:0;length-1
z(i)=x(i)*y(i);
end;
sound(z,rate);
Cheers
Greg Locock
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
RE: [b]Implementation of an ADSR envelope, help needed! [/b]
z=x.*y
assuming x and y are the same length
M
--
Dr Michael F Platten
RE: [b]Implementation of an ADSR envelope, help needed! [/b]
Everything's working as intended. Thanks for the help, it's actually quite easy when someone explains it to me...
Cheers!