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