matthiasm@8: function [chromaframes, info] = hpcp2chroma(hpcpframes, info) matthiasm@8: matthiasm@8: % calculate the best shift matthiasm@8: % (0 - none, 1 - one third of semitone down, matthiasm@8: % 2 - two thirds of semitone down) matthiasm@8: matthiasm@8: bps = info.binsperoctave/12; matthiasm@8: matthiasm@8: indices = (0:11) * bps; matthiasm@8: matthiasm@8: matthiasm@8: %%%%% NANs! $%%%%%%%%%%%% matthiasm@8: % nanrows = isnan(sum(hpcpframes,2)); matthiasm@8: % binweights = sum(hpcpframes(~nanrows,:)); matthiasm@8: % condensedweights = zeros(bps,12); matthiasm@8: % for iBin = 1:bps matthiasm@8: % condensedweights(iBin,1:12) = sum(binweights(indices+iBin)); matthiasm@8: % end matthiasm@8: % % [maximum, maxind] = max(... matthiasm@8: % % [sum(binweights(indices+1)),... matthiasm@8: % % sum(binweights(indices+2)),... matthiasm@8: % % sum(binweights(indices+3))]); matthiasm@8: % [maximum, maxind] = max(sum(condensedweights,2)); matthiasm@8: % shiftposs = [1 0 -1]; matthiasm@8: % shift = shiftposs(maxind); matthiasm@8: % if bps ==3 matthiasm@8: % hpcpframes = circshift(hpcpframes',shift)'; matthiasm@8: % info.tuning6th = shift; matthiasm@8: % end matthiasm@8: maxind = 1; matthiasm@8: matthiasm@8: % fprintf(1,['(max. energy at ' num2str(maxind) ', shift by ' num2str(shift) ')\n\n']) matthiasm@8: if (~info.maxx) matthiasm@8: if bps == 3 matthiasm@8: chromaframes = ... matthiasm@8: 0 * hpcpframes(:,indices+1) + ... matthiasm@8: 1 * hpcpframes(:,indices+2) + ... matthiasm@8: 0 * hpcpframes(:,indices+3); matthiasm@8: elseif bps == 2 matthiasm@8: chromaframes = ... matthiasm@8: (1-shift)* hpcpframes(:,indices+1) + ... matthiasm@8: shift* hpcpframes(:,indices+2); matthiasm@8: elseif bps == 1 matthiasm@8: chromaframes = hpcpframes; matthiasm@8: end matthiasm@8: else matthiasm@8: chromaframes = zeros(size(hpcpframes,1),12); matthiasm@8: for iChroma = 1:12 matthiasm@8: chromaframes(:,iChroma) = max(hpcpframes(:,indices(iChroma)+(1:3)),[],2); matthiasm@8: end matthiasm@8: end matthiasm@8: matthiasm@8: chromaframes = chromaframes ./ repmat(sum(chromaframes,2),1,12);