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
20 #ifndef _CumulativeDiff_h_
21 #define _CumulativeDiff_h_
28 //! do a Cumulative Diff with a specific wave-length of a desired note
31 //! the analysed semi-tone from A3
33 //! his corresponding frequency
38 double m_latency_factor;
42 * \param AFreq frequency of A3 (440.0)
43 * \param sampling_rate wave capture sampling rate (11khz;44khz)
44 * \param latency_factor latency factor [1;oo[
45 * \param ht analysed semi-tone (-48;+48)
47 CumulativeDiff(double latency_factor, int ht);
50 void receive(const deque<double>& buff, size_t start=0);
52 //! computed error for the desired semi-tone (m_ht)
58 //! do a correlation with a specific range of wave-length around a desired note
59 struct RangedCumulativeDiff
61 //! the analysed semi-tone from A3
63 //! his corresponding frequency
65 //! pitch tolerance for m_freq;
66 const double m_pitch_tolerance;
67 //! minimal to maximal scaned wave-length
68 const size_t m_smin, m_smax;
70 const double m_latency_factor;
74 * \param AFreq frequency of A3 (440.0)
75 * \param sampling_rate wave capture sampling rate (11khz;44khz)
76 * \param latency_factor latency factor [1;oo[
77 * \param pitch_tolerance ]0;0.5]
78 * \param ht analysed semi-tone (-48;+48)
80 RangedCumulativeDiff(double pitch_tolerance, double latency_factor, int ht);
83 void receive(const deque<double>& buff, size_t start=0);
85 //! computed error for the desired semi-tone (m_ht)
88 //! computed minimal error
91 //! the wave length returning the minimal error;
92 int m_min_wave_length;
94 static void GetMinWaveLength(double pitch_tolerance, int ht, double& error, double min_wave_length);
98 #endif // _CumulativeDiff_h_