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