1 // Copyright 2004 "Gilles Degottex"
3 // This file is part of "Music"
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.
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.
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
32 class Algorithm : public SettingsListener
34 static list<Algorithm*> s_algos;
37 double m_amplitude_treshold;
38 double m_max_amplitude;
40 virtual void samplingRateChanged() {cerr<<__FILE__<<":"<<__LINE__<<" Algorithm::samplingRateChanged Not Yet Implemented"<<endl;}
41 virtual void AFreqChanged() {cerr<<__FILE__<<":"<<__LINE__<<" Algorithm::AFreqChanged Not Yet Implemented"<<endl;}
42 virtual void semitoneBoundsChanged() {cerr<<__FILE__<<":"<<__LINE__<<" Algorithm::semitoneBoundsChanged Not Yet Implemented"<<endl;}
47 inline double getAmplitudeTreshold() {return m_amplitude_treshold;}
48 inline void setAmplitudeTreshold(double t) {m_amplitude_treshold=t;}
49 inline double getMaxAmplitude() {return m_max_amplitude;}
51 virtual int getSampleAlgoLatency() const =0;
52 virtual double getAlgoLatency() const {return double(getSampleAlgoLatency())/GetSamplingRate();}
54 virtual void apply(const deque<double>& buff)=0;
55 virtual bool hasNoteRecognized() const =0;
56 virtual double getFundamentalWaveLength() const {return GetSamplingRate()/getFundamentalFreq();}
57 virtual double getFundamentalFreq() const {return GetSamplingRate()/getFundamentalWaveLength();}
58 virtual double getFundamentalNote() const {return f2hf(getFundamentalFreq());}
59 virtual int getMinSize() const =0;
64 class Transform : public Algorithm
67 double m_component_treshold;
69 vector< complex<double> > m_harmonics;
70 vector<double> m_components;
71 double m_components_max;
74 inline double getComponentTreshold() {return m_component_treshold;}
75 inline void setComponentTreshold(double t) {m_component_treshold=t;}
79 size_t size() const {return m_components.size();}
81 const vector< complex<double> >& getHarmonics() {return m_harmonics;}
82 const vector<double>& getComponents() {return m_components;}
83 double getComponentsMax() {return m_components_max;}
85 virtual ~Transform(){}
89 #endif // _Algorithms_h_