Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/TimeStretch.cpp
Go to the documentation of this file.
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 "TimeStretch.h"
00020 
00021 using namespace std;
00022 using namespace Marsyas;
00023 
00024 TimeStretch::TimeStretch(mrs_string name):MarSystem("TimeStretch",name)
00025 {
00026   //type_ = "TimeStretch";
00027   //name_ = name;
00028 
00029   addControls();
00030 }
00031 
00032 TimeStretch::~TimeStretch()
00033 {
00034 }
00035 
00036 MarSystem*
00037 TimeStretch::clone() const
00038 {
00039   return new TimeStretch(*this);
00040 }
00041 
00042 void
00043 TimeStretch::addControls()
00044 {
00045   addctrl("mrs_real/factor", 1.0);
00046 }
00047 
00048 void
00049 TimeStretch::myProcess(realvec& in, realvec& out)
00050 {
00051   //checkFlow(in,out);
00052   mrs_real factor = getctrl("mrs_real/factor")->to<mrs_real>();
00053   mrs_natural inSamples = getctrl("mrs_natural/inSamples")->to<mrs_natural>();
00054 
00055   for (mrs_natural t=0; t < inSamples; t++)
00056   {
00057     // linear interpolation
00058     ni = t* factor;
00059     li = ((unsigned long)ni) % inSamples;
00060     ri = li + 1;
00061 
00062     w_ = ni - li;
00063     if (ri < inSamples)
00064       out(0,t) = in(li) + w_ * (in(0,ri) - in(0,li));
00065     else
00066       out(0,t) = in(li);
00067   }
00068 }
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077