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 _Algorithm_h_ 21 #define _Algorithm_h_ 22 23 #include <list> 24 #include <vector> 25 #include <deque> 26 #include <iostream> 27 using namespace std; 28 #include "Music.h" 29 30 namespace Music 31 { 32 class Algorithm : public SettingsListener 33 { 34 static list<Algorithm*> s_algos; 35 36 protected: 37 double m_amplitude_treshold; 38 double m_max_amplitude; 39 samplingRateChanged()40 virtual void samplingRateChanged() {cout<<__FILE__<<":"<<__LINE__<<" Algorithm::samplingRateChanged Not Yet Implemented"<<endl;} AFreqChanged()41 virtual void AFreqChanged() {cout<<__FILE__<<":"<<__LINE__<<" Algorithm::AFreqChanged Not Yet Implemented"<<endl;} semitoneBoundsChanged()42 virtual void semitoneBoundsChanged() {cout<<__FILE__<<":"<<__LINE__<<" Algorithm::semitoneBoundsChanged Not Yet Implemented"<<endl;} 43 44 public: 45 Algorithm(); 46 getAmplitudeTreshold()47 inline double getAmplitudeTreshold() {return m_amplitude_treshold;} setAmplitudeTreshold(double t)48 inline void setAmplitudeTreshold(double t) {m_amplitude_treshold=t;} getMaxAmplitude()49 inline double getMaxAmplitude() {return m_max_amplitude;} 50 51 virtual int getSampleAlgoLatency() const =0; getAlgoLatency()52 virtual double getAlgoLatency() const {return double(getSampleAlgoLatency())/GetSamplingRate();} 53 54 virtual void apply(const deque<double>& buff)=0; 55 virtual bool hasNoteRecognized() const =0; getFundamentalWaveLength()56 virtual double getFundamentalWaveLength() const {return GetSamplingRate()/getFundamentalFreq();} getFundamentalFreq()57 virtual double getFundamentalFreq() const {return GetSamplingRate()/getFundamentalWaveLength();} getFundamentalNote()58 virtual double getFundamentalNote() const {return f2hf(getFundamentalFreq());} 59 virtual int getMinSize() const =0; 60 61 virtual ~Algorithm(); 62 }; 63 64 class Transform : public Algorithm 65 { 66 protected: 67 double m_component_treshold; 68 69 vector< complex<double> > m_harmonics; 70 vector<double> m_components; 71 double m_components_max; 72 73 public: getComponentTreshold()74 inline double getComponentTreshold() {return m_component_treshold;} setComponentTreshold(double t)75 inline void setComponentTreshold(double t) {m_component_treshold=t;} 76 77 Transform(); 78 size()79 size_t size() const {return m_components.size();} 80 getHarmonics()81 const vector< complex<double> >& getHarmonics() {return m_harmonics;} getComponents()82 const vector<double>& getComponents() {return m_components;} getComponentsMax()83 double getComponentsMax() {return m_components_max;} 84 ~Transform()85 virtual ~Transform(){} 86 }; 87 } 88 89 #endif // _Algorithms_h_ 90 91