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