comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirtonalcentroid/mirtonalcentroid.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 = mirtonalcentroid(orig,varargin)
2 % c = mirtonalcentroid(x) calculates the 6-dimensional tonal centroid
3 % vector from the chromagram.
4 % It corresponds to a projection of the chords along circles of fifths,
5 % of minor thirds, and of major thirds.
6 % [c ch] = mirtonalcentroid(x) also returns the intermediate chromagram.
7 %
8 % C. A. Harte and M. B. Sandler, Detecting harmonic change in musical
9 % audio, in Proceedings of Audio and Music Computing for Multimedia
10 % Workshop, Santa Barbara, CA, 2006.
11
12 frame.key = 'Frame';
13 frame.type = 'Integer';
14 frame.number = 2;
15 frame.default = [0 0];
16 frame.keydefault = [.743 .1];
17 option.frame = frame;
18
19 specif.option = option;
20
21 varargout = mirfunction(@mirtonalcentroid,orig,varargin,nargout,specif,@init,@main);
22
23
24 function [c type] = init(orig,option)
25 if option.frame.length.val
26 c = mirchromagram(orig,'Frame',option.frame.length.val,...
27 option.frame.length.unit,...
28 option.frame.hop.val,...
29 option.frame.hop.unit);
30 else
31 c = mirchromagram(orig);
32 end
33 type = 'mirtonalcentroid';
34
35
36 function tc = main(ch,option,postoption)
37 if iscell(ch)
38 ch = ch{1};
39 end
40 if isa(ch,'mirtonalcentroid')
41 tc = orig;
42 ch = [];
43 else
44 x1 = sin(pi*7*(0:11)/6)';
45 y1 = cos(pi*7*(0:11)/6)';
46 % minor thirds circle
47 x2 = sin(pi*3*(0:11)/2)';
48 y2 = cos(pi*3*(0:11)/2)';
49 % major thirds circle
50 x3 = 0.5 * sin(pi*2*(0:11)/3)';
51 y3 = 0.5 * cos(pi*2*(0:11)/3)';
52 c = [x1 y1 x2 y2 x3 y3];
53 c = c';
54 tc = class(struct,'mirtonalcentroid',mirdata(ch));
55 tc = purgedata(tc);
56 tc = set(tc,'Title','Tonal centroid','Abs','dimensions','Ord','position');
57 m = get(ch,'Magnitude');
58 %disp('Computing tonal centroid...')
59 n = cell(1,length(m)); % The final structured list of magnitudes.
60 d = cell(1,length(m)); % The final structured list of centroid dimensions.
61 for i = 1:length(m)
62 mi = m{i};
63 if not(iscell(mi))
64 mi = {mi};
65 end
66 ni = cell(1,length(mi)); % The list of magnitudes.
67 di = cell(1,length(mi)); % The list of centroid dimensions.
68 for j = 1:length(mi)
69 mj = mi{j};
70 ni{j} = zeros(6,size(mj,2),size(mi,3));
71 for k = 1:size(mj,3)
72 ni{j}(:,:,k) = c * mj(:,:,k);
73 end
74 di{j} = repmat((1:6)',[1,size(mj,2),size(mi,3)]);
75 end
76 n{i} = ni;
77 d{i} = di;
78 end
79 tc = set(tc,'Positions',n,'Dimensions',d);
80 end
81 tc = {tc,ch};