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 _Convolution_h_
21 #define _Convolution_h_
22 
23 #include <vector>
24 #include <deque>
25 #include <complex>
26 using namespace std;
27 
28 namespace Music
29 {
30 	//! do a convolution with a specfic wave for a desired note
31 	struct Convolution
32 	{
33 		//! the desired semi-tone from A3
34 		const double m_ht;
35 		//! the corresponding frequency
36 		const double m_freq;
37 		//! latency factor, used for statistical purpose (40.0)
38 		const double m_latency_factor;
39 		//! duration in seconds
40 		const double m_duration;
41 
42 		//! the wave: the signal is convolued with
43 		vector< complex<double> > m_wave;
44 
45 		//! computed formant
46 		complex<double> m_value;
47 
48 		//! unique ctor
49 		/*!
50 		 * \param AFreq frequency of A3 (440.0)
51 		 * \param sampling_rate wave capture sampling rate (11khz;44khz)
52 		 * \param latency_factor latency factor [1;oo[
53 		 * \param gauss_factor the factor for the window fonction applied on the analysed sample (2.0)
54 		 * \param ht analysed semi-tone (-48;+48)
55 		 */
56 		Convolution(double latency_factor, double gauss_factor, double ht);
57 
58 		//! return the size of the analyse (the algorithmical N)
sizeConvolution59 		size_t size()	{return m_wave.size();}
60 
61 		//! compute a convolution
62 		void apply(const deque<double>& buff, int start=0);
63 	};
64 }
65 
66 #endif // _Convolution_h_
67