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 "MemorySource.h" 00020 #include "../common_source.h" 00021 00022 using std::ostringstream; 00023 using namespace Marsyas; 00024 00025 MemorySource::MemorySource(mrs_string name):MarSystem("MemorySource",name) 00026 { 00027 //type_ = "MemorySource"; 00028 //name_ = name; 00029 00030 count_= 0; 00031 00032 addControls(); 00033 } 00034 00035 00036 MemorySource::~MemorySource() 00037 { 00038 } 00039 00040 00041 MarSystem* 00042 MemorySource::clone() const 00043 { 00044 return new MemorySource(*this); 00045 } 00046 00047 void 00048 MemorySource::addControls() 00049 { 00050 samplesToUse_ = (mrs_natural)MRS_DEFAULT_SLICE_NSAMPLES; 00051 addctrl("mrs_natural/samplesToUse", (mrs_natural)MRS_DEFAULT_SLICE_NSAMPLES); 00052 setctrlState("mrs_natural/samplesToUse", true); 00053 addctrl("mrs_bool/done", false); 00054 setctrlState("mrs_bool/done", true); 00055 } 00056 00057 00058 void 00059 MemorySource::myUpdate(MarControlPtr sender) 00060 { 00061 (void) sender; //suppress warning of unused parameter(s) 00062 MRSDIAG("MemorySource.cpp - MemorySource:myUpdate"); 00063 00064 setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations") ); 00065 setctrl("mrs_real/osrate", getctrl("mrs_real/israte")->to<mrs_real>()); 00066 samplesToUse_ = getctrl("mrs_natural/samplesToUse")->to<mrs_natural>(); 00067 00068 if( getctrl("mrs_bool/done")->isTrue()) { 00069 count_ = 0; 00070 setctrl("mrs_bool/done", false); 00071 } 00072 } 00073 00074 void 00075 MemorySource::myProcess(realvec& in, realvec& out) 00076 { 00077 mrs_natural t,o; 00078 //checkFlow(in,out); 00079 00080 if( count_ < 1 + (samplesToUse_ -1) / onSamples_ ) { 00081 00082 for (o=0; o < inObservations_; o++) { 00083 for (t = 0 ; t < onSamples_ && count_*onSamples_+t < samplesToUse_ ; t++) 00084 { 00085 out(o,t) = in(o,count_*onSamples_+t); 00086 } 00087 00088 for( ; t < onSamples_ ; t++ ) 00089 { 00090 out(o,t) = 0.; 00091 } 00092 } 00093 count_++; 00094 } 00095 00096 if( count_ >= 1 + (samplesToUse_ -1) / onSamples_ ) 00097 setctrl("mrs_bool/done", true); 00098 }