00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "ShiftInput.h"
00020
00021 using namespace std;
00022 using namespace Marsyas;
00023
00024 ShiftInput::ShiftInput(mrs_string name): MarSystem("ShiftInput", name)
00025 {
00026 winSize_ = 0;
00027 hopSize_ = 0;
00028 addControls();
00029 }
00030
00031 ShiftInput::~ShiftInput()
00032 {
00033 }
00034
00035 ShiftInput::ShiftInput(const ShiftInput& a): MarSystem(a)
00036 {
00037 winSize_ = 0;
00038 hopSize_ = 0;
00039
00040 ctrl_reset_ = getctrl("mrs_bool/reset");
00041 ctrl_winSize_ = getctrl("mrs_natural/winSize");
00042
00043 ctrl_clean_ = getctrl("mrs_bool/clean");
00044 ctrl_lowCleanLimit_ = getctrl("mrs_real/lowCleanLimit");
00045 ctrl_highCleanLimit_ = getctrl("mrs_real/highCleanLimit");
00046 }
00047
00048 MarSystem*
00049 ShiftInput::clone() const
00050 {
00051 return new ShiftInput(*this);
00052 }
00053
00054 void
00055 ShiftInput::addControls()
00056 {
00057
00058 addControl("mrs_natural/winSize", (mrs_natural)MRS_DEFAULT_SLICE_NSAMPLES, ctrl_winSize_);
00059 setControlState("mrs_natural/winSize", true);
00060
00061
00062
00063 addControl("mrs_bool/reset", true, ctrl_reset_);
00064
00065
00066
00067
00068 addControl("mrs_bool/clean", false, ctrl_clean_);
00069 addControl("mrs_real/lowCleanLimit", 0.0, ctrl_lowCleanLimit_);
00070 addControl("mrs_real/highCleanLimit", 1.0, ctrl_highCleanLimit_);
00071 }
00072
00073 void
00074 ShiftInput::myUpdate(MarControlPtr sender)
00075 {
00076 (void) sender;
00077
00078
00079 winSize_ = ctrl_winSize_->to<mrs_natural>();
00080 hopSize_ = ctrl_inSamples_->to<mrs_natural>();
00081
00082
00083
00084
00085
00086 if (hopSize_ < winSize_)
00087 {
00088 outSavedData_.stretch(ctrl_inObservations_->to<mrs_natural>(), winSize_ - hopSize_);
00089
00090
00091 if (hopSize_ == 0) {
00092 addToStabilizingDelay_ = 0;
00093 } else {
00094 addToStabilizingDelay_ = (mrs_natural) ceil(((mrs_real) winSize_ / hopSize_)) - 1;
00095 }
00096 } else {
00097 addToStabilizingDelay_ = 0;
00098 }
00099
00100
00101 ctrl_onSamples_->setValue(ctrl_winSize_, NOUPDATE);
00102 ctrl_onObservations_->setValue(ctrl_inObservations_, NOUPDATE);
00103 ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE);
00104
00105
00106 ostringstream prefix_oss;
00107 prefix_oss << "HopSize" << hopSize_ << "_WinSize" << winSize_ << "_";
00108 mrs_string onObsNames = obsNamesAddPrefix(ctrl_inObsNames_->to<mrs_string>(), prefix_oss.str());
00109 ctrl_onObsNames_->setValue(onObsNames, NOUPDATE);
00110 }
00111
00112 void
00113 ShiftInput::myProcess(realvec& in, realvec& out)
00114 {
00115 mrs_natural t,o;
00116
00117
00118 for (o = 0; o<inObservations_; ++o)
00119 {
00120 if (hopSize_ < winSize_)
00121 {
00122
00123
00124
00125
00126
00127 if (ctrl_reset_->to<mrs_bool>())
00128 {
00129 outSavedData_.setval(0.0);
00130 ctrl_reset_->setValue(false);
00131 }
00132
00133
00134
00135 if(ctrl_clean_->to<mrs_bool>())
00136 {
00137
00138 mrs_natural lowCleanLimit = (mrs_natural) ceil(winSize_
00139 * getctrl("mrs_real/lowCleanLimit")->to<mrs_real>());
00140 mrs_natural highCleanLimit = (mrs_natural) (lowCleanLimit + (ceil( winSize_
00141 * getctrl("mrs_real/highCleanLimit")->to<mrs_real>()
00142 ) - lowCleanLimit));
00143
00144 for (t = lowCleanLimit; t < highCleanLimit; t++)
00145 outSavedData_(o, t) = 0.0;
00146
00147 ctrl_clean_->setValue(false);
00148 }
00149
00150
00151
00152
00153
00154 for (t = 0; t < winSize_ - hopSize_; t++)
00155 {
00156 out(o, t) = outSavedData_(o, t);
00157 }
00158
00159 for (t = winSize_ - hopSize_; t < winSize_; t++)
00160 {
00161 out(o, t) = in(o, t - (winSize_ - hopSize_));
00162 }
00163
00164 for (t = 0; t < winSize_ - hopSize_; t++)
00165 {
00166 outSavedData_(o, t) = out(o, t + hopSize_);
00167 }
00168 }
00169 else
00170 {
00171
00172
00173 for (t = 0; t < onSamples_; ++t)
00174 {
00175 out(o, t) = in(o, t);
00176 }
00177 }
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 }