1 // Copyright 2004 "Gilles Degottex" 2 3 // This file is part of "Music" 4 5 // "Music" is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation; either version 2.1 of the License, or 8 // (at your option) any later version. 9 // 10 // "Music" is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 20 #ifndef _MultiCumulativeDiffAlgo_h_ 21 #define _MultiCumulativeDiffAlgo_h_ 22 23 #include <vector> 24 #include <deque> 25 using namespace std; 26 #include "Algorithm.h" 27 #include "CumulativeDiff.h" 28 29 namespace Music 30 { 31 //! Compute error for each possible freqs with correlation algorithm 32 class MultiCumulativeDiffAlgo : public Transform 33 { 34 double m_test_complexity; 35 int m_first_fond; 36 vector<bool> m_is_fondamental; 37 38 protected: 39 void init(); AFreqChanged()40 virtual void AFreqChanged() {init();} samplingRateChanged()41 virtual void samplingRateChanged() {init();} semitoneBoundsChanged()42 virtual void semitoneBoundsChanged() {init();} 43 44 public: 45 //! correlation filters 46 vector< CumulativeDiff* > m_diffs; 47 48 bool is_minima(int ih); 49 50 public: 51 double m_pitch_tolerance; 52 setTestComplexity(double test_complexity)53 void setTestComplexity(double test_complexity) {m_test_complexity = test_complexity;} getTestComplexity()54 double getTestComplexity() {return m_test_complexity;} 55 getSampleAlgoLatency()56 virtual int getSampleAlgoLatency() const {return int((getAlgoLatency()/1000.0)*GetSamplingRate());} 57 //! in millis getAlgoLatency()58 virtual double getAlgoLatency() const {return 1000.0*(2*m_diffs[0]->m_s)/GetSamplingRate();} 59 60 //! unique ctor 61 /*! 62 * \param latency_factor latency factor for statistical purpose [1;oo[ 63 * \param test_complexity 64 */ 65 MultiCumulativeDiffAlgo(int latency_factor, double test_complexity); 66 67 //! overwrited computing function 68 virtual void apply(const deque<double>& buff); 69 70 virtual double getFondamentalWaveLength() const; 71 72 virtual ~MultiCumulativeDiffAlgo(); 73 }; 74 } 75 76 #endif 77