Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 2000 George Tzanetakis <gtzan@cs.princeton.edu> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00028 #include "AutoCorrelationFFT.h" 00029 00030 using std::ostringstream; 00031 using namespace Marsyas; 00032 00033 00034 AutoCorrelationFFT::AutoCorrelationFFT(mrs_string name):MarSystem("AutoCorrelationFFT", name) 00035 { 00036 //Add any specific controls needed by AutoCorrelationFFT 00037 //(default controls all MarSystems should have 00038 //were already added by MarSystem::addControl(), 00039 //called by :MarSystem(name) constructor). 00040 //If no specific controls are needed by a MarSystem 00041 //there is no need to implement and call this addControl() 00042 //method (see for e.g. Rms.cpp) 00043 //addControls(); 00044 } 00045 00046 AutoCorrelationFFT::AutoCorrelationFFT(const AutoCorrelationFFT& orig) : MarSystem(orig) 00047 { 00048 // For any MarControlPtr in a MarSystem 00049 // it is necessary to perform this getctrl 00050 // in the copy constructor in order for cloning to work 00051 00052 //ctrl_offStart_ = getctrl("mrs_real/offStart"); 00053 } 00054 00055 AutoCorrelationFFT::~AutoCorrelationFFT() 00056 { 00057 } 00058 00059 MarSystem* 00060 AutoCorrelationFFT::clone() const 00061 { 00062 return new AutoCorrelationFFT(*this); 00063 } 00064 00065 void 00066 AutoCorrelationFFT::myUpdate(MarControlPtr sender) 00067 { 00068 MarSystem::myUpdate(sender); 00069 mrs_string inObsNames = ctrl_inObsNames_->to<mrs_string>(); 00070 00071 setControl("mrs_natural/onSamples", (mrs_natural)(ctrl_inSamples_->to<mrs_natural>()/2)); 00072 setControl("mrs_natural/onObservations", (mrs_natural)(ctrl_inObservations_->to<mrs_natural>())); 00073 00074 // Add Names of The Observations to the observation names. 00075 //inObsNames+=""; 00076 00077 // Add prefix to the observation names. 00078 //ctrl_onObsNames_->setValue(obsNamesAddPrefix(inObsNames, "AutoCorrelationFFT_"), NOUPDATE); 00079 } 00080 00081 00082 void 00083 AutoCorrelationFFT::myProcess(realvec& in, realvec& out) 00084 { 00085 for (mrs_natural o=0; o<inObservations_; o++) 00086 { 00087 00088 mrs_natural i; 00089 temp_.create(inSamples_); 00090 for (i=0; i < inSamples_; ++i) 00091 temp_(i) = in(o,i); 00092 mrs_real *temp = temp_.getData(); 00093 fft_.rfft(temp, inSamples_/2, FFT_FORWARD); 00094 //temp[0] = 0.0; 00095 //temp[1] = 0.0; 00096 out(o,0) = 0.0; // DC 00097 00098 00099 // compute magnitude of freqs 00100 for (i=1; i<onSamples_; ++i) 00101 { 00102 out(o,i) = sqrt(temp[2*i]*temp[2*i] + temp[2*i+1]*temp[2*i+1]); 00103 //cout << "outvec[" << 2*i << "]: " << outvec(2*i) << endl; 00104 } 00105 } 00106 00107 00108 } 00109