File: Algorithm.h

package info (click to toggle)
fmit 1.3.2-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,356 kB
  • sloc: cpp: 9,515; sh: 69; makefile: 12
file content (90 lines) | stat: -rw-r--r-- 3,074 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2004 "Gilles Degottex"

// This file is part of "Music"

// "Music" is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// "Music" is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


#ifndef _Algorithm_h_
#define _Algorithm_h_

#include <list>
#include <vector>
#include <deque>
#include <iostream>
using namespace std;
#include "Music.h"

namespace Music
{
	class Algorithm : public SettingsListener
	{
		static list<Algorithm*> s_algos;

	  protected:
		double m_amplitude_treshold;
		double m_max_amplitude;

        virtual void samplingRateChanged()					{cout<<__FILE__<<":"<<long(__LINE__)<<" Algorithm::samplingRateChanged Not Yet Implemented"<<endl;}
        virtual void AFreqChanged()							{cout<<__FILE__<<":"<<long(__LINE__)<<" Algorithm::AFreqChanged Not Yet Implemented"<<endl;}
        virtual void semitoneBoundsChanged()				{cout<<__FILE__<<":"<<long(__LINE__)<<" Algorithm::semitoneBoundsChanged Not Yet Implemented"<<endl;}

	  public:
		Algorithm();

		inline double getAmplitudeTreshold()				{return m_amplitude_treshold;}
		inline void setAmplitudeTreshold(double t)			{m_amplitude_treshold=t;}
		inline double getMaxAmplitude()						{return m_max_amplitude;}

		virtual int getSampleAlgoLatency() const =0;
		virtual double getAlgoLatency() const				{return double(getSampleAlgoLatency())/GetSamplingRate();}

		virtual void apply(const deque<double>& buff)=0;
		virtual bool hasNoteRecognized() const =0;
		virtual double getFundamentalWaveLength() const		{return GetSamplingRate()/getFundamentalFreq();}
		virtual double getFundamentalFreq() const			{return GetSamplingRate()/getFundamentalWaveLength();}
		virtual double getFundamentalNote() const			{return f2hf(getFundamentalFreq());}
		virtual int getMinSize() const =0;

		virtual ~Algorithm();
	};

	class Transform : public Algorithm
	{
	  protected:
		double m_component_treshold;

		vector< complex<double> > m_harmonics;
		vector<double> m_components;
		double m_components_max;

	  public:
		inline double getComponentTreshold()				{return m_component_treshold;}
		inline void setComponentTreshold(double t)			{m_component_treshold=t;}

		Transform();

		size_t size() const									{return m_components.size();}

		const vector< complex<double> >& getHarmonics()		{return m_harmonics;}
		const vector<double>& getComponents()				{return m_components;}
		double getComponentsMax()							{return m_components_max;}

		virtual ~Transform(){}
	};
}

#endif // _Algorithms_h_