added matlab

This commit is contained in:
2025-08-21 07:27:52 +02:00
parent fd522e1b99
commit 64c6745c76
50 changed files with 2516 additions and 0 deletions
Vendored Executable
+53
View File
@@ -0,0 +1,53 @@
function eval_adsr(Ta, Td, Vs, Tr, ks)
% eval_adsr(0.1, 0.2, 0.2, 0.2)
fs = 1000;
a_a = -log(1-ks)/(Ta*fs);
a_d = 5/(Td*fs);
a_r = 5/(Tr*fs);
state = 0;
s = 0;
tol = 1E-4;
n = 1;
p = 0;
k = 1/ks;
while (1),
if state == 0 % Attack
s = a_a + (1-a_a)*s;
y(n) = k*s;
if s >= (ks-tol)
state = 1;
s = 1-ks;
end;
end;
if state == 1 % Decay
s = (1-a_d)*s;
y(n) = s/(1-ks);
if s <= (Vs+tol)
state = 2;
p = 0;
end;
end;
if state == 2 % sustain
y(n) = Vs;
if p >= 1*fs
state = 3;
s = Vs;
end;
p = p + 1;
end;
if state == 3 % Release
s = (1-a_r)*s;
y(n) = s;
if s <= (tol)
break;
end;
end;
n = n + 1;
end;
plot((0:n-1)/fs, y); grid;
set(gca,'xtick',[0:0.1:(n-1)/fs])
Vendored Executable
+52
View File
@@ -0,0 +1,52 @@
function eval_adsr(Ta, Td, Vs, Tr, ks)
% eval_adsr(0.1, 0.2, 0.2, 0.2)
fs = 1000;
a_a = -log(1-ks)/(Ta*fs);
a_d = 5/(Td*fs);
a_r = 5/(Tr*fs);
state = 0;
s = 0;
tol = 1E-4;
n = 1;
p = 0;
k = 1/ks;
while (1),
if state == 0 % Attack
s = a_a + (1-a_a)*s;
y(n) = s/ks;
if s >= (ks-tol)
state = 1;
end;
end;
if state == 1 % Decay
s = (1-a_d)*s;
y(n) = s/(ks);
if s <= (Vs*ks+tol)
state = 2;
p = 0;
end;
end;
if state == 2 % sustain
y(n) = Vs;
if p >= 1*fs
state = 3;
s = Vs;
end;
p = p + 1;
end;
if state == 3 % Release
s = (1-a_r)*s;
y(n) = s;
if s <= (tol)
break;
end;
end;
n = n + 1;
end;
plot((0:n-1)/fs, y); grid;
set(gca,'xtick',[0:0.1:(n-1)/fs])
Vendored Executable
+56
View File
@@ -0,0 +1,56 @@
function eval_adsr(Ta, Td, Vs, Tr)
% eval_adsr(0.1, 0.2, 0.2, 0.2)
fs = 10000;
aa = 1/(Ta*fs)
ba = (1-aa)
a_d = 5/(Td*fs)
a_r = 5/(Tr*fs)
state = 0;
s = 0;
tol = 1E-4;
ke = 1-exp(-1)
n = 0;
p = 0;
k = 1/ke;
kk = 0;
s
while (1),
if state == 0
s = aa + ba*s;
if s >= (ke-tol)
state = 1;
k = (1-Vs)/ke;
kk = Vs;
end;
end;
if state == 1
s = (1-a_d)*s;
if s <= (tol)
state = 2;
s = 1;
k = Vs;
kk = 0;
p = 0;
end;
end;
if state == 2
if p >= 0.1*fs
state = 3;
end;
p = p + 1;
end;
if state == 3
s = (1-a_r)*s;
if s <= (tol)
break;
end;
end;
n = n + 1;
y(n) = k*s + kk;
end;
plot((0:n-1)/fs, 0.8-y); grid;
Vendored Executable
+52
View File
@@ -0,0 +1,52 @@
function eval_adsr(Ta, Td, Vs, Tr)
% eval_adsr(0.1, 0.2, 0.2, 0.2)
fs = 1000;
a_a = 1/(Ta*fs);
a_d = -1/(Td*fs/log(Vs))
a_d = 5/(Td*fs)
a_r = 5/(Tr*fs)
state = 0;
s = 0;
tol = 1E-4;
target = 1;
n = 0;
p = 0;
k = 1/0.63;
while (1),
if state == 0 % Attack
s = a_a + (1-a_a)*s;
if s >= (0.63-tol)
state = 1
target = Vs;
end;
end;
if state == 1 % Decay
s = (1-a_d)*s;
if s <= (0.63*Vs+tol)
state = 2
target = 0;
p = 0;
end;
end;
if state == 2 % sustain
s = Vs/k;
if p >= 1*fs
state = 3
end;
p = p + 1;
end;
if state == 3 % Release
s = (1-a_r)*s;
if s <= (target+tol)
break;
end;
end;
n = n + 1;
y(n) = k*s;
end;
plot((0:n-1)/fs, y); grid;