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 00020 #include "MaxMin.h" 00021 using std::ostringstream; 00022 using namespace Marsyas; 00023 00024 MaxMin::MaxMin(mrs_string name): MarSystem("MaxMin",name) 00025 { 00026 } 00027 00028 MaxMin::~MaxMin() 00029 { 00030 } 00031 00032 MarSystem* 00033 MaxMin::clone() const 00034 { 00035 return new MaxMin(*this); 00036 } 00037 00038 void 00039 MaxMin::myUpdate(MarControlPtr sender) 00040 { 00041 // Start with the default MarSystem setup with equal input/output 00042 // stream format ... 00043 MarSystem::myUpdate(sender); 00044 00045 // ... but change the number and rate of output samples. 00046 setControl("mrs_natural/onSamples", (mrs_natural)2); 00047 setControl("mrs_real/osrate", 00048 getControl("mrs_real/israte")->to<mrs_real>() / getControl("mrs_natural/inSamples")->to<mrs_natural>() 00049 ); 00050 } 00051 00052 void 00053 MaxMin::myProcess(realvec& in, realvec& out) 00054 { 00055 mrs_natural t,o; 00056 for (o=0; o < inObservations_; o++) 00057 { 00058 max_ = -1.0 * DBL_MAX; 00059 min_ = DBL_MAX; 00060 for (t=0; t < inSamples_; t++) 00061 { 00062 if (in(o,t) > max_) 00063 { 00064 max_ = in(o,t); 00065 } 00066 if (in(o,t) < min_) 00067 { 00068 min_ = in(o,t); 00069 } 00070 } 00071 out(o,0) = max_; 00072 out(o,1) = min_; 00073 } 00074 }