SinTracking.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #ifndef _SinTracking__
00023 #define _SinTracking__
00024 #include <typeinfo>
00025 
00026 #include "DataTypes.hxx"
00027 #include "Processing.hxx"
00028 #include "SpectralPeakArray.hxx"
00029 #include "Array.hxx"
00030 #include "SinTrackingConfig.hxx"
00031 #include "InPort.hxx"
00032 #include "OutPort.hxx"
00033 #include "InControl.hxx"
00034 
00035 namespace CLAM {
00036 
00037         class Fundamental;      
00038         class SpectralPeak;
00039         class ProcessingConfig;
00040         
00044         /* SinTrackingConfig moved to SinTrackingConfig.hxx */
00045 
00046         typedef struct SGuide
00047         {
00048                 TData freq;
00049                 TData mag;
00050                 int trackId;
00051                 bool isDead;//true if track died in previous step, false else
00052         }TGuide;
00053 
00054 
00062         class SinTracking: public Processing
00063         {
00064                 mutable SinTrackingConfig mConfig;
00065 
00066                 const char *GetClassName() const {return "SinTracking";} 
00067 
00071                 virtual bool ConcreteConfigure(const ProcessingConfig&);
00072 
00073                 InPort<SpectralPeakArray> mInput;
00074                 OutPort<SpectralPeakArray> mOutput;
00075                 FloatInControl mFundFreqValue;
00076 
00077         public:
00078 
00079                 SinTracking();
00080                 SinTracking(const SinTrackingConfig &c);
00081                 ~SinTracking();
00082 
00083                 //Configuration accessor
00084                 const ProcessingConfig &GetConfig() const { return mConfig;};           
00085 
00086                 //Peak Continuation for one frame
00087                 bool Do(const SpectralPeakArray& iPeakArray, SpectralPeakArray& oPeakArray);
00088                 bool Do(void);
00089 
00090                 int GetnTracks() const {return mNextTrackId;};
00091 
00092         private:
00093 
00094                 bool DoHarmonic(const SpectralPeakArray& in, SpectralPeakArray& out,TData funFreq);
00095                 bool DoInharmonic(const SpectralPeakArray& in, SpectralPeakArray& out);
00096         
00097 
00099                 void Initialization(const SpectralPeakArray& iPeakArray, SpectralPeakArray& oPeakArray);
00100 
00101                 void InitHarmonicTracks(SpectralPeakArray& peaks, TData funFreq);
00102 
00103                 
00106                 void AddNewTrack(int trackPosition, const SpectralPeak& currentPeak,SpectralPeakArray& oPeakArray) const;
00107                 
00109                 void Tracking(const SpectralPeakArray& iPeakArray, SpectralPeakArray& oPeakArray, TIndex processedPeakPos) const;
00110 
00111                 void HarmonicTracking(const SpectralPeakArray& in,SpectralPeakArray& out,TData funFreq);
00112 
00114                 inline bool IsPeakAssigned(const SpectralPeakArray &peakArray, TIndex peakIndex) const;
00115 
00117                 inline bool IsCandidate(const SpectralPeak& fixedPeak,const SpectralPeak& candidate) const;
00118 
00120                 inline bool ThereIsCandidate(TData currentFramePeakFreq, 
00121                         const SpectralPeakArray& iPeakArray,SpectralPeakArray& oPeakArray) const;
00122                 
00124                 inline TIndex GetCandidate(TData currentFramePeakFreq, 
00125                                                 const SpectralPeakArray& nextFramePeakArray,TData& distance) const;
00126   
00128                 inline bool IsBestCandidate(TData candidateFreq, TData currentFreq) const;
00129 
00130                   
00133                 inline TIndex GetFirstNonAssignedPeakPos(const SpectralPeakArray& framePeakArray, TIndex beginAt) const;
00134   
00136                 inline void Match(TIndex trackId, TIndex peakIndex,const SpectralPeak& currentPeak, SpectralPeakArray& oPeakArray) const;
00137   
00140                 inline void KillTrack(int trackPosition) const;
00141 
00142                 void KillAll();
00143   
00144                 
00145   
00148                 void CheckForNewBornTracks(const SpectralPeakArray& iPeakArray,
00149                                                 SpectralPeakArray& oPeakArray) const;
00150 
00153                 TIndex GetMatchedPeak(const SpectralPeakArray &iPeakArray, TIndex peakIndex) const;
00154   
00158                 TIndex GetFirstNonMatchedPeakPos(const SpectralPeakArray& iPeakArray, TIndex beginAt) const;
00159         
00160 
00161 
00162         //Member variables
00163                 TData mThreshold;
00164                 mutable bool mInitialized;
00165                 SpectralPeakArray mPreviousPeakArray;
00166                 mutable Array<TGuide> mGuideArray;
00167                 int mnMaxSines;
00168                 mutable int mnActiveGuides;             
00169                 mutable int mNextTrackId;
00170                 bool mHarmonic;//TODO: this should be a runtime modificable control
00171 
00172                 bool mLastHarmonic;
00173 
00174         };
00175 
00176 };//namespace
00177 
00178 #endif
00179 
Generated by  doxygen 1.6.3