comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirkeystrength/mirkeystrength.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function varargout = mirkeystrength(orig,varargin)
2 % ks = mirkeystrength(x) computes the key strength, i.e., the probability
3 % associated with each possible key candidate.
4 % Optional parameters:
5 % mirkeystrength(...,'Frame',l,h) orders a frame decomposition of window
6 % length l (in seconds) and hop factor h, expressed relatively to
7 % the window length. For instance h = 1 indicates no overlap.
8 % Default values: l = 1 seconds and h = .5
9 % The mirchromagram options 'Weight' and 'Triangle' can be specified.
10 % [ks,c] = mirkeystrength(...) also displays the chromagram used for the key
11 % strength estimation.
12 %
13 % Krumhansl, Cognitive foundations of musical pitch. Oxford UP, 1990.
14 % Gomez, Tonal description of polyphonic audio for music content processing,
15 % INFORMS Journal on Computing, 18-3, pp. 294-304, 2006.
16
17 wth.key = 'Weight';
18 wth.type = 'Integer';
19 wth.default = .5;
20 option.wth = wth;
21
22 tri.key = 'Triangle';
23 tri.type = 'Boolean';
24 tri.default = 0;
25 option.tri = tri;
26
27 specif.option = option;
28 specif.defaultframelength = .1;
29 specif.defaultframehop = .125;
30
31 varargout = mirfunction(@mirkeystrength,orig,varargin,nargout,specif,@init,@main);
32
33
34 function [x type] = init(x,option)
35 if not(isamir(x,'mirchromagram'))
36 x = mirchromagram(x,'Weight',option.wth,'Triangle',option.tri,'Normal');
37 else
38 x = mirchromagram(x,'Wrap','Normal');
39 end
40 type = 'mirkeystrength';
41
42
43 function k = main(orig,option,postoption)
44 if iscell(orig)
45 orig = orig{1};
46 end
47 if isa(orig,'mirkeystrength')
48 c = [];
49 k = orig;
50 else
51 c = orig;
52 load gomezprofs;
53 m = get(c,'Magnitude');
54 st = cell(1,length(m));
55 kk = cell(1,length(m));
56 %disp('Computing key strengths...')
57 for i = 1:length(m)
58 mi = m{i};
59 if not(iscell(mi))
60 mi = {mi};
61 end
62 si = cell(1,length(mi));
63 ki = cell(1,length(mi));
64 for j = 1:length(mi)
65 mj = mi{j};
66 sj = zeros(12,size(mj,2),size(mj,3),2);
67 for k = 1:size(mj,2)
68 for l = 1:size(mj,3)
69 tmp = corrcoef([mj(:,k,l) gomezprofs']);
70 sj(:,k,l,1) = tmp(1,2:13);
71 sj(:,k,l,2) = tmp(1,14:25);
72 kj(:,k,l) = {'C','C#','D','D#','E','F','F#','G','G#','A','A#','B'};
73 end
74 end
75 si{j} = sj;
76 ki{j} = kj;
77 end
78 st{i} = si;
79 kk{i} = ki;
80 end
81 k = class(struct,'mirkeystrength',mirdata(c));
82 k = purgedata(k);
83 k = set(k,'Title','Key strength','Abs','tonal center','Ord','strength',...
84 'Tonic',kk,'Strength',st,'MultiData',{'maj','min'},'Interpolable',0);
85 end
86 k = {k c};