Hi! I've started working on chord segmentation - starting offline in ChordExtractor. The first step, suggested by David: separating the code responsible for segmentation, so that it is all in a separate class.
In short: Changelog: * Most of the segmentation code in ChordExtractor is now in a seperate class called ChordExtractorSegmentation This patch is a "blind man's approach" to the problem - the simplest first patch I could think of... I just took the biggest chunk of code responsible for segmentation, put it into the doIt of a new class and added the constructor. Then I added some other code to doIt, so that every variable necessary for the copy/pasted chunk to work has the same value as it had in the previous code (basically copy/pasting some other lines from the code, without changing them)... then I struglled with the "which variable needs to be a reference, which a pointer"-mess... ;) And then finally I started getting identical results from the old ChordExtractor and the new "improved and much more messy" one. TODO: * Clean up! There is some repetitive code now, probably completely unnecessary (also - the old code isn't deleted, it's just commented out for now). I decided to post the patch without the cleanup, so that, if I'm doing something really fundamentaly wrong, someone can notice now :) * Quite a few variables are now passed to the constructor, probably completely unnecessary (like _lastChord), this needs to change * there is also some code in the destructor of ChordExtractorDescriptionDumper, this needs to go into the new class * lots more :) cheers, roman
Index: Annotator/src/ChordExtractor/MainClam.cxx =================================================================== --- Annotator/src/ChordExtractor/MainClam.cxx (revision 10447) +++ Annotator/src/ChordExtractor/MainClam.cxx (working copy) @@ -126,6 +126,53 @@ "</DescriptionScheme>\n" ; +class ChordExtractorSegmentation +{ + const Simac::ChordExtractor & extractor; + CLAM::DescriptionDataPool * _pool; + std::string & _lastChord; + CLAM::DataArray * _chordSegmentation; + CLAM::TData _currentTime; +public: + ChordExtractorSegmentation(CLAM::DescriptionDataPool * pool, std::string & lastChord, CLAM::DataArray * chordSegmentation, CLAM::TData & currentTime, const Simac::ChordExtractor & extractor) + : extractor(extractor) + , _pool(pool) + , _lastChord(lastChord) + , _chordSegmentation(chordSegmentation) + , _currentTime(currentTime) + { + } + ~ChordExtractorSegmentation() {}; + + void doIt() + { + const std::vector<double> & correlation = extractor.chordCorrelation(); //pointer to correlation data + + CLAM::TData firstCandidateWeight = correlation[extractor.firstCandidate()]; + CLAM::TData secondCandidateWeight = correlation[extractor.secondCandidate()]; + CLAM::TData noCandidateWeigth = correlation[0]; + + std::string currentChord = firstCandidateWeight*0.6<=noCandidateWeigth || noCandidateWeigth<0.001 ? + "None": + extractor.chordRepresentation(extractor.firstCandidate()); + + if (currentChord!=_lastChord) + { + if (_lastChord != "None") + _chordSegmentation[0].AddElem(_currentTime); + if (currentChord != "None") + { + unsigned newSegment = _pool->GetNumberOfContexts("ExtractedChord"); + _chordSegmentation[0].AddElem(_currentTime); + _pool->Insert("ExtractedChord", newSegment); + _pool->GetWritePool<Simac::Enumerated>("ExtractedChord","Root")[newSegment]= extractor.root(extractor.firstCandidate()); + _pool->GetWritePool<Simac::Enumerated>("ExtractedChord","Mode")[newSegment]= extractor.mode(extractor.firstCandidate()); + } + _lastChord = currentChord; + } + } +}; + class ChordExtractorDescriptionDumper { const Simac::ChordExtractor & extractor; @@ -250,7 +297,11 @@ CLAM::TData currentTime = (_currentFrame*_hop+_firstFrameOffset)/_samplingRate; // _debugFrameSegmentation[0].AddElem(currentTime); - if (currentChord!=_lastChord) + + ChordExtractorSegmentation segmentation(_pool, _lastChord, _chordSegmentation, currentTime, extractor); + segmentation.doIt(); + + /*if (currentChord!=_lastChord) { if (_lastChord != "None") _chordSegmentation[0].AddElem(currentTime); @@ -263,7 +314,7 @@ _pool->GetWritePool<Simac::Enumerated>("ExtractedChord","Mode")[newSegment]= extractor.mode(extractor.firstCandidate()); } _lastChord = currentChord; - } + }*/ _currentFrame++; } };
_______________________________________________ Clam-devel mailing list Clam-devel@llistes.projectes.lafarga.org https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel