![]() |
Mixxx
|
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 #ifdef __WINDOWS__ 00029 #define _USE_MATH_DEFINES 00030 #include <math.h> 00031 #endif 00032 00033 namespace Simac 00034 { 00035 00044 class CircularPeaksToPCP 00045 { 00046 public: 00047 typedef std::vector<std::pair<double, double> > PeakList; 00048 typedef std::vector<double> PCP; 00049 private: 00050 PCP _output; 00051 bool _windowingActivated; 00052 static const unsigned nSemitones=12; 00053 public: 00054 CircularPeaksToPCP() 00055 { 00056 _output.resize(nSemitones); 00057 _windowingActivated=false; 00058 } 00059 ~CircularPeaksToPCP() 00060 { 00061 } 00062 void activateWindowing() 00063 { 00064 _windowingActivated=true; 00065 } 00066 static double windowedValue(double position, double value) 00067 { 00068 return value* (0.54 - 0.46*std::cos(2*M_PI*(position+.5))); 00069 } 00070 void doIt(const PeakList & peaks) 00071 { 00072 for (unsigned i=0; i<nSemitones; i++) 00073 _output[i]=0; 00074 const unsigned nPeaks=peaks.size(); 00075 for (unsigned i=0; i<nPeaks; i++) 00076 { 00077 int quantizedSemitone = int(peaks[i].first + .5); 00078 unsigned semitone = (quantizedSemitone+nSemitones)%nSemitones; 00079 if (_windowingActivated) 00080 _output[semitone] += windowedValue(peaks[i].first,peaks[i].second); 00081 else 00082 _output[semitone] += peaks[i].second; 00083 } 00084 } 00085 00086 const PCP & output() const 00087 { 00088 return _output; 00089 } 00090 }; 00091 00092 } // namespace Simac 00093 00094 #endif// CircularPeaksToPCP_hxx 00095