Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/DeInterleaveSizecontrol.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 "DeInterleaveSizecontrol.h"
00020 
00021 using std::ostringstream;
00022 using namespace Marsyas;
00023 
00024 DeInterleaveSizecontrol::DeInterleaveSizecontrol(mrs_string name):MarSystem("DeInterleaveSizecontrol", name)
00025 {
00026   //Add any specific controls needed by DeInterleaveSizecontrol
00027   //(default controls all MarSystems should have
00028   //were already added by MarSystem::addControl(),
00029   //called by :MarSystem(name) constructor).
00030   //If no specific controls are needed by a MarSystem
00031   //there is no need to implement and call this addControl()
00032   //method (see for e.g. Rms.cpp)
00033   addControls();
00034 }
00035 
00036 DeInterleaveSizecontrol::DeInterleaveSizecontrol(const DeInterleaveSizecontrol& a) : MarSystem(a)
00037 {
00038   // For any MarControlPtr in a MarSystem
00039   // it is necessary to perform this getctrl
00040   // in the copy constructor in order for cloning to work
00041   ctrl_numSets_ = getctrl("mrs_natural/numSets");
00042   ctrl_sizes_ = getctrl("mrs_realvec/sizes");
00043 }
00044 
00045 DeInterleaveSizecontrol::~DeInterleaveSizecontrol()
00046 {
00047 }
00048 
00049 MarSystem*
00050 DeInterleaveSizecontrol::clone() const
00051 {
00052   return new DeInterleaveSizecontrol(*this);
00053 }
00054 
00055 void
00056 DeInterleaveSizecontrol::addControls()
00057 {
00058   //Add specific controls needed by this MarSystem.
00059   addctrl("mrs_natural/numSets", 1, ctrl_numSets_);
00060   addctrl("mrs_realvec/sizes",realvec() , ctrl_sizes_);
00061 }
00062 
00063 void
00064 DeInterleaveSizecontrol::myUpdate(MarControlPtr sender)
00065 {
00066   MarSystem::myUpdate(sender);
00067 }
00068 
00069 
00070 void
00071 DeInterleaveSizecontrol::myProcess(realvec& in, realvec& out)
00072 {
00073   mrs_natural o,t;
00074   for (o=0; o < inSamples_; o++)
00075   {
00076     mrs_natural size=(mrs_natural)(ctrl_sizes_->to<mrs_realvec>()(o));
00077     if (size<=0) size=onSamples_;
00078     mrs_natural rest=size%ctrl_numSets_->to<mrs_natural>();
00079     mrs_natural part=size/ctrl_numSets_->to<mrs_natural>();
00080     mrs_natural count=0;
00081     for(int i=0; i<onObservations_/size; ++i)
00082     {
00083       for (t = 0; t < rest; t++)
00084       {
00085         for (mrs_natural n = 0; n <1+part ; n++)
00086         {
00087           //first deinterleave once to all rows for the first "rest" number
00088           //(which happen one time more often then the others)
00089           mrs_natural outindex=i*size+n+part*t;
00090           mrs_natural inindex=i*size+ctrl_numSets_->to<mrs_natural>()*n+t;
00091           out(outindex,o) = in(inindex,o);
00092           count++;
00093         }
00094       }
00095       for (t = rest; t < ctrl_numSets_->to<mrs_natural>(); t++)
00096       {
00097         for (mrs_natural n = 0; n < part; n++)
00098         {
00099           //apply deinterleave to all remaining rows
00100           mrs_natural outindex=i*size+n+rest+part*t;
00101           mrs_natural inindex=i*size+ctrl_numSets_->to<mrs_natural>()*n+t;
00102           out(outindex,o) = in(inindex,o);
00103           count++;
00104         }
00105       }
00106     }
00107   }
00108 }
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116