CLAM-Development
1.1
|
00001 /* 00002 * Copyright (c) 2001-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 _FundFreqDetect__ 00023 #define _FundFreqDetect__ 00024 #include <typeinfo> 00025 00026 #include "DataTypes.hxx" 00027 #include "Processing.hxx" 00028 #include "Array.hxx" 00029 #include "FundFreqDetectConfig.hxx" 00030 #include "InPort.hxx" 00031 #include "OutPort.hxx" 00032 #include "OutControl.hxx" 00033 #include "Array.hxx" 00034 00035 namespace CLAM { 00036 00037 class Storage; 00038 class ProcessingConfig; 00039 class Fundamental; 00040 class SpectralPeakArray; 00041 class IndexArray; 00042 00053 class FundFreqDetect: public Processing { 00054 mutable FundFreqDetectConfig mConfig; 00055 00056 const char *GetClassName() const {return "FundFreqDetect";} 00057 00058 bool ConcreteConfigure(const ProcessingConfig&); 00059 00060 InPort<SpectralPeakArray> mInput; 00061 OutPort<Fundamental> mOutput; 00062 OutControl mFundFreqValue; 00063 00064 public: 00065 FundFreqDetect(); 00066 00067 FundFreqDetect(const FundFreqDetectConfig &c); 00068 00069 ~FundFreqDetect(); 00070 00071 const ProcessingConfig &GetConfig() const; 00072 00073 bool Do(void); 00074 00076 bool Do(SpectralPeakArray& input,Fundamental& fund); 00077 private: 00078 00079 inline TData WeightCandidate(TData freq, const SpectralPeakArray&, const DataArray& magFactor, const DataArray& magFactor34q, 00080 const DataArray& magFactor4r,int maxNMP, int maxNPM) const; 00081 inline int GetClosestPeak(TData freq, int firstPeak, const IndexArray & peakIndexes, const DataArray & peakFrequencies) const; 00082 inline TData GetClosestHarmonic(TData peak, TData fundfreq, TData oneOverFundFreq) const; 00083 inline bool IsGoodCandidate(TData freq) const; 00084 00086 TData mnMaxCandidates; 00088 TData mReferenceFundFreq; 00089 TData mLowestFundFreq; 00090 TData mHighestFundFreq; 00091 00093 TData mMaxCandMagDiff; 00094 00096 TData mMaxFundFreqError; 00098 TSize mnInt; 00099 00102 TData mPMp, mPMq, mPMr, mMPp, mMPq, mMPr; // default values :0.5, 1.4, 0.5, 0.5, 1.4, 0.5 00103 TSize mPMnPeaks, mMPnPeaks; // Harmonic peaks to weight error, 10 by default 00104 TData mPMCont, mMPCont; // Harmonic error contributions. Default: 1, 1 00105 }; 00106 00107 } // namespace CLAM 00108 00109 #endif // _FUNFREQ_DETECT_ 00110