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