![]() |
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 #include <iostream> 00023 #include <cmath> 00024 #include "ConstantQFolder.hxx" 00025 00026 namespace Simac 00027 { 00028 00032 static double complexModule(const double & real, const double & imag) 00033 { 00034 return std::sqrt(real*real + imag*imag); 00035 } 00036 00037 ConstantQFolder::ConstantQFolder(unsigned nConstantQBins, int binsPerOctave) 00038 : _binsPerOctave(binsPerOctave) 00039 , _nConstantQBins(nConstantQBins) 00040 { 00041 _chromadata.resize(_binsPerOctave); 00042 } 00043 00044 ConstantQFolder::~ConstantQFolder() 00045 { 00046 } 00047 00048 void ConstantQFolder::doIt(const std::vector<double> & constantQData) 00049 { 00050 //initialise _chromadata to 0 00051 for (unsigned i=0; i<_binsPerOctave; i++) _chromadata[i]=0; 00052 00053 // add each octave of cq data into chromagram 00054 const unsigned nOctaves = (int)floor(double(_nConstantQBins/_binsPerOctave))-1; 00055 unsigned constantQBin = 0; 00056 for (unsigned octave=0; octave<=nOctaves; octave++) { 00057 for (unsigned i=0; i<_binsPerOctave; i++) { 00058 const double & real = constantQData[constantQBin++]; 00059 const double & imag = constantQData[constantQBin++]; 00060 _chromadata[i] += complexModule(real, imag); 00061 } 00062 } 00063 } 00064 00065 } 00066