Marsyas
0.6.0-alpha
|
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 "Deinterleave.h" 00020 00021 using std::ostringstream; 00022 using namespace Marsyas; 00023 00024 Deinterleave::Deinterleave(mrs_string name):MarSystem("Deinterleave", name) 00025 { 00026 00027 pat_ = new PatchMatrix("pat"); 00028 00029 outindex_.stretch(inObservations_); 00030 inindex_.stretch(inObservations_); 00031 weights_.stretch(inObservations_,inObservations_); 00032 00033 addControls(); 00034 } 00035 00036 Deinterleave::Deinterleave(const Deinterleave& 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 00043 pat_ = new PatchMatrix("pat"); 00044 00045 outindex_.stretch(inObservations_); 00046 inindex_.stretch(inObservations_); 00047 weights_.stretch(inObservations_,inObservations_); 00048 } 00049 00050 Deinterleave::~Deinterleave() 00051 { 00052 delete pat_; 00053 } 00054 00055 MarSystem* 00056 Deinterleave::clone() const 00057 { 00058 return new Deinterleave(*this); 00059 } 00060 00061 void 00062 Deinterleave::addControls() 00063 { 00064 //Add specific controls needed by this MarSystem. 00065 addctrl("mrs_natural/numSets", 2, ctrl_numSets_); 00066 //setControlState("mrs_realvec/consts",true); 00067 setControlState("mrs_natural/numSets",true); 00068 } 00069 00070 void 00071 Deinterleave::myUpdate(MarControlPtr sender) 00072 { 00073 00074 MarSystem::myUpdate(sender); 00075 00076 mrs_natural numSets = ctrl_numSets_->to<mrs_natural>(); 00077 00078 outindex_.stretch(inObservations_); 00079 inindex_.stretch(inObservations_); 00080 weights_.stretch(inObservations_,inObservations_); 00081 00082 00083 mrs_natural rest=inObservations_%numSets; 00084 mrs_natural part=inObservations_/numSets; 00085 mrs_natural count=0; 00086 00087 for (mrs_natural t = 0; t < rest; t++) 00088 { 00089 for (mrs_natural n = 0; n <1+part ; n++) 00090 { 00091 //get Reordering indices for all rows for which there is a rest (they get one output more) 00092 outindex_(count)=n+part*t; 00093 inindex_(count)=numSets*n+t; 00094 count++; 00095 } 00096 } 00097 for (mrs_natural t = rest; t < numSets; t++) 00098 { 00099 for (mrs_natural n = 0; n < part; n++) 00100 { 00101 //get Reordering indices for all remaining rows 00102 outindex_(count)=n+rest+part*t; 00103 inindex_(count)=numSets*n+t; 00104 count++; 00105 } 00106 } 00107 00108 //Weights deinterleave n 00109 for(mrs_natural i=0; i<inindex_.getSize(); ++i) 00110 { 00111 weights_((mrs_natural)(outindex_(i)),(mrs_natural)(inindex_(i)))=1.0; 00112 } 00113 00114 pat_->setctrl("mrs_realvec/weights",weights_); 00115 00116 00117 } 00118 00119 00120 void 00121 Deinterleave::myProcess(realvec& in, realvec& out) 00122 { 00123 //Weights deinterleave n 00124 00125 pat_->process(in,out); 00126 00127 } 00128 00129 00130 00131 00132 00133 00134 00135