SinTracking.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00045
00046 typedef struct SGuide
00047 {
00048 TData freq;
00049 TData mag;
00050 int trackId;
00051 bool isDead;
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
00084 const ProcessingConfig &GetConfig() const { return mConfig;};
00085
00086
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
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;
00171
00172 bool mLastHarmonic;
00173
00174 };
00175
00176 };
00177
00178 #endif
00179