Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2006 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #include "StretchLinear.h" 00020 #include "../common_source.h" 00021 00022 using namespace std; 00023 using namespace Marsyas; 00024 00025 StretchLinear::StretchLinear(mrs_string name):MarSystem("StretchLinear", name) 00026 { 00027 addControls(); 00028 } 00029 00030 StretchLinear::StretchLinear(const StretchLinear& a) : MarSystem(a) 00031 { 00032 ctrl_stretch_ = getctrl("mrs_real/stretch"); 00033 } 00034 00035 00036 StretchLinear::~StretchLinear() 00037 { 00038 } 00039 00040 MarSystem* 00041 StretchLinear::clone() const 00042 { 00043 return new StretchLinear(*this); 00044 } 00045 00046 void 00047 StretchLinear::addControls() 00048 { 00049 addctrl("mrs_real/stretch", 1.0, ctrl_stretch_); 00050 } 00051 00052 void 00053 StretchLinear::myUpdate(MarControlPtr sender) 00054 { 00055 (void) sender; //suppress warning of unused parameter(s) 00056 MRSDIAG("StretchLinear.cpp - StretchLinear:myUpdate"); 00057 mrs_real alpha = ctrl_stretch_->to<mrs_real>(); 00058 ctrl_onSamples_->setValue((mrs_natural) (alpha * ctrl_inSamples_->to<mrs_natural>()), NOUPDATE); 00059 ctrl_onObservations_->setValue(ctrl_inObservations_->to<mrs_natural>()); 00060 ctrl_osrate_->setValue(ctrl_israte_->to<mrs_real>()); 00061 } 00062 00063 void 00064 StretchLinear::myProcess(realvec& in, realvec& out) 00065 { 00066 mrs_natural t,o; 00067 mrs_real tp; 00068 mrs_natural tl, tr; 00069 mrs_real alpha = ctrl_stretch_->to<mrs_real>(); 00070 00071 00072 for (o=0; o < onObservations_; o++) 00073 { 00074 for (t = 0; t < onSamples_; t++) 00075 { 00076 tp = t / alpha; 00077 tl= (mrs_natural)tp; 00078 tr = tl + 1; 00079 if (tl<inSamples_) 00080 { 00081 out(o,t) = (tr-tp) * in(o,tl) + (tp-tl) * in(o,tr); 00082 } 00083 else // reflect on boundary 00084 { 00085 out(o,t) = in(o,inSamples_); 00086 } 00087 } 00088 } 00089 }