-
Notifications
You must be signed in to change notification settings - Fork 0
/
duracao.m
59 lines (50 loc) · 1.36 KB
/
duracao.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function [musica,tempo] = duracao(pontos,notas,fs)
durs = zeros(1,length(pontos)-1);
for n = 1:length(durs)
durs(n)=pontos(n+1)-pontos(n);
end
dist=zeros(1,ceil(max(durs)/1000)*1000);
for n = 1:length(durs)
dist(durs(n))=dist(durs(n))+1;
end
N = 60;
histdist=histcounts(durs,0:ceil(length(dist)/N):length(dist));
[val,loc]=max(histdist);
loc = (loc-.5)*length(dist)/N;
quarter=avex2(dist(ceil(loc*7/8):min(length(dist),floor(loc*9/8))),ceil(loc*7/8));
num8=round(2*durs/quarter);
lengths = cell(length(durs),1);
for n = 1:length(durs)
switch(num8(n))
case 1
lengths(n) = cellstr('colcheia');
case 2
lengths(n) = cellstr('semiminima');
case 3
lengths(n) = cellstr('semiminima ponto');
case 4
lengths(n) = cellstr('minima');
case 6
lengths(n) = cellstr('minima ponto');
case 8
lengths(n) = cellstr('semibreve');
otherwise
lengths(n) = cellstr('sem medida');
end
end
tam=size(notas);
musica = cell(tam(1),tam(2)+1);
for r = 1:tam(1)
for c = 1:tam(2)
musica{r,c}=notas{r,c};
end
musica{r,end}=lengths{r};
end
tempo = 60*fs/quarter;
end
function x = avex2(f,comeco)
if (nargin < 2)
comeco = 1;
end
x = sum(([1:length(f)]+comeco-1).*f)/sum(f);
end