CLAM-Development  1.4.0
FundFreqDetect.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef _FundFreqDetect__
23 #define _FundFreqDetect__
24 #include <typeinfo>
25 
26 #include "DataTypes.hxx"
27 #include "Processing.hxx"
28 #include "Array.hxx"
29 #include "FundFreqDetectConfig.hxx"
30 #include "InPort.hxx"
31 #include "OutPort.hxx"
32 #include "OutControl.hxx"
33 #include "Array.hxx"
34 
35 namespace CLAM {
36 
37  class Storage;
38  class ProcessingConfig;
39  class Fundamental;
40  class SpectralPeakArray;
41  class IndexArray;
42 
53  class FundFreqDetect: public Processing {
54  mutable FundFreqDetectConfig mConfig;
55 
56  const char *GetClassName() const {return "FundFreqDetect";}
57 
58  bool ConcreteConfigure(const ProcessingConfig&);
59 
61  OutPort<Fundamental> mOutput;
62  FloatOutControl mFundFreqValue;
63 
64  public:
66 
68 
70 
71  const ProcessingConfig &GetConfig() const;
72 
73  bool Do(void);
74 
76  bool Do(SpectralPeakArray& input,Fundamental& fund);
77  private:
78 
79  inline TData WeightCandidate(TData freq, const SpectralPeakArray&, const DataArray& magFactor, const DataArray& magFactor34q,
80  const DataArray& magFactor4r,int maxNMP, int maxNPM) const;
81  inline int GetClosestPeak(TData freq, int firstPeak, const IndexArray & peakIndexes, const DataArray & peakFrequencies) const;
82  inline TData GetClosestHarmonic(TData peak, TData fundfreq, TData oneOverFundFreq) const;
83  inline bool IsGoodCandidate(TData freq) const;
84 
86  TData mnMaxCandidates;
88  TData mReferenceFundFreq;
89  TData mLowestFundFreq;
90  TData mHighestFundFreq;
91 
93  TData mMaxCandMagDiff;
94 
96  TData mMaxFundFreqError;
98  TSize mnInt;
99 
102  TData mPMp, mPMq, mPMr, mMPp, mMPq, mMPr; // default values :0.5, 1.4, 0.5, 0.5, 1.4, 0.5
103  TSize mPMnPeaks, mMPnPeaks; // Harmonic peaks to weight error, 10 by default
104  TData mPMCont, mMPCont; // Harmonic error contributions. Default: 1, 1
105  };
106 
107 } // namespace CLAM
108 
109 #endif // _FUNFREQ_DETECT_
110