Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/WaveletPyramid.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 "WaveletPyramid.h"
00020 #include "../common_source.h"
00021 
00022 using namespace std;
00023 using namespace Marsyas;
00024 
00025 WaveletPyramid::WaveletPyramid(mrs_string name):MarSystem("WaveletPyramid",name)
00026 {
00027   waveletStep_ = NULL;
00028 
00029   addControls();
00030 }
00031 
00032 WaveletPyramid::~WaveletPyramid()
00033 {
00034   delete waveletStep_;
00035 }
00036 
00037 
00038 // copy constructor
00039 WaveletPyramid::WaveletPyramid(const WaveletPyramid& a):MarSystem(a)
00040 {
00041   waveletStep_ = NULL;
00042 }
00043 
00044 
00045 
00046 MarSystem*
00047 WaveletPyramid::clone() const
00048 {
00049   return new WaveletPyramid(*this);
00050 }
00051 
00052 void
00053 WaveletPyramid::addControls()
00054 {
00055   addctrl("mrs_bool/forward", true);
00056 }
00057 
00058 void
00059 WaveletPyramid::myUpdate(MarControlPtr sender)
00060 {
00061   (void) sender;  //suppress warning of unused parameter(s)
00062 
00063   if (waveletStep_ == NULL)
00064   {
00065     // TODO: why is this in myUpdate and not in the constructors?
00066     waveletStep_ = new Daub4("daub4");
00067   }
00068 
00069   MRSDIAG("WaveletPyramid.cpp - WaveletPyramid:myUpdate");
00070 
00071   setctrl("mrs_natural/onSamples", getctrl("mrs_natural/inSamples"));
00072   setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations"));
00073   setctrl("mrs_real/osrate", getctrl("mrs_real/israte"));
00074 
00075   waveletStep_->updControl("mrs_natural/inSamples", getctrl("mrs_natural/inSamples"));
00076   waveletStep_->updControl("mrs_natural/inObservations", getctrl("mrs_natural/inObservations"));
00077   waveletStep_->updControl("mrs_real/israte", getctrl("mrs_real/israte"));
00078 
00079 }
00080 
00081 
00082 void
00083 WaveletPyramid::myProcess(realvec& in, realvec& out)
00084 {
00085   mrs_natural o,t;
00086   mrs_natural nn;
00087   mrs_natural n;
00088   mrs_bool forward;
00089 
00090   n = getctrl("mrs_natural/inSamples")->to<mrs_natural>();
00091 
00092   if (n < 4)
00093   {
00094     // TODO: why do we return here immediately, and not after copying the
00095     // input to the output for example? Please explain.
00096     return;
00097   }
00098 
00099   // Copy input to output.
00100   for (o = 0; o < inObservations_; o++)
00101   {
00102     for (t = 0; t < inSamples_; t++)
00103     {
00104       out(o, t) = in(o, t);
00105     }
00106   }
00107 
00108   forward = getctrl("mrs_bool/forward")->to<mrs_bool>();
00109 
00110   waveletStep_->updControl("mrs_bool/forward", forward);
00111   if (forward)
00112   {
00113     for (nn = n; nn >=4; nn >>= 1)
00114     {
00115       waveletStep_->setctrl("mrs_natural/processSize", nn);
00116       waveletStep_->process(out, out);
00117     }
00118   }
00119   else
00120   {
00121     for (nn = 4; nn <= n; nn <<= 1)
00122     {
00123       waveletStep_->setctrl("mrs_natural/processSize", nn);
00124       waveletStep_->process(out, out);
00125     }
00126   }
00127 
00128 }