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