0001 function [distVec, minIndexVec, scoreVec] = melodyCompare(songDb, pitch, mrParam)
0002
0003
0004
0005
0006
0007
0008
0009
0010 pitch=pitch(:)';
0011 pitch=restHandle(pitch, mrParam.useRest);
0012 pitch=pitch-mean(pitch);
0013 pitchLen = length(pitch);
0014 maxSongLen = round(mrParam.lengthRatio*pitchLen);
0015 pitch=pitch(1:mrParam.pvrr:end);
0016 songNum=length(songDb);
0017 distVec=zeros(1, songNum);
0018 minIndexVec=zeros(1, songNum);
0019
0020 switch mrParam.method
0021 case 'dtw1'
0022 for i=1:length(songDb),
0023
0024 song=songDb(i).pv;
0025
0026 song=song(1:min(maxSongLen, length(song)));
0027 songLen = length(song);
0028
0029 songMean=mean(song(1:min(pitchLen, songLen)));
0030 song=song-songMean;
0031
0032 song=song(1:mrParam.pvrr:end);
0033
0034 beginCorner=mrParam.beginCorner;
0035 endCorner=mrParam.endCorner;
0036
0037 distVec(i)=dtw4mr(pitch, song, mrParam);
0038
0039
0040 end
0041 case 'dtw2'
0042 for i=1:length(songDb),
0043
0044 song=songDb(i).pv;
0045
0046 song=song(1:min(maxSongLen, length(song)));
0047 songLen = length(song);
0048
0049 songMean=mean(song(1:min(pitchLen, songLen)));
0050 song=song-songMean;
0051
0052 song=song(1:mrParam.pvrr:end);
0053
0054 beginCorner=mrParam.beginCorner;
0055 endCorner=mrParam.endCorner;
0056
0057 distVec(i) = dtw2mex(pitch, song, beginCorner, endCorner);
0058 end
0059 case 'dtw1fixedPoint'
0060 for i=1:length(songDb),
0061
0062 song=songDb(i).pv;
0063
0064 song=song(1:min(maxSongLen, length(song)));
0065 song=song(1:mrParam.pvrr:end);
0066
0067 param.dtwFunc='dtw1mex';
0068 param.anchorBeginning=mrParam.beginCorner;
0069 param.anchorEnd=mrParam.endCorner;
0070 param.maxIterationNum=mrParam.dtwCount;
0071 [minDist, allDist, allPitchShift]=dtwFixedPoint(pitch, song, param);
0072 distVec(i)=minDist;
0073 end
0074 case 'dtw2fixedPoint'
0075 for i=1:length(songDb),
0076
0077 song=songDb(i).pv;
0078
0079 song=song(1:min(maxSongLen, length(song)));
0080 song=song(1:mrParam.pvrr:end);
0081
0082 param.dtwFunc='dtw2mex';
0083 param.anchorBeginning=mrParam.beginCorner;
0084 param.anchorEnd=mrParam.endCorner;
0085 param.maxIterationNum=mrParam.dtwCount;
0086 [minDist, allDist, allPitchShift]=dtwFixedPoint(pitch, song, param);
0087 distVec(i)=minDist;
0088 end
0089 case 'ls'
0090
0091 lowerRatio=mrParam.lowerRatio;
0092 upperRatio=mrParam.upperRatio;
0093 resolution=mrParam.resolution;
0094 [scaledVecSet, scaledVecLen]=vecLinScaling(pitch, lowerRatio, upperRatio, resolution);
0095 for i=1:length(songDb)
0096
0097 anchorNum=length(songDb(i).anchorPvIndex);
0098 distVecInSong=zeros(anchorNum, 1);
0099 minIndexInSong=zeros(anchorNum, 1);
0100 for j=1:anchorNum
0101
0102
0103 song=songDb(i).pv(songDb(i).anchorPvIndex(j):end);
0104
0105 song=song(1:min(maxSongLen, length(song)));
0106 songLen = length(song);
0107
0108 song=song(1:mrParam.pvrr:end);
0109
0110
0111
0112 [distVecInSong(j), minIndexInSong(j)]=linScaling2Mex(scaledVecSet, scaledVecLen, song, mrParam.lsDistanceType);
0113 end
0114 [distVec(i), minIndex]=min(distVecInSong);
0115 minIndexVec(i)=minIndexInSong(minIndex);
0116 end
0117 case 'noteLevelDtw2'
0118 for i=1:length(songDb),
0119
0120
0121 song=songDb(i).pv;
0122 songLen = length(song);
0123 songMean=mean(song(1:min(pitchLen, songLen)));
0124 songNote=songDb(i).track(1:2:end)';
0125 songNote=songNote-songMean;
0126
0127 pitchTh=0.8;
0128 minNoteDuration=0.1;
0129 userNote = noteSegment(pitch, mrParam.timeStep, pitchTh, minNoteDuration);
0130
0131 userNote=userNote(1:2:end);
0132 beginCorner=mrParam.beginCorner;
0133 endCorner=mrParam.endCorner;
0134 distVec(i) = dtw2mex(userNote, songNote, beginCorner, endCorner);
0135 end
0136 case 'dtw3'
0137 for i=1:length(songDb),
0138
0139
0140 song=songDb(i).pv;
0141 songLen = length(song);
0142 songMean=mean(song(1:min(pitchLen, songLen)));
0143 songNote=songDb(i).track(1:2:end)';
0144 songNote=songNote-songMean;
0145
0146 song=song(1:mrParam.pvrr:end);
0147
0148 beginCorner=mrParam.beginCorner;
0149 endCorner=mrParam.endCorner;
0150
0151 distVec(i) = dtw3mex(pitch, songNote, beginCorner, endCorner);
0152 end
0153 otherwise
0154 error('Unknown method!');
0155 end
0156
0157
0158 a=1.60;
0159 b=6.37;
0160 scoreVec=100./(1+(distVec/a).^(2*b));