CircularPeaksToPCP.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 }
00088
00089 #endif// CircularPeaksToPCP_hxx
00090