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 _CumulativeDiff_h_ 21 #define _CumulativeDiff_h_ 22 23 #include <deque> 24 using namespace std; 25 26 namespace Music 27 { 28 //! do a Cumulative Diff with a specific wave-length of a desired note 29 struct CumulativeDiff 30 { 31 //! the analysed semi-tone from A3 32 const int m_ht; 33 //! his corresponding frequency 34 const double m_freq; 35 //! the wave-length 36 const size_t m_s; 37 //! latency_factor 38 double m_latency_factor; 39 40 //! unique ctor 41 /*! 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) 46 */ 47 CumulativeDiff(double latency_factor, int ht); 48 49 //! compute the error 50 void receive(const deque<double>& buff, size_t start=0); 51 52 //! computed error for the desired semi-tone (m_ht) 53 double m_error; 54 //! 55 double m_best_s; 56 }; 57 58 //! do a correlation with a specific range of wave-length around a desired note 59 struct RangedCumulativeDiff 60 { 61 //! the analysed semi-tone from A3 62 const int m_ht; 63 //! his corresponding frequency 64 const double m_freq; 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; 69 //! latency_factor 70 const double m_latency_factor; 71 72 //! unique ctor 73 /*! 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) 79 */ 80 RangedCumulativeDiff(double pitch_tolerance, double latency_factor, int ht); 81 82 //! compute the error 83 void receive(const deque<double>& buff, size_t start=0); 84 85 //! computed error for the desired semi-tone (m_ht) 86 double m_error; 87 88 //! computed minimal error 89 double m_min_error; 90 91 //! the wave length returning the minimal error; 92 int m_min_wave_length; 93 94 static void GetMinWaveLength(double pitch_tolerance, int ht, double& error, double min_wave_length); 95 }; 96 } 97 98 #endif // _CumulativeDiff_h_ 99