Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/Daub4.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 "Daub4.h"
00020 #include "../common_source.h"
00021 
00022 using std::ostringstream;
00023 using namespace Marsyas;
00024 
00025 Daub4::Daub4(mrs_string name):MarSystem("Daub4",name)
00026 {
00027   addControls();
00028 }
00029 
00030 Daub4::~Daub4()
00031 {
00032 }
00033 
00034 MarSystem*
00035 Daub4::clone() const
00036 {
00037   return new Daub4(*this);
00038 }
00039 
00040 void
00041 Daub4::addControls()
00042 {
00043   addctrl("mrs_bool/forward", true, ctrl_forward_);
00044   addctrl("mrs_natural/processSize", 0, ctrl_processSize_);
00045 }
00046 
00047 void
00048 Daub4::myUpdate(MarControlPtr sender)
00049 {
00050   (void) sender;  //suppress warning of unused parameter(s)
00051   MRSDIAG("Daub4.cpp - Daub4:myUpdate");
00052 
00053   setctrl("mrs_natural/onSamples", getctrl("mrs_natural/inSamples"));
00054   setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations"));
00055   setctrl("mrs_real/osrate", getctrl("mrs_real/israte"));
00056   c0_ = 0.4829629131445341f;
00057   c1_ = 0.8365163037378079f;
00058   c2_ = 0.2241438680420143f;
00059   c3_ = -0.1294095225512604f;
00060   workspace_.create(getctrl("mrs_natural/inSamples")->to<mrs_natural>());
00061 }
00062 
00063 void
00064 Daub4::myProcess(realvec& in, realvec& out)
00065 {
00066   //checkFlow(in,out);
00067   mrs_natural t;
00068   const mrs_natural& n = ctrl_processSize_->to<mrs_natural>();
00069   const mrs_bool& forward = ctrl_forward_->to<mrs_bool>();
00070 
00071   if (n < 4) return;
00072   nh = n >> 1;
00073   nh1 = nh + 1;
00074 
00075   // Apply Filter
00076   if (forward)
00077   {
00078     for (i=0, j=0; j <= n-4; j+=2, ++i)
00079     {
00080       workspace_(i) = c0_ * in(0,j) + c1_ * in(0,j+1) +
00081                       c2_ * in(0,j+2) + c3_ * in(0,j+3);
00082       workspace_(i+nh) = c3_ * in(0,j) - c2_ * in(0,j+1) +
00083                          c1_ * in(0,j+2) - c0_ * in(0,j+3);
00084     }
00085     workspace_(i) = c0_ * in(0,n-2) + c1_ * in(0,n-1) +
00086                     c2_ * in(0,0) + c3_ * in(0,1);
00087     workspace_(i+nh) = c3_ * in(0,n-2) - c2_ * in(0,n-1) +
00088                        c1_ * in(0,0) - c0_ * in(0,1);
00089   }
00090   // Apply transpose filter
00091   else if (!forward)
00092   {
00093     workspace_(0) =  c2_ * in(0,nh-1) + c1_ * in(0,n-1) +
00094                      c0_ * in(0,0) + c3_ * in(0,nh1-1);
00095     workspace_(1) = c3_ * in(0,nh-1) - c0_ * in(0,n-1) +
00096                     c1_ * in(0,0) - c2_ * in(0,nh1-1);
00097     for (i=0, j=2; i < nh-1; ++i)
00098     {
00099       workspace_(j++) = c2_ * in(0,i) + c1_ * in(0,i+nh) +
00100                         c0_ * in(0,i+1) + c3_ * in(0,i+nh1);
00101       workspace_(j++) = c3_ * in(0,i) - c0_ * in(0,i+nh) +
00102                         c1_ * in(0,i+1) - c2_ * in(0,i+nh1);
00103     }
00104   }
00105 
00106   for (t=0; t < n; t++)
00107   {
00108     out(0,t) = workspace_(t);
00109   }
00110 }
00111 
00112 
00113 
00114