Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/tonal/InstantTunningEstimator.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2006 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #ifndef InstantTunningEstimator_hxx
00023 #define InstantTunningEstimator_hxx
00024 #include <list>
00025 #include <vector>
00026 #include <cmath>
00027 
00028 namespace Simac
00029 {
00030 
00040 class InstantTunningEstimator
00041 {
00042 public:
00043         typedef std::vector<std::pair<double, double> > PeakList;
00044 private:
00045         double _fasorX;
00046         double _fasorY;
00047         double _instantX;
00048         double _instantY;
00049         double _inertia;
00050 public:
00051         InstantTunningEstimator(double inertia=0.0)
00052                 : _inertia(inertia)
00053         {
00054                 _fasorX=1.0;
00055                 _fasorY=0.0;
00056         }
00057         ~InstantTunningEstimator()
00058         {
00059         }
00060         void setInertia(double inertia)
00061         {
00062                 _inertia=inertia;
00063         }
00064         // TODO: This function is taken by S&R of the previous one, no test!!
00065         void doIt(const std::vector<std::pair<double, double> >& peaks)
00066         {
00067                 _fasorX*=_inertia;
00068                 _fasorY*=_inertia;
00069                 _instantX=0;
00070                 _instantY=0;
00071                 for (unsigned int peak=0; peak<peaks.size(); peak++)
00072                 {
00073                         double radiantTunning=peaks[peak].first*2*M_PI;
00074                         _instantX+=cos(radiantTunning)*peaks[peak].second;
00075                         _instantY+=sin(radiantTunning)*peaks[peak].second;
00076                 }
00077                 _fasorX += _instantX;
00078                 _fasorY += _instantY;
00079         }
00080         std::pair<double,double> output() const
00081         {
00082                 double tunning=std::atan2(_fasorY,_fasorX)/2/M_PI;
00083                 double strength=std::sqrt(_fasorY*_fasorY+_fasorX*_fasorX);
00084                 return std::make_pair(tunning, strength);
00085         }
00086         std::pair<double,double> instantTunning() const
00087         {
00088                 double tunning=std::atan2(_instantY,_instantX)/2/M_PI;
00089                 double strength=std::sqrt(_instantY*_instantY+_instantX*_instantX);
00090                 return std::make_pair(tunning, strength);
00091         }
00092 };
00093 
00094 } // namespace Simac
00095 
00096 #endif// InstantTunningEstimator_hxx
00097 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines