Daniel@0: function varargout = mirkeystrength(orig,varargin) Daniel@0: % ks = mirkeystrength(x) computes the key strength, i.e., the probability Daniel@0: % associated with each possible key candidate. Daniel@0: % Optional parameters: Daniel@0: % mirkeystrength(...,'Frame',l,h) orders a frame decomposition of window Daniel@0: % length l (in seconds) and hop factor h, expressed relatively to Daniel@0: % the window length. For instance h = 1 indicates no overlap. Daniel@0: % Default values: l = 1 seconds and h = .5 Daniel@0: % The mirchromagram options 'Weight' and 'Triangle' can be specified. Daniel@0: % [ks,c] = mirkeystrength(...) also displays the chromagram used for the key Daniel@0: % strength estimation. Daniel@0: % Daniel@0: % Krumhansl, Cognitive foundations of musical pitch. Oxford UP, 1990. Daniel@0: % Gomez, Tonal description of polyphonic audio for music content processing, Daniel@0: % INFORMS Journal on Computing, 18-3, pp. 294-304, 2006. Daniel@0: Daniel@0: wth.key = 'Weight'; Daniel@0: wth.type = 'Integer'; Daniel@0: wth.default = .5; Daniel@0: option.wth = wth; Daniel@0: Daniel@0: tri.key = 'Triangle'; Daniel@0: tri.type = 'Boolean'; Daniel@0: tri.default = 0; Daniel@0: option.tri = tri; Daniel@0: Daniel@0: specif.option = option; Daniel@0: specif.defaultframelength = .1; Daniel@0: specif.defaultframehop = .125; Daniel@0: Daniel@0: varargout = mirfunction(@mirkeystrength,orig,varargin,nargout,specif,@init,@main); Daniel@0: Daniel@0: Daniel@0: function [x type] = init(x,option) Daniel@0: if not(isamir(x,'mirchromagram')) Daniel@0: x = mirchromagram(x,'Weight',option.wth,'Triangle',option.tri,'Normal'); Daniel@0: else Daniel@0: x = mirchromagram(x,'Wrap','Normal'); Daniel@0: end Daniel@0: type = 'mirkeystrength'; Daniel@0: Daniel@0: Daniel@0: function k = main(orig,option,postoption) Daniel@0: if iscell(orig) Daniel@0: orig = orig{1}; Daniel@0: end Daniel@0: if isa(orig,'mirkeystrength') Daniel@0: c = []; Daniel@0: k = orig; Daniel@0: else Daniel@0: c = orig; Daniel@0: load gomezprofs; Daniel@0: m = get(c,'Magnitude'); Daniel@0: st = cell(1,length(m)); Daniel@0: kk = cell(1,length(m)); Daniel@0: %disp('Computing key strengths...') Daniel@0: for i = 1:length(m) Daniel@0: mi = m{i}; Daniel@0: if not(iscell(mi)) Daniel@0: mi = {mi}; Daniel@0: end Daniel@0: si = cell(1,length(mi)); Daniel@0: ki = cell(1,length(mi)); Daniel@0: for j = 1:length(mi) Daniel@0: mj = mi{j}; Daniel@0: sj = zeros(12,size(mj,2),size(mj,3),2); Daniel@0: for k = 1:size(mj,2) Daniel@0: for l = 1:size(mj,3) Daniel@0: tmp = corrcoef([mj(:,k,l) gomezprofs']); Daniel@0: sj(:,k,l,1) = tmp(1,2:13); Daniel@0: sj(:,k,l,2) = tmp(1,14:25); Daniel@0: kj(:,k,l) = {'C','C#','D','D#','E','F','F#','G','G#','A','A#','B'}; Daniel@0: end Daniel@0: end Daniel@0: si{j} = sj; Daniel@0: ki{j} = kj; Daniel@0: end Daniel@0: st{i} = si; Daniel@0: kk{i} = ki; Daniel@0: end Daniel@0: k = class(struct,'mirkeystrength',mirdata(c)); Daniel@0: k = purgedata(k); Daniel@0: k = set(k,'Title','Key strength','Abs','tonal center','Ord','strength',... Daniel@0: 'Tonic',kk,'Strength',st,'MultiData',{'maj','min'},'Interpolable',0); Daniel@0: end Daniel@0: k = {k c};