Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2007 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 "MinArgMin.h" 00020 00021 using std::ostringstream; 00022 using namespace Marsyas; 00023 00024 MinArgMin::MinArgMin(mrs_string name):MarSystem("MinArgMin",name) 00025 { 00026 //type_ = "MinArgMin"; 00027 //name_ = name; 00028 00029 addControls(); 00030 } 00031 00032 00033 MinArgMin::~MinArgMin() 00034 { 00035 } 00036 00037 00038 MarSystem* 00039 MinArgMin::clone() const 00040 { 00041 return new MinArgMin(*this); 00042 } 00043 00044 00045 void 00046 MinArgMin::addControls() 00047 { 00048 addctrl("mrs_natural/nMinimums", (mrs_natural)1); 00049 } 00050 00051 void 00052 MinArgMin::myUpdate(MarControlPtr sender) 00053 { 00054 (void) sender; //suppress warning of unused parameter(s) 00055 mrs_natural k = getctrl("mrs_natural/nMinimums")->to<mrs_natural>(); 00056 00057 setctrl("mrs_natural/onSamples", 2 * k); 00058 setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations")); 00059 setctrl("mrs_real/osrate", getctrl("mrs_real/israte")); 00060 } 00061 00062 00063 00064 void 00065 MinArgMin::myProcess(realvec& in, realvec& out) 00066 { 00067 out.setval(MAXREAL); 00068 mrs_natural k = getctrl("mrs_natural/nMinimums")->to<mrs_natural>(); 00069 mrs_natural inSamples = getctrl("mrs_natural/inSamples")->to<mrs_natural>(); 00070 00071 00072 for (mrs_natural t=0; t < inSamples; t++) 00073 { 00074 // for all the current minimums 00075 for (ki=0; ki < k; ++ki) 00076 { 00077 if (in(0,t) < out(0,2*ki)) 00078 { 00079 out(0,2*ki) = in(t); 00080 out(0,2*ki+1) = (mrs_real)t; 00081 break; 00082 } 00083 } 00084 } 00085 } 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096