22 #ifndef ChordSegmentator_hxx
23 #define ChordSegmentator_hxx
47 std::vector<unsigned> _chordIndexes;
49 unsigned _currentSegment;
56 std::vector< std::vector<double> > _chordSimilarity;
57 std::vector<double> _segmentChordCorrelation;
58 unsigned _framesInSegment;
71 void doIt(
CLAM::TData & currentTime,
const std::vector<double> & correlation,
const unsigned firstCandidate,
const unsigned secondCandidate)
77 doItSimilarity(currentTime, correlation, firstCandidate, secondCandidate);
80 doItSimple(currentTime, correlation, firstCandidate, secondCandidate);
87 void doItSimple(
CLAM::TData & currentTime,
const std::vector<double> & correlation,
const unsigned firstCandidate,
const unsigned secondCandidate)
89 CLAM::TData firstCandidateWeight = correlation[firstCandidate];
92 unsigned currentChord = firstCandidateWeight*0.6<=noCandidateWeight || noCandidateWeight<0.001 ?
99 if(currentChord != _lastChord)
108 _lastChord = currentChord;
111 _segmentation.
dragOffset(_currentSegment, currentTime);
117 void doItSimilarity(
CLAM::TData & currentTime,
const std::vector<double> & correlation,
const unsigned firstCandidate,
const unsigned secondCandidate)
119 CLAM::TData firstCandidateWeight = correlation[firstCandidate];
122 unsigned currentChord = firstCandidateWeight*0.6<=noCandidateWeight || noCandidateWeight<0.001 ?
125 unsigned segmentChord=0;
129 for(
unsigned i=0; i<correlation.size(); i++)
130 _segmentChordCorrelation[i] += correlation[i]/correlation[0];
133 _chordIndexes[_currentSegment] = segmentChord;
135 double segmentCorrelationDiffNew = (_segmentChordCorrelation[segmentChord] - _segmentChordCorrelation[currentChord]) / _framesInSegment;
137 double similarity = _chordSimilarity[currentChord][segmentChord];
139 double similarityThreshold = 0.67;
140 double correlationThreshold = 0.3;
145 _framesInSegment = 0;
146 for(
unsigned i=0; i<correlation.size(); i++)
147 _segmentChordCorrelation[i] = 0;
150 if (similarity < similarityThreshold)
152 if(segmentCorrelationDiffNew > correlationThreshold)
155 _framesInSegment = 0;
156 for(
unsigned i=0; i<correlation.size(); i++)
157 _segmentChordCorrelation[i] = 0;
162 if(!_segmentOpen && currentChord)
165 for(
unsigned i=0; i<correlation.size(); i++)
166 _segmentChordCorrelation[i] = correlation[i]/correlation[0];
168 segmentChord=currentChord;
172 _segmentation.
dragOffset(_currentSegment, currentTime);
177 _chordIndexes.push_back(currentChord);
178 _currentSegment = _segmentation.
insert(currentTime);
183 _segmentation.
dragOffset(_currentSegment, currentTime);
184 _segmentOpen =
false;
201 double minSegmentLength = 0.5;
203 std::vector<double> onsets = _segmentation.
onsets();
204 std::vector<double> offsets = _segmentation.
offsets();
205 unsigned lastSegment = onsets.size();
206 CLAM_ASSERT(segment<lastSegment,
"changeChordIfSegmentTooSmall: Accessing a segment beyond lastSegment");
208 if(offsets[segment]-onsets[segment] < minSegmentLength)
210 if(segment<lastSegment)
211 if(offsets[segment]==onsets[segment+1])
212 _chordIndexes[segment] = _chordIndexes[segment+1];
214 if(onsets[segment]==offsets[segment-1])
215 _chordIndexes[segment] = _chordIndexes[segment-1];
223 if(_chordIndexes[segment] == _chordIndexes[segment-1]
224 && _segmentation.
onsets()[segment] == _segmentation.
offsets()[segment-1])
226 _segmentation.
remove(segment);
227 _chordIndexes.erase(_chordIndexes.begin()+segment);
240 _segmentation.
dragOffset(_currentSegment, currentTime);
241 _segmentOpen =
false;
255 while( _segmentation.
onsets().size() )
258 _chordIndexes.pop_back();
265 double maxCorrelation = 0;
266 double underMaxCorrelation = 0;
267 unsigned maxIndex = 0;
268 unsigned underMaxIndex = 0;
269 for (
unsigned i=0; i<correlation.size(); i++)
271 if (correlation[i]<underMaxCorrelation)
continue;
272 if (correlation[i]<maxCorrelation)
275 underMaxCorrelation=correlation[i];
278 underMaxIndex=maxIndex;
279 underMaxCorrelation=maxCorrelation;
281 maxCorrelation=correlation[i];
283 estimatedChord = maxIndex;
297 for(
unsigned segment=0; segment<_segmentation.
onsets().size(); segment++)
302 for(
unsigned segment=1; segment<_segmentation.
onsets().size(); segment++)
307 const std::vector<unsigned> &
chordIndexes()
const {
return _chordIndexes; };
311 if(method != 0 && method != 1 && method != 2)
319 for(
unsigned i=0; i<101; ++i)
320 _segmentChordCorrelation.push_back(0);
326 #endif//ChordSegmentator