function y=tempered_scales(p_from, base_note, r_what, how_many, type_of_array, octavies)
if not(exist('p_from','var')); p_from=12; end
if not(exist('how_many','var')); how_many=1; end
if not(exist('base_note','var')); base_note=440; end
if not(exist('r_what','var')); r_what='rows'; end
if not(exist('type_of_array','var')); type_of_array='array'; end
if not(exist('octavies','var')); octavies=1; end
if (p_from < 0) || (p_from > 1000);p_from = 1;end
if ((how_many < 1) || (how_many > 1000));how_many = 1;end
if (base_note <= 0) || (how_many > 100000); base_note = 440;end
if (not(strcmp(r_what,'rows')) && not(strcmp(r_what,'diff')) && not(strcmp(r_what,'ratio'))); r_what='rows';end
if (not(strcmp(type_of_array,'mat')) && not(strcmp(type_of_array,'cell'))); type_of_array='mat';end
a=cell(how_many,1);
v=a;
r=a;
an=ones(how_many*octavies,how_many);
an=an./0;
vn=an;
rn=an;
n= [1 1.25 1.5 1.75 2 2.25 2.5 2.75 3 3.25 3.5 3.75 4 4.25 4.5 4.75 5 5.25 5.5 5.75 6];
n=n.*base_note;
if (p_from > 0)
for i=p_from:(p_from + how_many - 1)
rows=i*octavies;
ax=ones(1,i);
vx=ax; rx=ax;
b=base_note;
s=2^(1/i);
rx(1,1)=1; rn(1,i - p_from +1)=1;
for j=1:rows
ax(1,j)=b; an(j,i-p_from + 1)=b;
b=b*s;
rx(1,j+1)=rx(1,j)*s;
rn(j+1,i - p_from +1)=rx(1,j)*s;
temp_v= abs(n(1)- b);
for k=1:5
temp_v2= abs(n(k)- b);
if temp_v <= temp_v2
if temp_v < 0.01
temp_v=inf; end
vx(1,j)= temp_v; vn(j,i-p_from + 1)= temp_v;
else
if temp_v2 < 0.01
temp_v2=inf;
end
vx(1,j)= temp_v2; vn(j,i-p_from + 1)= temp_v2;
if temp_v2 < abs(n(k+1)- b)
break
end
end
end
end
a(i - p_from +1,1)={ax};
v(i - p_from +1,1)={vx};
r(i - p_from +1,1)={rx};
end
elseif (p_from == 0)
r=[1 1.25 1.5 1.75 2];
a=r.*base_note;
v=[0 0 0 0 0];
an=a;
vn=v;
rn=r;
end
if strcmp(r_what,'rows')
if strcmp(type_of_array,'cell')
y=a;
elseif strcmp(type_of_array,'mat')
y=an;
end
elseif strcmp(r_what,'diff')
if strcmp(type_of_array,'cell')
y=v;
else
y=vn;
end
elseif strcmp(r_what,'ratio')
if strcmp(type_of_array,'cell')
y=r;
else
y=rn;
end
end