Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/PvConvolve.cpp
Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 1998-2006 George Tzanetakis <gtzan@cs.uvic.ca>
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 
00019 #include "PvConvolve.h"
00020 
00021 using std::ostringstream;
00022 using namespace Marsyas;
00023 
00024 PvConvolve::PvConvolve(mrs_string name):MarSystem("PvConvolve",name)
00025 {
00026   //type_ = "PvConvolve";
00027   //name_ = name;
00028 }
00029 
00030 
00031 PvConvolve::~PvConvolve()
00032 {
00033 }
00034 
00035 MarSystem*
00036 PvConvolve::clone() const
00037 {
00038   return new PvConvolve(*this);
00039 }
00040 
00041 
00042 void
00043 PvConvolve::myUpdate(MarControlPtr sender)
00044 {
00045   (void) sender;  //suppress warning of unused parameter(s)
00046   setctrl("mrs_natural/onSamples", getctrl("mrs_natural/inSamples"));
00047   setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations")->to<mrs_natural>() / 2);
00048   setctrl("mrs_real/osrate", getctrl("mrs_real/israte")->to<mrs_real>());
00049 }
00050 
00051 void
00052 PvConvolve::myProcess(realvec& in, realvec& out)
00053 {
00054   //checkFlow(in,out);
00055 
00056 
00057   mrs_natural N2 = onObservations_ / 2;
00058   mrs_real sqN = (mrs_real)N2 * N2;
00059 
00060   mrs_real r1, i1, r2, i2;
00061 
00062   for (mrs_natural o=0; o < N2; o++)
00063   {
00064 
00065     if (o==0)
00066     {
00067       r1 = in(2*o,0);
00068       i1 = 0.0;
00069       r2 = in(2*o + onObservations_, 0);
00070       i2 = 0.0;
00071       out(2*o, 0) = r1 * r2;
00072     }
00073     else if (o == N2)
00074     {
00075       r1 = in(1,0);
00076       i1 = 0.0;
00077       r2 = in(1 + onObservations_, 0);
00078       i2 = 0.0;
00079       out(1,0) = r1 * r2;
00080     }
00081     else
00082     {
00083       r1 = in(2*o,0);
00084       i1 = in(2*o+1,0);
00085       r2 = in(2*o + onObservations_, 0);
00086       i2 = in(2*o+1 + onObservations_, 0);
00087 
00088       out(2*o,0) = (r1 * r2 - i1 * i2) * sqN;
00089       out(2*o+1, 0) = (r1 * i2 + r2 * i1) * sqN;
00090 
00091       // out(2*o,0) = r1;
00092       // out(2*o+1, 0) = i1;
00093 
00094     }
00095 
00096 
00097 
00098   }
00099 
00100 
00101 
00102 
00103 
00104 
00105 }
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119