CircularPeaksToPCP.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 CircularPeaksToPCP_hxx
00023 #define CircularPeaksToPCP_hxx
00024 #include <list>
00025 #include <vector>
00026 #include <cmath>
00027 
00028 namespace Simac
00029 {
00030 
00039 class CircularPeaksToPCP
00040 {
00041 public:
00042         typedef std::vector<std::pair<double, double> > PeakList;
00043         typedef std::vector<double> PCP;
00044 private:
00045         PCP _output;
00046         bool _windowingActivated;
00047         static const unsigned nSemitones=12;
00048 public:
00049         CircularPeaksToPCP()
00050         {
00051                 _output.resize(nSemitones);
00052                 _windowingActivated=false;
00053         }
00054         ~CircularPeaksToPCP()
00055         {
00056         }
00057         void activateWindowing()
00058         {
00059                 _windowingActivated=true;
00060         }
00061         static double windowedValue(double position, double value)
00062         {
00063                 return value* (0.54 - 0.46*std::cos(2*M_PI*(position+.5)));
00064         }
00065         void doIt(const PeakList & peaks)
00066         {
00067                 for (unsigned i=0; i<nSemitones; i++)
00068                         _output[i]=0;
00069                 const unsigned nPeaks=peaks.size();
00070                 for (unsigned i=0; i<nPeaks; i++)
00071                 {
00072                         int quantizedSemitone = int(peaks[i].first + .5);
00073                         unsigned semitone = (quantizedSemitone+nSemitones)%nSemitones;
00074                         if (_windowingActivated)
00075                                 _output[semitone] += windowedValue(peaks[i].first,peaks[i].second);
00076                         else
00077                                 _output[semitone] += peaks[i].second;
00078                 }
00079         }
00080 
00081         const PCP & output() const
00082         {
00083                 return _output;
00084         }
00085 };
00086 
00087 } // namespace Simac
00088 
00089 #endif// CircularPeaksToPCP_hxx
00090 
Generated by  doxygen 1.6.3