wolffd@0: function varargout = mirtonalcentroid(orig,varargin) wolffd@0: % c = mirtonalcentroid(x) calculates the 6-dimensional tonal centroid wolffd@0: % vector from the chromagram. wolffd@0: % It corresponds to a projection of the chords along circles of fifths, wolffd@0: % of minor thirds, and of major thirds. wolffd@0: % [c ch] = mirtonalcentroid(x) also returns the intermediate chromagram. wolffd@0: % wolffd@0: % C. A. Harte and M. B. Sandler, Detecting harmonic change in musical wolffd@0: % audio, in Proceedings of Audio and Music Computing for Multimedia wolffd@0: % Workshop, Santa Barbara, CA, 2006. wolffd@0: wolffd@0: frame.key = 'Frame'; wolffd@0: frame.type = 'Integer'; wolffd@0: frame.number = 2; wolffd@0: frame.default = [0 0]; wolffd@0: frame.keydefault = [.743 .1]; wolffd@0: option.frame = frame; wolffd@0: wolffd@0: specif.option = option; wolffd@0: wolffd@0: varargout = mirfunction(@mirtonalcentroid,orig,varargin,nargout,specif,@init,@main); wolffd@0: wolffd@0: wolffd@0: function [c type] = init(orig,option) wolffd@0: if option.frame.length.val wolffd@0: c = mirchromagram(orig,'Frame',option.frame.length.val,... wolffd@0: option.frame.length.unit,... wolffd@0: option.frame.hop.val,... wolffd@0: option.frame.hop.unit); wolffd@0: else wolffd@0: c = mirchromagram(orig); wolffd@0: end wolffd@0: type = 'mirtonalcentroid'; wolffd@0: wolffd@0: wolffd@0: function tc = main(ch,option,postoption) wolffd@0: if iscell(ch) wolffd@0: ch = ch{1}; wolffd@0: end wolffd@0: if isa(ch,'mirtonalcentroid') wolffd@0: tc = orig; wolffd@0: ch = []; wolffd@0: else wolffd@0: x1 = sin(pi*7*(0:11)/6)'; wolffd@0: y1 = cos(pi*7*(0:11)/6)'; wolffd@0: % minor thirds circle wolffd@0: x2 = sin(pi*3*(0:11)/2)'; wolffd@0: y2 = cos(pi*3*(0:11)/2)'; wolffd@0: % major thirds circle wolffd@0: x3 = 0.5 * sin(pi*2*(0:11)/3)'; wolffd@0: y3 = 0.5 * cos(pi*2*(0:11)/3)'; wolffd@0: c = [x1 y1 x2 y2 x3 y3]; wolffd@0: c = c'; wolffd@0: tc = class(struct,'mirtonalcentroid',mirdata(ch)); wolffd@0: tc = purgedata(tc); wolffd@0: tc = set(tc,'Title','Tonal centroid','Abs','dimensions','Ord','position'); wolffd@0: m = get(ch,'Magnitude'); wolffd@0: %disp('Computing tonal centroid...') wolffd@0: n = cell(1,length(m)); % The final structured list of magnitudes. wolffd@0: d = cell(1,length(m)); % The final structured list of centroid dimensions. wolffd@0: for i = 1:length(m) wolffd@0: mi = m{i}; wolffd@0: if not(iscell(mi)) wolffd@0: mi = {mi}; wolffd@0: end wolffd@0: ni = cell(1,length(mi)); % The list of magnitudes. wolffd@0: di = cell(1,length(mi)); % The list of centroid dimensions. wolffd@0: for j = 1:length(mi) wolffd@0: mj = mi{j}; wolffd@0: ni{j} = zeros(6,size(mj,2),size(mi,3)); wolffd@0: for k = 1:size(mj,3) wolffd@0: ni{j}(:,:,k) = c * mj(:,:,k); wolffd@0: end wolffd@0: di{j} = repmat((1:6)',[1,size(mj,2),size(mi,3)]); wolffd@0: end wolffd@0: n{i} = ni; wolffd@0: d{i} = di; wolffd@0: end wolffd@0: tc = set(tc,'Positions',n,'Dimensions',d); wolffd@0: end wolffd@0: tc = {tc,ch};