00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "StretchLinear.h"
00020
00021 using namespace std;
00022 using namespace Marsyas;
00023
00024 StretchLinear::StretchLinear(mrs_string name):MarSystem("StretchLinear", name)
00025 {
00026 addControls();
00027 }
00028
00029 StretchLinear::StretchLinear(const StretchLinear& a) : MarSystem(a)
00030 {
00031 ctrl_stretch_ = getctrl("mrs_real/stretch");
00032 }
00033
00034
00035 StretchLinear::~StretchLinear()
00036 {
00037 }
00038
00039 MarSystem*
00040 StretchLinear::clone() const
00041 {
00042 return new StretchLinear(*this);
00043 }
00044
00045 void
00046 StretchLinear::addControls()
00047 {
00048 addctrl("mrs_real/stretch", 1.0, ctrl_stretch_);
00049 }
00050
00051 void
00052 StretchLinear::myUpdate(MarControlPtr sender)
00053 {
00054 (void) sender;
00055 MRSDIAG("StretchLinear.cpp - StretchLinear:myUpdate");
00056 mrs_real alpha = ctrl_stretch_->to<mrs_real>();
00057 ctrl_onSamples_->setValue((mrs_natural) (alpha * ctrl_inSamples_->to<mrs_natural>()), NOUPDATE);
00058 ctrl_onObservations_->setValue(ctrl_inObservations_->to<mrs_natural>());
00059 ctrl_osrate_->setValue(ctrl_israte_->to<mrs_real>());
00060 }
00061
00062 void
00063 StretchLinear::myProcess(realvec& in, realvec& out)
00064 {
00065 mrs_natural t,o;
00066 mrs_real tp;
00067 mrs_natural tl, tr;
00068 mrs_real alpha = ctrl_stretch_->to<mrs_real>();
00069
00070
00071 for (o=0; o < onObservations_; o++)
00072 {
00073 for (t = 0; t < onSamples_; t++)
00074 {
00075 tp = t / alpha;
00076 tl= (mrs_natural)tp;
00077 tr = tl + 1;
00078 if (tl<inSamples_)
00079 {
00080 out(o,t) = (tr-tp) * in(o,tl) + (tp-tl) * in(o,tr);
00081 }
00082 else
00083 {
00084 out(o,t) = in(o,inSamples_);
00085 }
00086 }
00087 }
00088 }